https://mooseframework.inl.gov
KokkosHeader.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #ifndef MOOSE_KOKKOS_SCOPE
13 #error Kokkos header was included in a source file which is not in the Kokkos compilation scope
14 #endif
15 
16 // NVCC invokes compile error due to conflicting built-in and PETSc complex operators
17 // so this preprocessor should be defined
18 #define PETSC_SKIP_CXX_COMPLEX_FIX 1
19 
20 // Kokkos headers
21 #include "Kokkos_Core.hpp"
22 #include "Kokkos_StdAlgorithms.hpp"
23 
24 // libMesh uses an old Boost library and causes a build error due to an outdated CUDA
25 // preprocessor which should be manually undefined after including CUDA runtime header
26 #undef __CUDACC_VER__
27 
28 // MOOSE includes
29 #include "MooseError.h"
30 #include "MooseUtils.h"
31 #include "MooseConfig.h"
32 
33 // Architecture-dependent execution spaces
34 #ifdef MOOSE_ENABLE_KOKKOS_GPU
35 #ifdef KOKKOS_ENABLE_CUDA
36 #define MemSpace ::Kokkos::CudaSpace
37 #define ExecSpace ::Kokkos::Cuda
38 #endif
39 #ifdef KOKKOS_ENABLE_HIP
40 #define MemSpace ::Kokkos::HIPSpace
41 #define ExecSpace ::Kokkos::HIP
42 #endif
43 #ifdef KOKKOS_ENABLE_SYCL
44 #define MemSpace ::Kokkos::SYCLDeviceUSMSpace
45 #define ExecSpace ::Kokkos::SYCL
46 #endif
47 #else
48 #define MemSpace ::Kokkos::HostSpace
49 #define ExecSpace ::Kokkos::OpenMP
50 #undef KOKKOS_FUNCTION
51 #define KOKKOS_FUNCTION
52 #undef KOKKOS_INLINE_FUNCTION
53 #define KOKKOS_INLINE_FUNCTION inline
54 #undef KOKKOS_IF_ON_HOST
55 #define KOKKOS_IF_ON_HOST(code) \
56  if (!omp_get_level()) \
57  { \
58  code \
59  }
60 #undef KOKKOS_IF_ON_DEVICE
61 #define KOKKOS_IF_ON_DEVICE(code) \
62  if (omp_get_level()) \
63  { \
64  code \
65  }
66 #endif
67 
68 namespace Moose
69 {
70 namespace Kokkos
71 {
75 constexpr unsigned int MAX_TAG = 30;
79 constexpr unsigned int MAX_CACHED_DOF = 30;
80 } // namespace Kokkos
81 } // namespace Moose
constexpr unsigned int MAX_TAG
Maximum tag ID.
Definition: KokkosHeader.h:75
constexpr unsigned int MAX_CACHED_DOF
Maximum number of DOFs to cache during residual and Jacobian computation.
Definition: KokkosHeader.h:79
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...