| 1 | /* |
| 2 | * cuda_util.hpp |
| 3 | * |
| 4 | * Created on: Jun 13, 2018 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_ |
| 9 | #define OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_ |
| 10 | |
| 11 | #include "config.h" |
| 12 | #if defined(CUDA_GPU) && !defined(CUDA_ON_CPU) |
| 13 | #include <cuda_runtime.h> |
| 14 | #endif |
| 15 | |
| 16 | #ifdef CUDA_GPU |
| 17 | |
| 18 | #ifndef __NVCC__ |
| 19 | |
| 20 | #ifndef __host__ |
| 21 | #define __host__ |
| 22 | #define __device__ |
| 23 | #define __shared__ |
| 24 | #define __global__ |
| 25 | #endif |
| 26 | |
| 27 | #else |
| 28 | |
| 29 | #ifndef __host__ |
| 30 | #define __host__ |
| 31 | #define __device__ |
| 32 | #define __global__ |
| 33 | #endif |
| 34 | |
| 35 | #ifdef CUDA_ON_CPU |
| 36 | |
| 37 | #define CUDA_SAFE(cuda_call) \ |
| 38 | cuda_call; |
| 39 | |
| 40 | #ifdef __shared__ |
| 41 | #undef __shared__ |
| 42 | #endif |
| 43 | #define __shared__ static |
| 44 | |
| 45 | #else |
| 46 | |
| 47 | #define CUDA_SAFE(cuda_call) \ |
| 48 | cuda_call; \ |
| 49 | {\ |
| 50 | cudaError_t e = cudaPeekAtLastError();\ |
| 51 | if (e != cudaSuccess)\ |
| 52 | {\ |
| 53 | std::string error = cudaGetErrorString(e);\ |
| 54 | std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\ |
| 55 | }\ |
| 56 | } |
| 57 | |
| 58 | #ifndef __shared__ |
| 59 | #define __shared__ |
| 60 | #endif |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | #endif |
| 65 | #else |
| 66 | |
| 67 | #ifndef __host__ |
| 68 | #define __host__ |
| 69 | #define __device__ |
| 70 | #define __shared__ static |
| 71 | #define __global__ |
| 72 | #endif |
| 73 | |
| 74 | #endif |
| 75 | |
| 76 | |
| 77 | #endif /* OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_ */ |
| 78 | |