Macros.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_MACROS_HPP
12 #define CUBBYFLOW_MACROS_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 // Host vs. device
17 #ifdef __CUDACC__
18 #define CUBBYFLOW_CUDA_DEVICE __device__
19 #define CUBBYFLOW_CUDA_HOST __host__
20 #else
21 #define CUBBYFLOW_CUDA_DEVICE
22 #define CUBBYFLOW_CUDA_HOST
23 #endif // __CUDACC__
24 #define CUBBYFLOW_CUDA_HOST_DEVICE CUBBYFLOW_CUDA_HOST CUBBYFLOW_CUDA_DEVICE
25 
26 // Alignment
27 #ifdef __CUDACC__ // NVCC
28 #define CUBBYFLOW_CUDA_ALIGN(n) __align__(n)
29 #elif defined(__GNUC__) // GCC
30 #define CUBBYFLOW_CUDA_ALIGN(n) __attribute__((aligned(n)))
31 #elif defined(_MSC_VER) // MSVC
32 #define CUBBYFLOW_CUDA_ALIGN(n) __declspec(align(n))
33 #else
34 #error "Don't know how to handle CUBBYFLOW_CUDA_ALIGN"
35 #endif // __CUDACC__
36 
37 // Exception
38 #define _CUBBYFLOW_CUDA_CHECK(result, msg, file, line) \
39  if (result != cudaSuccess) \
40  { \
41  fprintf(stderr, "CUDA error at %s:%d code=%d (%s) \"%s\" \n", file, \
42  line, static_cast<unsigned int>(result), \
43  cudaGetErrorString(result), msg); \
44  cudaDeviceReset(); \
45  exit(EXIT_FAILURE); \
46  }
47 
48 #define CUBBYFLOW_CUDA_CHECK(expression) \
49  _CUBBYFLOW_CUDA_CHECK((expression), #expression, __FILE__, __LINE__)
50 
51 #define CUBBYFLOW_CUDA_CHECK_LAST_ERROR(msg) \
52  _CUBBYFLOW_CUDA_CHECK(cudaGetLastError(), msg, __FILE__, __LINE__)
53 
54 #endif // CUBBYFLOW_USE_CUDA
55 
56 #if defined(_WIN32) || defined(_WIN64)
57 #define CUBBYFLOW_WINDOWS
58 #elif defined(__APPLE__)
59 #define CUBBYFLOW_APPLE
60 #ifndef CUBBYFLOW_IOS
61 #define CUBBYFLOW_MACOSX
62 #endif
63 #elif defined(linux) || defined(__linux__)
64 #define CUBBYFLOW_LINUX
65 #endif
66 
67 #if defined(CUBBYFLOW_WINDOWS) && defined(_MSC_VER)
68 #include <BaseTsd.h>
69 typedef SSIZE_T ssize_t;
70 #else
71 #include <sys/types.h>
72 #endif
73 
74 #ifndef UNUSED_VARIABLE
75 #define UNUSED_VARIABLE(x) ((void)x)
76 #endif
77 
78 #endif