Actual source code: cupmblasinterface.cxx

      1: #include <petsc/private/cupmblasinterface.hpp>
      2: #include <petsc/private/petscadvancedmacros.h>

      4: namespace Petsc
      5: {

      7: namespace device
      8: {

     10: namespace cupm
     11: {

     13: namespace impl
     14: {

     16: #define PETSC_CUPMBLAS_STATIC_VARIABLE_DEFN(THEIRS, DEVICE, OURS) const decltype(THEIRS) BlasInterfaceImpl<DeviceType::DEVICE>::OURS;

     18: // in case either one or the other don't agree on a name, you can specify all three here:
     19: //
     20: // PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_EXACT(CUBLAS_STATUS_SUCCESS, rocblas_status_success,
     21: // CUPMBLAS_STATUS_SUCCESS) ->
     22: // const decltype(CUBLAS_STATUS_SUCCESS)  BlasInterface<DeviceType::CUDA>::CUPMBLAS_STATUS_SUCCESS;
     23: // const decltype(rocblas_status_success) BlasInterface<DeviceType::HIP>::CUPMBLAS_STATUS_SUCCESS;
     24: #define PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_EXACT(CUORIGINAL, HIPORIGINAL, OURS) \
     25:   PetscIfPetscDefined(HAVE_CUDA, PETSC_CUPMBLAS_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(CUORIGINAL, CUDA, OURS) PetscIfPetscDefined(HAVE_HIP, PETSC_CUPMBLAS_STATIC_VARIABLE_DEFN, PetscExpandToNothing)(HIPORIGINAL, HIP, OURS)

     27: // if both cuda and hip agree on the same naming scheme i.e. CUBLAS_STATUS_SUCCESS and
     28: // HIPBLAS_STATUS_SUCCESS:
     29: //
     30: // PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_PREFIX(STATUS_SUCCESS) ->
     31: // const decltype(CUBLAS_STATUS_SUCCESS)  BlasInterface<DeviceType::CUDA>::CUPMBLAS_STATUS_SUCCESS;
     32: // const decltype(HIPBLAS_STATUS_SUCCESS) BlasInterface<DeviceType::HIP>::CUPMBLAS_STATUS_SUCCESS;
     33: #define PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(SUFFIX) PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_EXACT(PetscConcat(CUBLAS_, SUFFIX), PetscConcat(HIPBLAS_, SUFFIX), PetscConcat(CUPMBLAS_, SUFFIX))

     35: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(STATUS_SUCCESS)
     36: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(STATUS_NOT_INITIALIZED)
     37: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(STATUS_ALLOC_FAILED)
     38: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(POINTER_MODE_HOST)
     39: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(POINTER_MODE_DEVICE)
     40: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(OP_T)
     41: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(OP_N)
     42: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(OP_C)
     43: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(FILL_MODE_LOWER)
     44: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(FILL_MODE_UPPER)
     45: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(SIDE_LEFT)
     46: PETSC_CUPMBLAS_DEFINE_STATIC_VARIABLE_MATCHING_SCHEME(DIAG_NON_UNIT)

     48: #if PetscDefined(HAVE_CUDA)
     49: template struct BlasInterface<DeviceType::CUDA>;
     50: #endif

     52: #if PetscDefined(HAVE_HIP)
     53: template struct BlasInterface<DeviceType::HIP>;
     54: #endif

     56: } // namespace impl

     58: } // namespace cupm

     60: } // namespace device

     62: } // namespace Petsc