Actual source code: cupminterface.cxx
1: #include <petsc/private/cupminterface.hpp>
2: #include <petsc/private/petscadvancedmacros.h>
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...
8: namespace Petsc
9: {
11: namespace device
12: {
14: namespace cupm
15: {
17: namespace impl
18: {
20: #define PETSC_CUPM_STATIC_VARIABLE_DEFN(theirs, DEVICE, ours) const decltype(theirs) InterfaceImpl<DeviceType::DEVICE>::ours
22: #define PETSC_CUPM_STATIC_VARIABLE_DEFN_CLASS(type_name, DEVICE, ours) const typename InterfaceImpl<DeviceType::DEVICE>::type_name InterfaceImpl<DeviceType::DEVICE>::ours
24: #define PETSC_CUPM_STATIC_VARIABLE_DEFN_EXACT(type_name, DEVICE, ours) const type_name InterfaceImpl<DeviceType::DEVICE>::ours
26: // in case either one or the other don't agree on a name, you can specify all three here:
27: //
28: // PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cudaSuccess, hipAllGood, cupmSuccess) ->
29: // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
30: // const decltype(hipAllGood) Interface<DeviceType::HIP>::cupmSuccess;
31: #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(cuoriginal, hiporiginal, ours) \
32: PetscIfPetscDefined(HAVE_CUDA, PETSC_CUPM_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(cuoriginal, CUDA, ours); \
33: PetscIfPetscDefined(HAVE_HIP, PETSC_CUPM_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(hiporiginal, HIP, ours)
35: // define the static variable in terms of the class typename
36: #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(type_name, ours) \
37: PetscIfPetscDefined(HAVE_CUDA, PETSC_CUPM_STATIC_VARIABLE_DEFN_CLASS, PetscExpandToNothing)(type_name, CUDA, ours); \
38: PetscIfPetscDefined(HAVE_HIP, PETSC_CUPM_STATIC_VARIABLE_DEFN_CLASS, PetscExpandToNothing)(type_name, HIP, ours)
40: #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_EXACT_TYPENAME(type_name, ours) \
41: PetscIfPetscDefined(HAVE_CUDA, PETSC_CUPM_STATIC_VARIABLE_DEFN_EXACT, PetscExpandToNothing)(type_name, CUDA, ours); \
42: PetscIfPetscDefined(HAVE_HIP, PETSC_CUPM_STATIC_VARIABLE_DEFN_EXACT, PetscExpandToNothing)(type_name, HIP, ours)
44: // if both cuda and hip agree on the same naming scheme i.e. cudaSuccess and hipSuccess:
45: //
46: // PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(Success) ->
47: // const decltype(cudaSuccess) Interface<DeviceType::CUDA>::cupmSuccess;
48: // const decltype(hipSuccess) Interface<DeviceType::HIP>::cupmSuccess;
49: #define PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(suffix) PETSC_CUPM_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(cuda, suffix), PetscConcat(hip, suffix), PetscConcat(cupm, suffix))
51: // error codes
52: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmSuccess);
53: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmErrorNotReady);
54: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmErrorSetOnActiveProcess);
55: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmErrorNoDevice);
56: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmErrorDeviceAlreadyInUse);
57: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmError_t, cupmErrorStubLibrary);
59: // enums
60: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(StreamDefault);
61: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(StreamNonBlocking);
62: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(DeviceMapHost);
64: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemcpyKind_t, cupmMemcpyHostToDevice);
65: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemcpyKind_t, cupmMemcpyDeviceToHost);
66: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemcpyKind_t, cupmMemcpyDeviceToDevice);
67: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemcpyKind_t, cupmMemcpyHostToHost);
68: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemcpyKind_t, cupmMemcpyDefault);
70: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemoryTypeHost);
71: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemoryTypeDevice);
72: // A vile, vile, hack. Would use PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME() with
73: // cupmMemoryType_t however MSVC chokes on this with:
74: //
75: // \src\sys\objects\device\impls\cupm\cupminterface.cxx(69): error C2371: 'cupmMemoryTypeHost':
76: // redefinition; different basic types
77: // \include\petsc/private/cupminterface.hpp(314): note: see declaration of 'cupmMemoryTypeHost'
78: // \src\sys\objects\device\impls\cupm\cupminterface.cxx(70): error C2371:
79: // 'cupmMemoryTypeDevice': redefinition; different basic types
80: // \include\petsc/private/cupminterface.hpp(315): note: see declaration of 'cupmMemoryTypeDevice'
81: // \src\sys\objects\device\impls\cupm\cupminterface.cxx(71): error C2371:
82: // 'cupmMemoryTypeManaged': redefinition; different basic types
83: // \include\petsc/private/cupminterface.hpp(316): note: see declaration of
84: // 'cupmMemoryTypeManaged'
85: //
86: // the only way to get it to compile is to use
87: // PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME() but since cupmMemoryTypeManaged is
88: // secretly hipMemoryTypeUnified that doesn't work unless we fudge it with preprocessor
89: #define hipMemoryTypeManaged hipMemoryTypeUnified
90: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(MemoryTypeManaged);
92: PETSC_CUPM_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(EventDisableTiming);
93: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_EXACT_TYPENAME(int, cupmHostAllocDefault);
94: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_EXACT_TYPENAME(int, cupmHostAllocWriteCombined);
96: PETSC_CUPM_DEFINE_STATIC_VARIABLE_VIA_CLASS_TYPENAME(cupmMemPoolAttr, cupmMemPoolAttrReleaseThreshold);
98: #if PetscDefined(HAVE_CUDA)
99: template struct Interface<DeviceType::CUDA>;
100: #endif
101: #if PetscDefined(HAVE_HIP)
102: template struct Interface<DeviceType::HIP>;
103: #endif
105: } // namespace impl
107: } // namespace cupm
109: } // namespace device
111: } // namespace Petsc