Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / cuda_tools / vectype_ops.cuh
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
7  *
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.
15  *
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.
20  *
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.
25  *
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.
30  *
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.
38  *
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.
41  */
42
43 #ifndef VECTYPE_OPS_CUH
44 #define VECTYPE_OPS_CUH
45
46 /**** float3 ****/
47 inline __host__ __device__ float3 make_float3(float s)
48 {
49     return make_float3(s, s, s);
50 }
51 inline __host__ __device__ float3 make_float3(float4 a)
52 {
53     return make_float3(a.x, a.y, a.z);
54 }
55 inline __host__ __device__ float3 operator-(float3 &a)
56 {
57     return make_float3(-a.x, -a.y, -a.z);
58 }
59 inline __host__ __device__ float3 operator+(float3 a, float3 b)
60 {
61     return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
62 }
63 inline __host__ __device__ float3 operator-(float3 a, float3 b)
64 {
65     return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
66 }
67 inline __host__ __device__ float3 operator*(float3 a, float k)
68 {
69     return make_float3(k * a.x, k * a.y, k * a.z);
70 }
71 inline __host__ __device__ float3 operator*(float k, float3 a)
72 {
73     return make_float3(k * a.x, k * a.y, k * a.z);
74 }
75 inline __host__ __device__ void operator+=(float3 &a, float3 b)
76 {
77     a.x += b.x; a.y += b.y; a.z += b.z;
78 }
79 inline __host__ __device__ void operator+=(float3 &a, float4 b)
80 {
81     a.x += b.x; a.y += b.y; a.z += b.z;
82 }
83 inline __host__ __device__ void operator-=(float3 &a, float3 b)
84 {
85     a.x -= b.x; a.y -= b.y; a.z -= b.z;
86 }
87 inline __host__ __device__ float norm(float3 a)
88 {
89     return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
90 }
91 inline __host__ __device__ float norm2(float3 a)
92 {
93     return (a.x * a.x + a.y * a.y + a.z * a.z);
94 }
95 inline __host__ __device__ float dist3(float3 a, float3 b)
96 {
97     return norm(b - a);
98 }
99 inline __host__ __device__ float3 operator*(float3 a, float3 b)
100 {
101     return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
102 }
103 inline __host__ __device__ void operator*=(float3 &a, float3 b)
104 {
105     a.x *= b.x; a.y *= b.y; a.z *= b.z;
106 }
107 inline __device__ void atomicAdd(float3 *addr, float3 val)
108 {
109     atomicAdd(&addr->x, val.x);
110     atomicAdd(&addr->y, val.y);
111     atomicAdd(&addr->z, val.z);
112 }
113 /****************************************************************/
114
115 /**** float4 ****/
116 inline __host__ __device__ float4 make_float4(float s)
117 {
118     return make_float4(s, s, s, s);
119 }
120 inline __host__ __device__ float4 make_float4(float3 a)
121 {
122     return make_float4(a.x, a.y, a.z, 0.0f);
123 }
124 inline __host__ __device__ float4 operator+(float4 a, float4 b)
125 {
126     return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
127 }
128 inline __host__ __device__ float4 operator+(float4 a, float3 b)
129 {
130     return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w);
131 }
132 inline __host__ __device__ float4 operator-(float4 a, float4 b)
133 {
134     return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
135 }
136 inline __host__ __device__ float4 operator*(float4 a, float k)
137 {
138     return make_float4(k * a.x, k * a.y, k * a.z, k * a.w);
139 }
140 inline __host__ __device__ void operator+=(float4 &a, float4 b)
141 {
142     a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
143 }
144 inline __host__ __device__ void operator+=(float4 &a, float3 b)
145 {
146     a.x += b.x; a.y += b.y; a.z += b.z;
147 }
148 inline __host__ __device__ void operator-=(float4 &a, float3 b)
149 {
150     a.x -= b.x; a.y -= b.y; a.z -= b.z;
151 }
152
153 inline __host__ __device__ float norm(float4 a)
154 {
155     return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
156 }
157
158 inline __host__ __device__ float dist3(float4 a, float4 b)
159 {
160     return norm(b - a);
161 }
162
163 #endif /* VECTYPE_OPS_CUH */