XGCa
 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 #endif
46 
47 using DeviceType = Kokkos::Device<ExSpace,MemSpace>;
48 
49 // Designate a CPU-specific Memory and Execution space
50 using HostMemSpace = Kokkos::HostSpace;
51 #ifdef USE_OMP
52 using HostExSpace = Kokkos::OpenMP;
53 #elif defined(USE_SERIAL)
54 using HostExSpace = Kokkos::Serial;
55 #endif
56 using HostType = Kokkos::Device<HostExSpace,HostMemSpace>;
57 
58 // MPI
59 #ifdef USE_GPU_AWARE_MPI
61 #else
63 #endif
64 
65 /* Some commonly used Kokkos features that are renamed to increase legibility */
66 using Kokkos::View; // Now just View
67 using CLayout = Kokkos::LayoutRight; // 'C' Layout, i.e. the right-most index is the contiguous one
68 using NoInit = Kokkos::ViewAllocateWithoutInitializing; // Turns off default View behavior of initializing to zero upon allocation
69 
70 // For random number generation
71 typedef Kokkos::Random_XorShift64_Pool<DeviceType> pool_type;
72 typedef typename pool_type::generator_type RandGen;
73 
74 // Which level of memory team scratch is placed in. 0 is kilobytes (L1), 1 is a few gigabytes, 2 is generally node capacity
75 #ifndef KOKKOS_TEAM_SCRATCH_OPT
76 #define KOKKOS_TEAM_SCRATCH_OPT 0
77 #endif
78 
79 // Default Kokkos behavior is that a kernel cannot be launched until the previous one is complete (essentially a fence)
80 // HintLightWeight removes this fence and is necessary to allow asynchronous CPU/GPU kernels.
81 namespace Opt = Kokkos::Experimental;
82 constexpr static const Kokkos::Experimental::WorkItemProperty::HintLightWeight_t Async = Kokkos::Experimental::WorkItemProperty::HintLightWeight;
83 
84 #ifndef USE_SYCL
85 # define DEVICE_PRINTF(...) printf(__VA_ARGS__)
86 #else
87 # define DEVICE_PRINTF(...) sycl::ext::oneapi::experimental::printf(__VA_ARGS__)
88 #endif
89 
90 // SPACE_SETTINGS_HPP
91 #endif
Kokkos::Random_XorShift64_Pool< DeviceType > pool_type
Definition: space_settings.hpp:71
Kokkos::CudaSpace MemSpace
Definition: space_settings.hpp:10
Kokkos::Device< HostExSpace, HostMemSpace > HostType
Definition: space_settings.hpp:56
Kokkos::Cuda ExSpace
Definition: space_settings.hpp:11
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:67
pool_type::generator_type RandGen
Definition: space_settings.hpp:72
Kokkos::HostSpace HostMemSpace
Definition: space_settings.hpp:50
static constexpr const Kokkos::Experimental::WorkItemProperty::HintLightWeight_t Async
Definition: space_settings.hpp:82
Kokkos::Device< ExSpace, MemSpace > DeviceType
Definition: space_settings.hpp:47
Kokkos::OpenMP HostExSpace
Definition: space_settings.hpp:52
HostType MPIDeviceType
Definition: space_settings.hpp:62
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68