xref: /petsc/src/sys/objects/device/impls/cupm/cupminterface.cxx (revision f97672e55eacc8688507b9471cd7ec2664d7f203)
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 
11 namespace Device
12 {
13 
14 namespace CUPM
15 {
16 
17 namespace Impl
18 {
19 
20 #define PETSC_CUPM_STATIC_VARIABLE_DEFN(theirs,DEVICE,ours)     \
21   const decltype(theirs) Interface<DeviceType::DEVICE>::ours;
22 
23 // in case either one or the other don't agree on a name, you can specify all three here:
24 //
25 // PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cudaSuccess, hipAllGood, cupmSuccess) ->
26 // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
27 // const decltype(hipAllGood)  Interface<DeviceType::HIP>::cupmSuccess;
28 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cuoriginal,hiporiginal,ours) \
29   PetscIfPetscDefined(HAVE_CUDA,PETSC_CUPM_STATIC_VARIABLE_DEFN,PetscExpandToNothing)(cuoriginal,CUDA,ours) \
30   PetscIfPetscDefined(HAVE_HIP,PETSC_CUPM_STATIC_VARIABLE_DEFN,PetscExpandToNothing)(hiporiginal,HIP,ours)
31 
32 // if both cuda and hip agree on the same naming scheme i.e. cudaSuccess and hipSuccess:
33 //
34 // PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(Success) ->
35 // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
36 // const decltype(hipSuccess)  Interface<DeviceType::HIP>::cupmSuccess;
37 #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(suffix)         \
38   PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(cuda,suffix),PetscConcat(hip,suffix),PetscConcat(cupm,suffix))
39 
40 // error codes
41 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(Success)
42 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorNotReady)
43 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorSetOnActiveProcess)
44 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(ErrorNoDevice)
45 
46 // hip not conforming, see declaration in cupminterface.hpp
47 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cudaErrorDeviceAlreadyInUse,hipErrorContextAlreadyInUse,cupmErrorDeviceAlreadyInUse)
48 
49 // hip not conforming, and cuda faffs around with versions see declaration in cupminterface.hpp
50 #if PetscDefined(HAVE_CUDA)
51 #  if PETSC_PKG_CUDA_VERSION_GE(11,1,0)
52 #    define PetscCudaErrorStubLibrary ErrorStubLibrary
53 #  endif
54 #endif
55 
56 #ifndef PetscCudaErrorStubLibrary
57 #define PetscCudaErrorStubLibrary ErrorInsufficientDriver
58 #endif
59 
60 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(cuda,PetscCudaErrorStubLibrary),hipErrorInsufficientDriver,cupmErrorStubLibrary)
61 
62 // enums
63 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(StreamNonBlocking)
64 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(DeviceMapHost)
65 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyHostToDevice)
66 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDeviceToHost)
67 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDeviceToDevice)
68 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyHostToHost)
69 PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemcpyDefault)
70 
71 } // namespace Impl
72 
73 } // namespace CUPM
74 
75 } // namespace Device
76 
77 } // namespace Petsc
78