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 PETSC_CUPM_DEFINE_STATIC_VARIABLE(ErrorNoDevice) 42 43 // hip not conforming, see declaration in cupminterface.hpp 44 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(ErrorDeviceAlreadyInUse,ErrorContextAlreadyInUse,ErrorDeviceAlreadyInUse) 45 46 // hip not conforming, and cuda faffs around with versions see declaration in cupminterface.hpp 47 #if PetscDefined(HAVE_CUDA) 48 # if PETSC_PKG_CUDA_VERSION_GE(11,1,0) 49 # define PetscCudaErrorStubLibrary ErrorStubLibrary 50 # endif 51 #endif 52 53 #ifndef PetscCudaErrorStubLibrary 54 #define PetscCudaErrorStubLibrary ErrorInsufficientDriver 55 #endif 56 57 PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscCudaErrorStubLibrary,ErrorInsufficientDriver,ErrorStubLibrary) 58 59 // enums 60 PETSC_CUPM_DEFINE_STATIC_VARIABLE(StreamNonBlocking) 61 PETSC_CUPM_DEFINE_STATIC_VARIABLE(DeviceMapHost) 62 PETSC_CUPM_DEFINE_STATIC_VARIABLE(MemcpyHostToDevice) 63 64 } // namespace Petsc 65