2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
18 // Common preprocessor definitions for CUDA compiler
22 #ifndef BTCUDADEFINES_H
23 #define BTCUDADEFINES_H
27 #ifdef __DEVICE_EMULATION__
28 #define B_CUDA_USE_TEX 0
30 #define B_CUDA_USE_TEX 1
35 #define BT_GPU_FETCH(t, i) tex_fetch3F1U(tex1Dfetch(t##Tex, i))
36 #define BT_GPU_FETCH4(t, i) tex1Dfetch(t##Tex, i)
38 #define BT_GPU_FETCH(t, i) t[i]
39 #define BT_GPU_FETCH4(t, i) t[i]
44 #define BT_GPU___device__ __device__
45 #define BT_GPU___devdata__ __device__
46 #define BT_GPU___constant__ __constant__
47 #define BT_GPU_max(a, b) max(a, b)
48 #define BT_GPU_min(a, b) min(a, b)
49 #define BT_GPU_params params
50 #define BT_GPU___mul24(a, b) __mul24(a, b)
51 #define BT_GPU___global__ __global__
52 #define BT_GPU___shared__ __shared__
53 #define BT_GPU___syncthreads() __syncthreads()
54 #define BT_GPU_make_uint2(x, y) make_uint2(x, y)
55 #define BT_GPU_make_int3(x, y, z) make_int3(x, y, z)
56 #define BT_GPU_make_float3(x, y, z) make_float3(x, y, z)
57 #define BT_GPU_make_float34(x) make_float3(x)
58 #define BT_GPU_make_float31(x) make_float3(x)
59 #define BT_GPU_make_float42(a, b) make_float4(a, b)
60 #define BT_GPU_make_float44(a, b, c, d) make_float4(a, b, c, d)
61 #define BT_GPU_PREF(func) btCuda_##func
62 #define BT_GPU_Memset cudaMemset
63 #define BT_GPU_MemcpyToSymbol(a, b, c) cudaMemcpyToSymbol(a, b, c)
64 #define BT_GPU_blockIdx blockIdx
65 #define BT_GPU_blockDim blockDim
66 #define BT_GPU_threadIdx threadIdx
67 #define BT_GPU_dot(a, b) dot(a, b)
68 #define BT_GPU_dot4(a, b) dot(a, b)
69 #define BT_GPU_cross(a, b) cross(a, b)
70 #define BT_GPU_BindTexture(a, b, c, d) cudaBindTexture(a, b, c, d)
71 #define BT_GPU_UnbindTexture(a) cudaUnbindTexture(a)
72 #define BT_GPU_EXECKERNEL(numb, numt, kfunc, args) kfunc<<<numb, numt>>>args
76 //! Check for CUDA error
77 #define BT_GPU_CHECK_ERROR(errorMessage) \
80 cudaError_t err = cudaGetLastError(); \
81 if(err != cudaSuccess) \
83 fprintf(stderr,"Cuda error: %s in file '%s' in line %i : %s.\n",\
84 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err));\
85 btCuda_exit(EXIT_FAILURE); \
87 err = cudaThreadSynchronize(); \
88 if(err != cudaSuccess) \
90 fprintf(stderr,"Cuda error: %s in file '%s' in line %i : %s.\n",\
91 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err));\
92 btCuda_exit(EXIT_FAILURE); \
99 #define BT_GPU_SAFE_CALL_NO_SYNC(call) \
102 cudaError err = call; \
103 if(err != cudaSuccess) \
105 fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
106 __FILE__, __LINE__, cudaGetErrorString( err) ); \
107 btCuda_exit(EXIT_FAILURE); \
114 #define BT_GPU_SAFE_CALL(call) \
117 BT_GPU_SAFE_CALL_NO_SYNC(call); \
118 cudaError err = cudaThreadSynchronize(); \
119 if(err != cudaSuccess) \
121 fprintf(stderr,"Cuda errorSync in file '%s' in line %i : %s.\n",\
122 __FILE__, __LINE__, cudaGetErrorString( err) ); \
123 btCuda_exit(EXIT_FAILURE); \
129 extern "C" void btCuda_exit(int val);
133 #endif // BTCUDADEFINES_H