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 #define KOKKOS_VIRTUAL_FUNCTION KOKKOS_FUNCTION virtual
39 #endif
40 #ifdef KOKKOS_ENABLE_HIP
41 #define MemSpace ::Kokkos::HIPSpace
42 #define ExecSpace ::Kokkos::HIP
43 #define KOKKOS_VIRTUAL_FUNCTION KOKKOS_FUNCTION virtual
44 #endif
45 #ifdef KOKKOS_ENABLE_SYCL
46 #define MemSpace ::Kokkos::SYCLDeviceUSMSpace
47 #define ExecSpace ::Kokkos::SYCL
48 #define KOKKOS_VIRTUAL_FUNCTION \
49  KOKKOS_FUNCTION SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( \
50  sycl::ext::oneapi::experimental::indirectly_callable) virtual
51 #endif
52 #else
53 #define MemSpace ::Kokkos::HostSpace
54 #define ExecSpace ::Kokkos::OpenMP
55 #undef KOKKOS_FUNCTION
56 #define KOKKOS_FUNCTION
57 #undef KOKKOS_INLINE_FUNCTION
58 #define KOKKOS_INLINE_FUNCTION inline
59 #define KOKKOS_VIRTUAL_FUNCTION KOKKOS_FUNCTION virtual
60 #undef KOKKOS_IF_ON_HOST
61 #define KOKKOS_IF_ON_HOST(code) \
62  if (!omp_get_level()) \
63  { \
64  code \
65  }
66 #undef KOKKOS_IF_ON_DEVICE
67 #define KOKKOS_IF_ON_DEVICE(code) \
68  if (omp_get_level()) \
69  { \
70  code \
71  }
72 #endif
73 
74 namespace Moose::Kokkos
75 {
79 constexpr unsigned int MAX_TAG = 30;
83 constexpr unsigned int MAX_CACHED_DOF = 30;
84 } // namespace Moose::Kokkos
constexpr unsigned int MAX_TAG
Maximum tag ID.
Definition: KokkosHeader.h:79
constexpr unsigned int MAX_CACHED_DOF
Maximum number of DOFs to cache during residual and Jacobian computation.
Definition: KokkosHeader.h:83