Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-17 02:41:17

0001 #ifndef FWCore_Utilities_HostDeviceConstant_h
0002 #define FWCore_Utilities_HostDeviceConstant_h
0003 
0004 // The use of host-side consexpr constants in device code is limited to:
0005 //   - scalars (other than `long double`)
0006 //   - scalar elements of aggregates used inside `constexpr` functions
0007 //
0008 // See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#constexpr-variables .
0009 //
0010 // In particular, it's not possible to use constexpr scalars by pointer or reference (e.g. std::min() takes arguments
0011 // by reference), or pass constexpr arrays as pointers, or access elements of constexpr arrays outside of constexpr
0012 // functions.
0013 //
0014 // The workaround is to define a macro that evaluates to "constexpr" on the host, and "__device__ constexpr" on the
0015 // device. Such macro can be used to declare aggregate objects that are available both on the host and on the device.
0016 // Note these objects may be at different memory addresses on the host and device, so their pointers will be different
0017 // -- but the actual values should be the same.
0018 
0019 #if defined(__CUDA_ARCH__) or defined(__HIP_DEVICE_COMPILE__)
0020 #define HOST_DEVICE_CONSTANT __device__ constexpr
0021 #else
0022 #define HOST_DEVICE_CONSTANT constexpr
0023 #endif
0024 
0025 #endif  // FWCore_Utilities_HostDeviceConstant_h