VecCore 0.8.1
C++ Library for Portable SIMD Vectorization
Loading...
Searching...
No Matches
CUDA.h
Go to the documentation of this file.
1#ifndef VECCORE_CUDA_H
2#define VECCORE_CUDA_H
3
4#if !defined(VECCORE_ENABLE_CUDA)
5
6#define VECCORE_IMPL_NAMESPACE cxx
7
8#define VECCORE_ATT_HOST /* empty */
9#define VECCORE_ATT_DEVICE /* empty */
10#define VECCORE_ATT_HOST_DEVICE /* empty */
11#define VECCORE_ATT_GLOBAL /* empty */
12#define VECCORE_CUDA_ALIGN /* empty */
13#define VECCORE_DECLARE_CUDA(x) /* empty */
14#define VECCORE_DECLARE_CUDA_TYPE(T) /* empty */
15#define VECCORE_DECLARE_CUDA_CLASS(x) /* empty */
16#define VECCORE_DECLARE_CUDA_STRUCT(x) /* empty */
17#define VECCORE_DEVICE_CONSTANT
18
19#elif (defined(__CUDACC__) || defined(__NVCC__))
20
21#define VECCORE_IMPL_NAMESPACE cuda
22
23#define VECCORE_CUDA
24#ifdef __CUDA_ARCH__
25#define VECCORE_CUDA_DEVICE_COMPILATION
26#endif
27
28#define VECCORE_ATT_HOST __host__
29#define VECCORE_ATT_DEVICE __device__
30#define VECCORE_ATT_HOST_DEVICE __host__ __device__
31#define VECCORE_ATT_GLOBAL __global__
32#define VECCORE_CUDA_ALIGN __align__((64))
33#define VECCORE_DECLARE_CUDA(x) /* empty */
34#define VECCORE_DECLARE_CUDA_TYPE(T) /* empty */
35#define VECCORE_DECLARE_CUDA_CLASS(x) /* empty */
36#define VECCORE_DECLARE_CUDA_STRUCT(x) /* empty */
37#define VECCORE_DECLARE_CUDA_TEMPLATE(x) /* empty */
38#define VECCORE_DEVICE_CONSTANT __constant__
39
40#else // CUDA enabled, but compiling regular C++ code
41
42#define VECCORE_CUDA_INTERFACE
43#define VECCORE_ATT_HOST /* empty */
44#define VECCORE_ATT_DEVICE /* empty */
45#define VECCORE_ATT_HOST_DEVICE /* empty */
46#define VECCORE_ATT_GLOBAL /* empty */
47#define VECCORE_CUDA_ALIGN /* empty */
48
49// Keep the macro compact
50// clang-format off
51
52#define VECCORE_CUDA_BASIC_TYPES \
53template <typename T> struct CudaTypeTraits; \
54template <> struct CudaTypeTraits<float> { using Type = float; }; \
55template <> struct CudaTypeTraits<double> { using Type = double; }; \
56template <> struct CudaTypeTraits<int8_t> { using Type = int8_t; }; \
57template <> struct CudaTypeTraits<int16_t> { using Type = int16_t; }; \
58template <> struct CudaTypeTraits<int32_t> { using Type = int32_t; }; \
59template <> struct CudaTypeTraits<int64_t> { using Type = int64_t; }; \
60template <> struct CudaTypeTraits<uint8_t> { using Type = uint8_t; }; \
61template <> struct CudaTypeTraits<uint16_t> { using Type = uint16_t; }; \
62template <> struct CudaTypeTraits<uint32_t> { using Type = uint32_t; }; \
63template <> struct CudaTypeTraits<uint64_t> { using Type = uint64_t; }; \
64template <typename T> using CudaType = typename CudaTypeTraits<T>::Type;
65
66#define VECCORE_DECLARE_CUDA(T) T; namespace cuda { T; }
67
68#define VECCORE_DECLARE_CUDA_TYPE(T) \
69 template <> struct CudaTypeTraits<T> { using Type = cuda::T; }; \
70
71#define VECCORE_DECLARE_CUDA_CLASS(x) \
72 VECCORE_DECLARE_CUDA(class x) VECCORE_DECLARE_CUDA_TYPE(x)
73
74#define VECCORE_DECLARE_CUDA_STRUCT(x) \
75 VECCORE_DECLARE_CUDA(struct x) VECCORE_DECLARE_CUDA_TYPE(x)
76
77// clang-format on
78
79#endif // defined (VECCORE_ENABLE_CUDA)
80
81#endif