2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2012, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 #ifndef VECTYPE_OPS_CUH
40 #define VECTYPE_OPS_CUH
43 inline __host__ __device__ float3 make_float3(float s)
45 return make_float3(s, s, s);
47 inline __host__ __device__ float3 make_float3(float4 a)
49 return make_float3(a.x, a.y, a.z);
51 inline __host__ __device__ float3 operator-(float3 &a)
53 return make_float3(-a.x, -a.y, -a.z);
55 inline __host__ __device__ float3 operator+(float3 a, float3 b)
57 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
59 inline __host__ __device__ float3 operator-(float3 a, float3 b)
61 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
63 inline __host__ __device__ float3 operator*(float3 a, float k)
65 return make_float3(k * a.x, k * a.y, k * a.z);
67 inline __host__ __device__ float3 operator*(float k, float3 a)
69 return make_float3(k * a.x, k * a.y, k * a.z);
71 inline __host__ __device__ void operator+=(float3 &a, float3 b)
73 a.x += b.x; a.y += b.y; a.z += b.z;
75 inline __host__ __device__ void operator+=(float3 &a, float4 b)
77 a.x += b.x; a.y += b.y; a.z += b.z;
79 inline __host__ __device__ void operator-=(float3 &a, float3 b)
81 a.x -= b.x; a.y -= b.y; a.z -= b.z;
83 inline __host__ __device__ float norm(float3 a)
85 return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
87 inline __host__ __device__ float norm2(float3 a)
89 return (a.x * a.x + a.y * a.y + a.z * a.z);
91 inline __host__ __device__ float dist3(float3 a, float3 b)
95 inline __host__ __device__ float3 operator*(float3 a, float3 b)
97 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
99 inline __host__ __device__ void operator*=(float3 &a, float3 b)
101 a.x *= b.x; a.y *= b.y; a.z *= b.z;
103 inline __device__ void atomicAdd(float3 *addr, float3 val)
105 atomicAdd(&addr->x, val.x);
106 atomicAdd(&addr->y, val.y);
107 atomicAdd(&addr->z, val.z);
109 /****************************************************************/
112 inline __host__ __device__ float4 make_float4(float s)
114 return make_float4(s, s, s, s);
116 inline __host__ __device__ float4 make_float4(float3 a)
118 return make_float4(a.x, a.y, a.z, 0.0f);
120 inline __host__ __device__ float4 operator+(float4 a, float4 b)
122 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
124 inline __host__ __device__ float4 operator+(float4 a, float3 b)
126 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w);
128 inline __host__ __device__ float4 operator-(float4 a, float4 b)
130 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
132 inline __host__ __device__ float4 operator*(float4 a, float k)
134 return make_float4(k * a.x, k * a.y, k * a.z, k * a.w);
136 inline __host__ __device__ void operator+=(float4 &a, float4 b)
138 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
140 inline __host__ __device__ void operator+=(float4 &a, float3 b)
142 a.x += b.x; a.y += b.y; a.z += b.z;
144 inline __host__ __device__ void operator-=(float4 &a, float3 b)
146 a.x -= b.x; a.y -= b.y; a.z -= b.z;
149 inline __host__ __device__ float norm(float4 a)
151 return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
154 inline __host__ __device__ float dist3(float4 a, float4 b)
159 #endif /* VECTYPE_OPS_CUH */