xref: /petsc/src/sys/objects/device/impls/cupm/cupminterface.cxx (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
1 #include <petsc/private/cupminterface.hpp>
2 #include <petsc/private/petscadvancedmacros.h>
3 
4 // This file serves simply to store the definitions of all the static variables that we
5 // DON'T have access to. Ones defined in PETSc-defined enum classes don't seem to have to
6 // need this declaration...
7 
8 namespace Petsc {
9 
10 namespace Device {
11 
12 namespace CUPM {
13 
14 namespace Impl {
15 
16 #define PETSC_CUPM_STATIC_VARIABLE_DEFN(theirs, DEVICE, ours) const decltype(theirs) Interface<DeviceType::DEVICE>::ours;
17 
18 // in case either one or the other don't agree on a name, you can specify all three here:
19 //
20 // PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cudaSuccess, hipAllGood, cupmSuccess) ->
21 // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
22 // const decltype(hipAllGood)  Interface<DeviceType::HIP>::cupmSuccess;
23 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cuoriginal, hiporiginal, ours) \
24   PetscIfPetscDefined(HAVE_CUDA, PETSC_CUPM_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(cuoriginal, CUDA, ours) PetscIfPetscDefined(HAVE_HIP, PETSC_CUPM_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(hiporiginal, HIP, ours)
25 
26 // if both cuda and hip agree on the same naming scheme i.e. cudaSuccess and hipSuccess:
27 //
28 // PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(Success) ->
29 // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
30 // const decltype(hipSuccess)  Interface<DeviceType::HIP>::cupmSuccess;
31 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(suffix) PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(cuda, suffix), PetscConcat(hip, suffix), PetscConcat(cupm, suffix))
32 
33 // error codes
34 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(Success)
35 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorNotReady)
36 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorSetOnActiveProcess)
37 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorNoDevice)
38 
39 // hip not conforming, see declaration in cupminterface.hpp
40 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cudaErrorDeviceAlreadyInUse, hipErrorContextAlreadyInUse, cupmErrorDeviceAlreadyInUse)
41 
42 // hip not conforming, and cuda faffs around with versions see declaration in cupminterface.hpp
43 #if PetscDefined(HAVE_CUDA)
44 #if PETSC_PKG_CUDA_VERSION_GE(11, 1, 0)
45 #define PetscCudaErrorStubLibrary ErrorStubLibrary
46 #endif
47 #endif
48 
49 #ifndef PetscCudaErrorStubLibrary
50 #define PetscCudaErrorStubLibrary ErrorInsufficientDriver
51 #endif
52 
53 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(cuda, PetscCudaErrorStubLibrary), hipErrorInsufficientDriver, cupmErrorStubLibrary)
54 
55 // enums
56 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(StreamNonBlocking)
57 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(DeviceMapHost)
58 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyHostToDevice)
59 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDeviceToHost)
60 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDeviceToDevice)
61 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyHostToHost)
62 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDefault)
63 
64 } // namespace Impl
65 
66 } // namespace CUPM
67 
68 } // namespace Device
69 
70 } // namespace Petsc
71