xref: /petsc/src/sys/objects/device/impls/cupm/cupminterface.cxx (revision ccb4e88a40f0b86eaeca07ff64c64e4de2fae686)
1 #include <petsc/private/cupminterface.hpp>
2 
3 // This file serves simply to store the definitions of all the static variables that we
4 // DON'T have access to. Ones defined in PETSc-defined enum classes don't seem to have to
5 // need this declaration...
6 
7 namespace Petsc
8 {
9 
10 // do all of this with macros to enforce that both CUDA and HIP implementations both have
11 // things defined. If you for example implement something on the HIP side but forget to
12 // implement it on the CUDA side you'll get an error.
13 
14 // need these for the indirection when building the if_0 and if_1 variants of the macro
15 #define CAT_(x,y) x ## y
16 #define CAT(x,y) CAT_(x,y)
17 
18 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_IF_HAVE_EXACT_0(PREFIX,original,mapped)
19 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_IF_HAVE_EXACT_1(PREFIX,original,mapped) \
20   const decltype(original) CUPMInterface<CUPMDeviceType::PREFIX>::mapped;
21 
22 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_IF_HAVE_EXACT(HAVE,PREFIX,orginal,mapped) \
23   CAT(PETSC_CUPM_DEFINE_STATIC_VARIABLE_IF_HAVE_EXACT_,HAVE)(PREFIX,orginal,mapped)
24 
25 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT_(PREFIX,orginal,mapped) \
26   PETSC_CUPM_DEFINE_STATIC_VARIABLE_IF_HAVE_EXACT(PetscDefined(HAVE_ ## PREFIX),PREFIX,orginal,mapped)
27 
28 // in case either one or the other don't agree on a name, you can specify all three here
29 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cuoriginal,hiporiginal,mapped) \
30   PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT_(CUDA,CAT(cuda,cuoriginal),CAT(cupm,mapped)) \
31   PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT_(HIP,CAT(hip,hiporiginal),CAT(cupm,mapped))
32 
33 // if both cuda and hip agree on the same name
34 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE(stem)                 \
35   PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(stem,stem,stem)
36 
37 // error codes
38 PETSC_CUPM_DEFINE_STATIC_VARIABLE(Success)
39 PETSC_CUPM_DEFINE_STATIC_VARIABLE(ErrorNotReady)
40 PETSC_CUPM_DEFINE_STATIC_VARIABLE(ErrorSetOnActiveProcess)
41 
42 // hip not conforming, see declaration in cupminterface.hpp
43 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(ErrorDeviceAlreadyInUse,ErrorContextAlreadyInUse,ErrorDeviceAlreadyInUse)
44 
45 // hip not conforming, and cuda faffs around with versions see declaration in cupminterface.hpp
46 #if PetscDefined(HAVE_CUDA)
47 #  if PETSC_PKG_CUDA_VERSION_GE(11,1,0)
48 #    define PetscCudaErrorStubLibrary ErrorStubLibrary
49 #  endif
50 #endif
51 
52 #ifndef PetscCudaErrorStubLibrary
53 #define PetscCudaErrorStubLibrary ErrorInsufficientDriver
54 #endif
55 
56 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscCudaErrorStubLibrary,ErrorInsufficientDriver,ErrorStubLibrary)
57 
58 // enums
59 PETSC_CUPM_DEFINE_STATIC_VARIABLE(StreamNonBlocking)
60 PETSC_CUPM_DEFINE_STATIC_VARIABLE(DeviceMapHost)
61 PETSC_CUPM_DEFINE_STATIC_VARIABLE(MemcpyHostToDevice)
62 
63 } // namespace Petsc
64