Commit c30883dc authored by karius's avatar karius

added util.h

parent f6e356b0
/*
* CParticles.h
*
* Created on: Feb 25, 2019
* Author: kkarius
*/
#ifndef UTIL_H_
#define UTIL_H_
#include <cuda_util_include/cutil_math.h>
#include <functional>
#include <thrust/functional.h>
//cuda helper function stolen from the interwebs
#define CUDA_ERROR_CHECK
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ )
inline void __cudaSafeCall(cudaError err, const char *file, const int line) {
#ifdef CUDA_ERROR_CHECK
if (cudaSuccess != err) {
fprintf( stderr, "cudaSafeCall() failed at %s:%i : %s\n", file, line,
cudaGetErrorString(err));
exit(-1);
}
#endif
return;
}
inline void __cudaCheckError(const char *file, const int line) {
#ifdef CUDA_ERROR_CHECK
cudaError err = cudaGetLastError();
if (cudaSuccess != err) {
fprintf( stderr, "cudaCheckError() failed at %s:%i : %s\n", file, line,
cudaGetErrorString(err));
exit(-1);
}
// More careful checking. However, this will affect performance.
// Comment away if needed.
err = cudaDeviceSynchronize();
if (cudaSuccess != err) {
fprintf( stderr, "cudaCheckError() with sync failed at %s:%i : %s\n",
file, line, cudaGetErrorString(err));
exit(-1);
}
#endif
return;
}
const size_t one_gb = 1073741824;
static const int MAXTHREADS = 1024;
struct compare_float4_x
{
__host__ __device__
bool operator()(float4 lhs, float4 rhs)
{
return lhs.x < rhs.x;
}
};
struct compare_float4_y
{
__host__ __device__
bool operator()(float4 lhs, float4 rhs)
{
return lhs.y < rhs.y;
}
};
struct compare_float4_z
{
__host__ __device__
bool operator()(float4 lhs, float4 rhs)
{
return lhs.z < rhs.z;
}
};
struct min_float4 : public thrust::binary_function<float4,float4,float4>
{
__host__ __device__
float4 operator()(float4 x, float4 y) { return fminf(x,y); }
};
struct max_float4 : public thrust::binary_function<float4,float4,float4>
{
__host__ __device__
float4 operator()(float4 x, float4 y) { return fmaxf(x,y); }
};
inline int ipow(int base, int exp)
{
int result = 1;
for (;;)
{
if (exp & 1)
result *= base;
exp >>= 1;
if (!exp)
break;
base *= base;
}
return result;
}
#endif /* UTIL_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment