| 1 | #pragma once |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #if defined(__HIPCC__) |
| 6 | #define HOST_DEVICE_INLINE __host__ __device__ |
| 7 | #define DEVICE_INLINE __device__ |
| 8 | #define HOST_INLINE __host__ |
| 9 | #elif defined(__CUDACC__) || defined(_NVHPC_CUDA) |
| 10 | #define HOST_DEVICE_INLINE __host__ __device__ __forceinline__ |
| 11 | #define DEVICE_INLINE __device__ __forceinline__ |
| 12 | #define HOST_INLINE __host__ __forceinline__ |
| 13 | #else |
| 14 | #define HOST_DEVICE_INLINE inline |
| 15 | #define DEVICE_INLINE inline |
| 16 | #define HOST_INLINE inline |
| 17 | #endif |
| 18 | |
| 19 | #define CUDA_CHECK(cmd) \ |
| 20 | do { \ |
| 21 | cudaError_t e = cmd; \ |
| 22 | if (e != cudaSuccess) { \ |
| 23 | printf("Failed: Cuda error %s:%d '%s'\n", __FILE__, __LINE__, \ |
| 24 | cudaGetErrorString(e)); \ |
| 25 | exit(EXIT_FAILURE); \ |
| 26 | } \ |
| 27 | } while (0) |
| 28 | |
| 29 | int64_t get_device_attribute(int64_t attribute, int64_t device_id); |
| 30 | |
| 31 | int64_t get_max_shared_memory_per_block_device_attribute(int64_t device_id); |
| 32 | |
| 33 | namespace cuda_utils { |
| 34 | |
| 35 | template <typename T> |
| 36 | HOST_DEVICE_INLINE constexpr std::enable_if_t<std::is_integral_v<T>, T> |
| 37 | ceil_div(T a, T b) { |
| 38 | return (a + b - 1) / b; |
| 39 | } |
| 40 | |
| 41 | }; // namespace cuda_utils |