diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-05 13:26:21 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-05 13:26:21 -0400 |
commit | 48cb6fc276143567e13bfec6846721beb4ca2f46 (patch) | |
tree | f0b9352b107494bd7c6c4371a3a2d3bd0f4e392a /linalg.h | |
download | chroma-48cb6fc276143567e13bfec6846721beb4ca2f46.tar.gz chroma-48cb6fc276143567e13bfec6846721beb4ca2f46.tar.bz2 chroma-48cb6fc276143567e13bfec6846721beb4ca2f46.zip |
beginnings of some cuda linear algebra operations and a kernel to test them.
Diffstat (limited to 'linalg.h')
-rw-r--r-- | linalg.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/linalg.h b/linalg.h new file mode 100644 index 0000000..4d0344e --- /dev/null +++ b/linalg.h @@ -0,0 +1,101 @@ +#ifndef __LINALG_H__ +#define __LINALG_H__ + +__device__ __host__ float3 operator+ (const float3 &a, const float3 &b) +{ + return make_float3(a.x+b.x, a.y+b.y, a.z+b.y); +} + +__device__ __host__ void operator+= (float3 &a, const float3 &b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; +} + +__device__ __host__ float3 operator- (const float3 &a, const float3 &b) +{ + return make_float3(a.x-b.x, a.y-b.y, a.z-b.z); +} + +__device__ __host__ void operator-= (float3 &a, const float3 &b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; +} + +__device__ __host__ float3 operator+ (const float3 &a, const float &c) +{ + return make_float3(a.x+c, a.y+c, a.z+c); +} + +__device__ __host__ float3 operator+= (const float3 &a, const float &c) +{ + a.x += c; + a.y += c; + a.z += c; +} + +__device__ __host__ float3 operator+ (const float &c, const float3 &a) +{ + return make_float3(c+a.x, c+a.y, c+a.z); +} + +__device__ __host__ float3 operator- (const float3 &a, const float &c) +{ + return make_float3(a.x-c, a.y-c, a.z-c); +} + +__device__ __host__ float3 operator-= (const float3 &a, const float &c) +{ + a.x -= c; + a.y -= c; + a.z -= c; +} + +__device__ __host__ float3 operator- (const float &c, const float3& a) +{ + return make_float3(c-a.x, c-a.y, c-a.z); +} + +__device__ __host__ float3 operator* (const float3 &a, const float &c) +{ + return make_float3(a.x*c, a.y*c, a.z*c); +} + +__device__ __host__ float3 operator*= (const float3 &a, const float &c) +{ + a.x *= c; + a.y *= c; + a.z *= c; +} + +__device__ __host__ float3 operator* (const float &c, const float3& a) +{ + return make_float3(c*a.x, c*a.y, c*a.z); +} + +__device__ __host__ float3 operator/ (const float3 &a, const float &c) +{ + return make_float3(a.x/c, a.y/c, a.z/c); +} + +__device__ __host__ float3 operator/= (const float3 &a, const float &c) +{ + a.x /= c; + a.y /= c; + a.z /= c; +} + +__device__ __host__ float3 operator/ (const float &c, const float3 &a) +{ + return make_float3(c/a.x, c/a.y, c/a.z); +} + +__device__ __host__ float dot(const float3 &a, const float3 &b) +{ + return a.x*b.x + a.y*b.y + a.z*b.z; +} + +#endif |