-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmath.cuh
76 lines (62 loc) · 2.01 KB
/
vmath.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef VMATH_CUH
#define VMATH_CUH
/**
Out of place float3 vector operations.
*/
__device__ __forceinline__ float3 sub(float3 vecA, float3 vecB){
return {vecA.x-vecB.x, vecA.y-vecB.y, vecA.z-vecB.z};
}
__device__ __forceinline__ float3 add(float3 vecA, float3 vecB){
return {vecA.x+vecB.x, vecA.y+vecB.y, vecA.z+vecB.z};
}
__device__ __forceinline__ float3 addScaled(float3 vecA, float3 vecB, float scalarA, float scalarB){
return {vecA.x*scalarA+vecB.x*scalarB,
vecA.y*scalarA+vecB.y*scalarB,
vecA.z*scalarA+vecB.z*scalarB};
}
__device__ __forceinline__ float3 mul(float3 vecA, float3 vecB){
return {vecA.x*vecB.x, vecA.y*vecB.y, vecA.z*vecB.z};
}
// Sum squares.
__device__ __forceinline__ float norm1(float3 vector){
return vector.x*vector.x+vector.y*vector.y+vector.z*vector.z;
}
// Euclidean norm.
__device__ __forceinline__ float norm2(float3 vector){
return sqrt(vector.x*vector.x+vector.y*vector.y+vector.z*vector.z);
}
// Dot product.
__device__ __forceinline__ float dot(float3 vecA, float3 vecB){
return vecA.x*vecB.x+vecA.y*vecB.y+vecA.z*vecB.z;
}
// Scalar multiplication.
__device__ __forceinline__ float3 scal(float3 vector, float scalar){
return {vector.x*scalar, vector.y*scalar, vector.z*scalar};
}
__device__ __forceinline__ float3 unit(float3 vector, float length){
return {vector.x/length, vector.y/length, vector.z/length};
}
/**
In place float3 vector operations.
*/
__device__ __forceinline__ void setVector(float3 &vector, float3 xyz){
vector.x = xyz.x;
vector.y = xyz.y;
vector.z = xyz.z;
}
__device__ __forceinline__ void addIP(float3 &vector, float3 xyz){
vector.x += xyz.x;
vector.y += xyz.y;
vector.z += xyz.z;
}
__device__ __forceinline__ void IPsubXYZ(float3 &vector, float3 xyz){
vector.x -= xyz.x;
vector.y -= xyz.y;
vector.z -= xyz.z;
}
__device__ __forceinline__ void IPscalXYZ(float3 &vector, float scalar){
vector.x *= scalar;
vector.y *= scalar;
vector.z *= scalar;
}
#endif // VMATH_CUH