Xmipp  v3.23.11-Nereus
Macros | Typedefs | Functions
cuda_basic_math.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Pole   (sqrt(3.0f)-2.0f)
 

Typedefs

typedef unsigned int uint
 
typedef unsigned short ushort
 
typedef unsigned char uchar
 
typedef signed char schar
 

Functions

__host__ __device__ float power (float base, int exp)
 
__host__ __device__ double power (double base, int exp)
 
__host__ __device__ float2 make_float2 (float s)
 
__host__ __device__ float2 make_float2 (int2 a)
 
__host__ __device__ float2 operator+ (float2 a, float2 b)
 
__host__ __device__ void operator+= (float2 &a, float2 b)
 
__host__ __device__ double2 operator+ (double2 a, double2 b)
 
__host__ __device__ void operator+= (double2 &a, double2 b)
 
__host__ __device__ float2 operator- (float2 a, float2 b)
 
__host__ __device__ void operator-= (float2 &a, float2 b)
 
__host__ __device__ float2 operator* (float2 a, float2 b)
 
__host__ __device__ void operator*= (float2 &a, float2 b)
 
__host__ __device__ float2 operator* (float2 a, float s)
 
__host__ __device__ float2 operator* (float s, float2 a)
 
__host__ __device__ void operator*= (float2 &a, float s)
 
__host__ __device__ double2 operator* (double2 a, double2 b)
 
__host__ __device__ void operator*= (double2 &a, double2 b)
 
__host__ __device__ double2 operator* (double2 a, float s)
 
__host__ __device__ double2 operator* (float s, double2 a)
 
__host__ __device__ void operator*= (double2 &a, float s)
 
__host__ __device__ float2 operator/ (float2 a, float2 b)
 
__host__ __device__ float2 operator/ (float2 a, float s)
 
__host__ __device__ float2 operator/ (float s, float2 a)
 
__host__ __device__ void operator/= (float2 &a, float s)
 
__host__ __device__ void operator/= (double2 &a, float s)
 
__host__ __device__ float dot (float2 a, float2 b)
 
__host__ __device__ float length (float2 v)
 
__host__ __device__ float2 normalize (float2 v)
 
__host__ __device__ float2 floor (const float2 v)
 
__host__ __device__ float2 reflect (float2 i, float2 n)
 
__device__ __host__ uint UMIN (uint a, uint b)
 
__device__ __host__ uint PowTwoDivider (uint n)
 
__device__ __host__ float2 operator- (float a, float2 b)
 
__device__ __host__ float3 operator- (float a, float3 b)
 
__host__ __device__ float3 make_float3 (float s)
 
__host__ __device__ float3 make_float3 (float2 a)
 
__host__ __device__ float3 make_float3 (float2 a, float s)
 
__host__ __device__ float3 make_float3 (float4 a)
 
__host__ __device__ float3 make_float3 (int3 a)
 
__host__ __device__ float3 operator+ (float3 a, float3 b)
 
__host__ __device__ float3 operator+ (float3 a, float b)
 
__host__ __device__ void operator+= (float3 &a, float3 b)
 
__host__ __device__ float3 operator- (float3 a, float3 b)
 
__host__ __device__ float3 operator- (float3 a, float b)
 
__host__ __device__ void operator-= (float3 &a, float3 b)
 
__host__ __device__ float3 operator* (float3 a, float3 b)
 
__host__ __device__ float3 operator* (float3 a, float s)
 
__host__ __device__ float3 operator* (float s, float3 a)
 
__host__ __device__ void operator*= (float3 &a, float s)
 
__host__ __device__ float3 operator/ (float3 a, float3 b)
 
__host__ __device__ float3 operator/ (float3 a, float s)
 
__host__ __device__ float3 operator/ (float s, float3 a)
 
__host__ __device__ void operator/= (float3 &a, float s)
 
__host__ __device__ float dot (float3 a, float3 b)
 
__host__ __device__ float3 cross (float3 a, float3 b)
 
__host__ __device__ float length (float3 v)
 
__host__ __device__ float3 normalize (float3 v)
 
__host__ __device__ float3 floor (const float3 v)
 
__host__ __device__ float3 reflect (float3 i, float3 n)
 
template<typename T >
__host__ __device__ T lerp (T v0, T v1, T t)
 
template<typename T >
__host__ __device__ T biLerp (T x0, T x1, T y0, T y1, T tx, T ty)
 
template<typename T , typename U >
__host__ __device__ T biLerp (const T *__restrict__ data, int sizeX, int sizeY, U x, U y)
 

Macro Definition Documentation

◆ Pole

#define Pole   (sqrt(3.0f)-2.0f)

Definition at line 34 of file cuda_basic_math.h.

Typedef Documentation

◆ schar

typedef signed char schar

Definition at line 32 of file cuda_basic_math.h.

◆ uchar

typedef unsigned char uchar

Definition at line 31 of file cuda_basic_math.h.

◆ uint

typedef unsigned int uint

Definition at line 29 of file cuda_basic_math.h.

◆ ushort

typedef unsigned short ushort

Definition at line 30 of file cuda_basic_math.h.

Function Documentation

◆ biLerp() [1/2]

template<typename T >
__host__ __device__ T biLerp ( x0,
x1,
y0,
y1,
tx,
ty 
)
inline

Definition at line 376 of file cuda_basic_math.h.

376  {
377  T d0 = lerp(x0, x1, tx);
378  T d1 = lerp(y0, y1, tx);
379  return lerp(d0, d1, ty);
380 }
__host__ __device__ T lerp(T v0, T v1, T t)
#define y0
#define x0
double * d0

◆ biLerp() [2/2]

template<typename T , typename U >
__host__ __device__ T biLerp ( const T *__restrict__  data,
int  sizeX,
int  sizeY,
x,
y 
)
inline

Definition at line 384 of file cuda_basic_math.h.

384  {
385  int x0 = floor(x);
386  int x1 = ceil(x);
387  int y0 = floor(y);
388  int y1 = ceil(y);
389  return biLerp(
390  data[(y0 * sizeX) + x0],
391  data[(y0 * sizeX) + x1],
392  data[(y1 * sizeX) + x0],
393  data[(y1 * sizeX) + x1],
394  x - x0,
395  y - y0);
396 }
__host__ __device__ float2 floor(const float2 v)
static double * y
__host__ __device__ T biLerp(T x0, T x1, T y0, T y1, T tx, T ty)
doublereal * x
#define y0
#define x0

◆ cross()

__host__ __device__ float3 cross ( float3  a,
float3  b 
)
inline

Definition at line 322 of file cuda_basic_math.h.

323 {
324  return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
325 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ dot() [1/2]

__host__ __device__ float dot ( float2  a,
float2  b 
)
inline

Definition at line 156 of file cuda_basic_math.h.

157 {
158  return a.x * b.x + a.y * b.y;
159 }
doublereal * b
doublereal * a

◆ dot() [2/2]

__host__ __device__ float dot ( float3  a,
float3  b 
)
inline

Definition at line 316 of file cuda_basic_math.h.

317 {
318  return a.x * b.x + a.y * b.y + a.z * b.z;
319 }
doublereal * b
doublereal * a

◆ floor() [1/2]

__host__ __device__ float2 floor ( const float2  v)
inline

Definition at line 175 of file cuda_basic_math.h.

176 {
177  return make_float2(floor(v.x), floor(v.y));
178 }
__host__ __device__ float2 make_float2(float s)
__host__ __device__ float2 floor(const float2 v)

◆ floor() [2/2]

__host__ __device__ float3 floor ( const float3  v)
inline

Definition at line 341 of file cuda_basic_math.h.

342 {
343  return make_float3(floor(v.x), floor(v.y), floor(v.z));
344 }
__host__ __device__ float2 floor(const float2 v)
__host__ __device__ float3 make_float3(float s)

◆ length() [1/2]

__host__ __device__ float length ( float2  v)
inline

Definition at line 162 of file cuda_basic_math.h.

163 {
164  return sqrtf(dot(v, v));
165 }
__host__ __device__ float dot(float2 a, float2 b)

◆ length() [2/2]

__host__ __device__ float length ( float3  v)
inline

Definition at line 328 of file cuda_basic_math.h.

329 {
330  return sqrtf(dot(v, v));
331 }
__host__ __device__ float dot(float2 a, float2 b)

◆ lerp()

template<typename T >
__host__ __device__ T lerp ( v0,
v1,
t 
)
inline

Linear interpolation

Definition at line 370 of file cuda_basic_math.h.

370  {
371  return fma(t, v1, fma(-t, v0, v0));
372 }
double v1
double v0

◆ make_float2() [1/2]

__host__ __device__ float2 make_float2 ( float  s)
inline

Definition at line 49 of file cuda_basic_math.h.

50 {
51  return make_float2(s, s);
52 }
__host__ __device__ float2 make_float2(float s)

◆ make_float2() [2/2]

__host__ __device__ float2 make_float2 ( int2  a)
inline

Definition at line 53 of file cuda_basic_math.h.

54 {
55  return make_float2(float(a.x), float(a.y));
56 }
__host__ __device__ float2 make_float2(float s)
doublereal * a

◆ make_float3() [1/5]

__host__ __device__ float3 make_float3 ( float  s)
inline

Definition at line 214 of file cuda_basic_math.h.

215 {
216  return make_float3(s, s, s);
217 }
__host__ __device__ float3 make_float3(float s)

◆ make_float3() [2/5]

__host__ __device__ float3 make_float3 ( float2  a)
inline

Definition at line 218 of file cuda_basic_math.h.

219 {
220  return make_float3(a.x, a.y, 0.0f);
221 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ make_float3() [3/5]

__host__ __device__ float3 make_float3 ( float2  a,
float  s 
)
inline

Definition at line 222 of file cuda_basic_math.h.

223 {
224  return make_float3(a.x, a.y, s);
225 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ make_float3() [4/5]

__host__ __device__ float3 make_float3 ( float4  a)
inline

Definition at line 226 of file cuda_basic_math.h.

227 {
228  return make_float3(a.x, a.y, a.z); // discards w
229 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ make_float3() [5/5]

__host__ __device__ float3 make_float3 ( int3  a)
inline

Definition at line 230 of file cuda_basic_math.h.

231 {
232  return make_float3(float(a.x), float(a.y), float(a.z));
233 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ normalize() [1/2]

__host__ __device__ float2 normalize ( float2  v)
inline

Definition at line 168 of file cuda_basic_math.h.

169 {
170  float invLen = 1.0f / sqrtf(dot(v, v));
171  return v * invLen;
172 }
__host__ __device__ float dot(float2 a, float2 b)

◆ normalize() [2/2]

__host__ __device__ float3 normalize ( float3  v)
inline

Definition at line 334 of file cuda_basic_math.h.

335 {
336  float invLen = 1.0f / sqrtf(dot(v, v));
337  return v * invLen;
338 }
__host__ __device__ float dot(float2 a, float2 b)

◆ operator*() [1/9]

__host__ __device__ float2 operator* ( float2  a,
float2  b 
)
inline

Definition at line 87 of file cuda_basic_math.h.

88 {
89  return make_float2(a.x * b.x, a.y * b.y);
90 }
__host__ __device__ float2 make_float2(float s)
doublereal * b
doublereal * a

◆ operator*() [2/9]

__host__ __device__ float2 operator* ( float2  a,
float  s 
)
inline

Definition at line 96 of file cuda_basic_math.h.

97 {
98  return make_float2(a.x * s, a.y * s);
99 }
__host__ __device__ float2 make_float2(float s)
doublereal * a

◆ operator*() [3/9]

__host__ __device__ float2 operator* ( float  s,
float2  a 
)
inline

Definition at line 100 of file cuda_basic_math.h.

101 {
102  return make_float2(a.x * s, a.y * s);
103 }
__host__ __device__ float2 make_float2(float s)
doublereal * a

◆ operator*() [4/9]

__host__ __device__ double2 operator* ( double2  a,
double2  b 
)
inline

Definition at line 108 of file cuda_basic_math.h.

109 {
110  return make_double2(a.x * b.x, a.y * b.y);
111 }
doublereal * b
doublereal * a

◆ operator*() [5/9]

__host__ __device__ double2 operator* ( double2  a,
float  s 
)
inline

Definition at line 117 of file cuda_basic_math.h.

118 {
119  return make_double2(a.x * s, a.y * s);
120 }
doublereal * a

◆ operator*() [6/9]

__host__ __device__ double2 operator* ( float  s,
double2  a 
)
inline

Definition at line 121 of file cuda_basic_math.h.

122 {
123  return make_double2(a.x * s, a.y * s);
124 }
doublereal * a

◆ operator*() [7/9]

__host__ __device__ float3 operator* ( float3  a,
float3  b 
)
inline

Definition at line 276 of file cuda_basic_math.h.

277 {
278  return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
279 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator*() [8/9]

__host__ __device__ float3 operator* ( float3  a,
float  s 
)
inline

Definition at line 280 of file cuda_basic_math.h.

281 {
282  return make_float3(a.x * s, a.y * s, a.z * s);
283 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ operator*() [9/9]

__host__ __device__ float3 operator* ( float  s,
float3  a 
)
inline

Definition at line 284 of file cuda_basic_math.h.

285 {
286  return make_float3(a.x * s, a.y * s, a.z * s);
287 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ operator*=() [1/5]

__host__ __device__ void operator*= ( float2 &  a,
float2  b 
)
inline

Definition at line 91 of file cuda_basic_math.h.

92 {
93  a.x *= b.x;
94  a.y *= b.y;
95 }
doublereal * b
doublereal * a

◆ operator*=() [2/5]

__host__ __device__ void operator*= ( float2 &  a,
float  s 
)
inline

Definition at line 104 of file cuda_basic_math.h.

105 {
106  a.x *= s; a.y *= s;
107 }
doublereal * a

◆ operator*=() [3/5]

__host__ __device__ void operator*= ( double2 &  a,
double2  b 
)
inline

Definition at line 112 of file cuda_basic_math.h.

113 {
114  a.x *= b.x;
115  a.y *= b.y;
116 }
doublereal * b
doublereal * a

◆ operator*=() [4/5]

__host__ __device__ void operator*= ( double2 &  a,
float  s 
)
inline

Definition at line 125 of file cuda_basic_math.h.

126 {
127  a.x *= s; a.y *= s;
128 }
doublereal * a

◆ operator*=() [5/5]

__host__ __device__ void operator*= ( float3 &  a,
float  s 
)
inline

Definition at line 288 of file cuda_basic_math.h.

289 {
290  a.x *= s; a.y *= s; a.z *= s;
291 }
doublereal * a

◆ operator+() [1/4]

__host__ __device__ float2 operator+ ( float2  a,
float2  b 
)
inline

Definition at line 59 of file cuda_basic_math.h.

60 {
61  return make_float2(a.x + b.x, a.y + b.y);
62 }
__host__ __device__ float2 make_float2(float s)
doublereal * b
doublereal * a

◆ operator+() [2/4]

__host__ __device__ double2 operator+ ( double2  a,
double2  b 
)
inline

Definition at line 67 of file cuda_basic_math.h.

68 {
69  return make_double2(a.x + b.x, a.y + b.y);
70 }
doublereal * b
doublereal * a

◆ operator+() [3/4]

__host__ __device__ float3 operator+ ( float3  a,
float3  b 
)
inline

Definition at line 248 of file cuda_basic_math.h.

249 {
250  return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
251 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator+() [4/4]

__host__ __device__ float3 operator+ ( float3  a,
float  b 
)
inline

Definition at line 252 of file cuda_basic_math.h.

253 {
254  return make_float3(a.x + b, a.y + b, a.z + b);
255 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator+=() [1/3]

__host__ __device__ void operator+= ( float2 &  a,
float2  b 
)
inline

Definition at line 63 of file cuda_basic_math.h.

64 {
65  a.x += b.x; a.y += b.y;
66 }
doublereal * b
doublereal * a

◆ operator+=() [2/3]

__host__ __device__ void operator+= ( double2 &  a,
double2  b 
)
inline

Definition at line 71 of file cuda_basic_math.h.

72 {
73  a.x += b.x; a.y += b.y;
74 }
doublereal * b
doublereal * a

◆ operator+=() [3/3]

__host__ __device__ void operator+= ( float3 &  a,
float3  b 
)
inline

Definition at line 256 of file cuda_basic_math.h.

257 {
258  a.x += b.x; a.y += b.y; a.z += b.z;
259 }
doublereal * b
doublereal * a

◆ operator-() [1/5]

__host__ __device__ float2 operator- ( float2  a,
float2  b 
)
inline

Definition at line 77 of file cuda_basic_math.h.

78 {
79  return make_float2(a.x - b.x, a.y - b.y);
80 }
__host__ __device__ float2 make_float2(float s)
doublereal * b
doublereal * a

◆ operator-() [2/5]

__device__ __host__ float2 operator- ( float  a,
float2  b 
)
inline

Definition at line 199 of file cuda_basic_math.h.

200 {
201  return make_float2(a - b.x, a - b.y);
202 }
__host__ __device__ float2 make_float2(float s)
doublereal * b
doublereal * a

◆ operator-() [3/5]

__device__ __host__ float3 operator- ( float  a,
float3  b 
)
inline

Definition at line 204 of file cuda_basic_math.h.

205 {
206  return make_float3(a - b.x, a - b.y, a - b.z);
207 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator-() [4/5]

__host__ __device__ float3 operator- ( float3  a,
float3  b 
)
inline

Definition at line 262 of file cuda_basic_math.h.

263 {
264  return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
265 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator-() [5/5]

__host__ __device__ float3 operator- ( float3  a,
float  b 
)
inline

Definition at line 266 of file cuda_basic_math.h.

267 {
268  return make_float3(a.x - b, a.y - b, a.z - b);
269 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator-=() [1/2]

__host__ __device__ void operator-= ( float2 &  a,
float2  b 
)
inline

Definition at line 81 of file cuda_basic_math.h.

82 {
83  a.x -= b.x; a.y -= b.y;
84 }
doublereal * b
doublereal * a

◆ operator-=() [2/2]

__host__ __device__ void operator-= ( float3 &  a,
float3  b 
)
inline

Definition at line 270 of file cuda_basic_math.h.

271 {
272  a.x -= b.x; a.y -= b.y; a.z -= b.z;
273 }
doublereal * b
doublereal * a

◆ operator/() [1/6]

__host__ __device__ float2 operator/ ( float2  a,
float2  b 
)
inline

Definition at line 132 of file cuda_basic_math.h.

133 {
134  return make_float2(a.x / b.x, a.y / b.y);
135 }
__host__ __device__ float2 make_float2(float s)
doublereal * b
doublereal * a

◆ operator/() [2/6]

__host__ __device__ float2 operator/ ( float2  a,
float  s 
)
inline

Definition at line 136 of file cuda_basic_math.h.

137 {
138  float inv = 1.0f / s;
139  return a * inv;
140 }
doublereal * a

◆ operator/() [3/6]

__host__ __device__ float2 operator/ ( float  s,
float2  a 
)
inline

Definition at line 141 of file cuda_basic_math.h.

142 {
143  return make_float2(s / a.x, s / a.y);
144 }
__host__ __device__ float2 make_float2(float s)
doublereal * a

◆ operator/() [4/6]

__host__ __device__ float3 operator/ ( float3  a,
float3  b 
)
inline

Definition at line 294 of file cuda_basic_math.h.

295 {
296  return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
297 }
__host__ __device__ float3 make_float3(float s)
doublereal * b
doublereal * a

◆ operator/() [5/6]

__host__ __device__ float3 operator/ ( float3  a,
float  s 
)
inline

Definition at line 298 of file cuda_basic_math.h.

299 {
300  float inv = 1.0f / s;
301  return a * inv;
302 }
doublereal * a

◆ operator/() [6/6]

__host__ __device__ float3 operator/ ( float  s,
float3  a 
)
inline

Definition at line 303 of file cuda_basic_math.h.

304 {
305 // float inv = 1.0f / s;
306 // return a * inv;
307  return make_float3(s / a.x, s / a.y, s / a.z);
308 }
__host__ __device__ float3 make_float3(float s)
doublereal * a

◆ operator/=() [1/3]

__host__ __device__ void operator/= ( float2 &  a,
float  s 
)
inline

Definition at line 145 of file cuda_basic_math.h.

146 {
147  float inv = 1.0f / s;
148  a *= inv;
149 }
doublereal * a

◆ operator/=() [2/3]

__host__ __device__ void operator/= ( double2 &  a,
float  s 
)
inline

Definition at line 150 of file cuda_basic_math.h.

151 {
152  double inv = 1.0 / s;
153  a *= inv;
154 }
doublereal * a

◆ operator/=() [3/3]

__host__ __device__ void operator/= ( float3 &  a,
float  s 
)
inline

Definition at line 309 of file cuda_basic_math.h.

310 {
311  float inv = 1.0f / s;
312  a *= inv;
313 }
doublereal * a

◆ power() [1/2]

__host__ __device__ float power ( float  base,
int  exp 
)
inline

Definition at line 36 of file cuda_basic_math.h.

36  {
37  return powf(base, exp);
38 }

◆ power() [2/2]

__host__ __device__ double power ( double  base,
int  exp 
)
inline

Definition at line 40 of file cuda_basic_math.h.

40  {
41  return pow(base, exp);
42 }

◆ PowTwoDivider()

__device__ __host__ uint PowTwoDivider ( uint  n)
inline

Definition at line 191 of file cuda_basic_math.h.

192 {
193  if (n == 0) return 0;
194  uint divider = 1;
195  while ((n & divider) == 0) divider <<= 1;
196  return divider;
197 }
unsigned int uint
int * n

◆ reflect() [1/2]

__host__ __device__ float2 reflect ( float2  i,
float2  n 
)
inline

Definition at line 181 of file cuda_basic_math.h.

182 {
183  return i - 2.0f * n * dot(n,i);
184 }
#define i
int * n
__host__ __device__ float dot(float2 a, float2 b)

◆ reflect() [2/2]

__host__ __device__ float3 reflect ( float3  i,
float3  n 
)
inline

Definition at line 347 of file cuda_basic_math.h.

348 {
349  return i - 2.0f * n * dot(n,i);
350 }
#define i
int * n
__host__ __device__ float dot(float2 a, float2 b)

◆ UMIN()

__device__ __host__ uint UMIN ( uint  a,
uint  b 
)
inline

Definition at line 186 of file cuda_basic_math.h.

187 {
188  return a < b ? a : b;
189 }
doublereal * b
doublereal * a