XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
space_settings.hpp
Go to the documentation of this file.
1 #ifndef SPACE_SETTINGS_HPP
2 #define SPACE_SETTINGS_HPP
3 #include <Kokkos_Core.hpp>
4 #include <Kokkos_Random.hpp>
5 #include <vector>
6 // Declare the memory and execution spaces.
7 #ifdef USE_GPU
8 // 4 eventual possible GPU options: Cuda, Hip, Sycl, OpenMP+
9 #ifdef USE_CUDA
10 using MemSpace = Kokkos::CudaSpace;
11 using ExSpace = Kokkos::Cuda;
12 #elif defined(USE_HIP)
13 using MemSpace = Kokkos::Experimental::HIPSpace;
14 using ExSpace = Kokkos::Experimental::HIP;
15 #elif defined(USE_SYCL)
16 using MemSpace = Kokkos::Experimental::SYCLDeviceUSMSpace;
17 using ExSpace = Kokkos::Experimental::SYCL;
18 #elif defined(USE_OMPT)
19 using MemSpace = Kokkos::Experimental::OpenMPTargetSpace;
20 using ExSpace = Kokkos::Experimental::OpenMPTarget;
21 #else
22 #error USE_GPU is on, but no Kokkos backend specified
23 #endif
24 
25 #else
26 // USE_GPU undefined
27 using MemSpace = Kokkos::HostSpace;
28 #ifdef USE_OMP
29 using ExSpace = Kokkos::OpenMP;
30 #elif defined(USE_SERIAL)
31 using ExSpace = Kokkos::Serial;
32 #else
33 #error No CPU backend specified (USE_OMP or USE_SERIAL)
34 #endif
35 
36 #endif
37 
38 #ifndef USE_CUDA
39 // Native cuda min/max is used with cuda since std library is not available
40 // Otherwise, use std min/max.
41 using std::min;
42 using std::max;
43 using std::abs;
44 using std::isnan;
45 using std::isfinite;
46 #endif
47 
48 using DeviceType = Kokkos::Device<ExSpace,MemSpace>;
49 
50 // Designate a CPU-specific Memory and Execution space
51 using HostMemSpace = Kokkos::HostSpace;
52 #ifdef USE_OMP
53 using HostExSpace = Kokkos::OpenMP;
54 #elif defined(USE_SERIAL)
55 using HostExSpace = Kokkos::Serial;
56 #endif
57 using HostType = Kokkos::Device<HostExSpace,HostMemSpace>;
58 
59 // MPI
60 #ifdef USE_GPU_AWARE_MPI
62 #else
64 #endif
65 
66 /* Some commonly used Kokkos features that are renamed to increase legibility */
67 using Kokkos::View; // Now just View
68 using CLayout = Kokkos::LayoutRight; // 'C' Layout, i.e. the right-most index is the contiguous one
69 using NoInit = Kokkos::ViewAllocateWithoutInitializing; // Turns off default View behavior of initializing to zero upon allocation
70 
71 // For random number generation
72 typedef Kokkos::Random_XorShift64_Pool<DeviceType> pool_type;
73 typedef typename pool_type::generator_type RandGen;
74 
75 // Which level of memory team scratch is placed in. 0 is kilobytes (L1), 1 is a few gigabytes, 2 is generally node capacity
76 #ifndef KOKKOS_TEAM_SCRATCH_OPT
77 #define KOKKOS_TEAM_SCRATCH_OPT 0
78 #endif
79 
80 // Default Kokkos behavior is that a kernel cannot be launched until the previous one is complete (essentially a fence)
81 // HintLightWeight removes this fence and is necessary to allow asynchronous CPU/GPU kernels.
82 namespace Opt = Kokkos::Experimental;
83 constexpr static const Kokkos::Experimental::WorkItemProperty::HintLightWeight_t Async = Kokkos::Experimental::WorkItemProperty::HintLightWeight;
84 
85 #ifndef USE_SYCL
86 # define DEVICE_PRINTF(...) printf(__VA_ARGS__)
87 #else
88 # define DEVICE_PRINTF(...) sycl::ext::oneapi::experimental::printf(__VA_ARGS__)
89 #endif
90 
91 // SPACE_SETTINGS_HPP
92 #endif
Kokkos::Random_XorShift64_Pool< DeviceType > pool_type
Definition: space_settings.hpp:72
Kokkos::CudaSpace MemSpace
Definition: space_settings.hpp:10
Kokkos::Device< HostExSpace, HostMemSpace > HostType
Definition: space_settings.hpp:57
Kokkos::Cuda ExSpace
Definition: space_settings.hpp:11
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:68
pool_type::generator_type RandGen
Definition: space_settings.hpp:73
Kokkos::HostSpace HostMemSpace
Definition: space_settings.hpp:51
static constexpr const Kokkos::Experimental::WorkItemProperty::HintLightWeight_t Async
Definition: space_settings.hpp:83
Kokkos::Device< ExSpace, MemSpace > DeviceType
Definition: space_settings.hpp:48
Kokkos::OpenMP HostExSpace
Definition: space_settings.hpp:53
HostType MPIDeviceType
Definition: space_settings.hpp:63
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69