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