1 #include "../cupmcontext.hpp" /*I "petscdevice.h" I*/ 2 3 using namespace Petsc::device::cupm; 4 5 PetscErrorCode PetscDeviceContextCreate_CUDA(PetscDeviceContext dctx) 6 { 7 static constexpr auto cuda_context = CUPMContextCuda(); 8 9 PetscFunctionBegin; 10 PetscCall(cuda_context.initialize()); 11 dctx->data = new PetscDeviceContext_(CUDA); 12 PetscCall(PetscMemcpy(dctx->ops, &cuda_context.ops, sizeof(cuda_context.ops))); 13 PetscFunctionReturn(0); 14 } 15 16 /* Management of CUBLAS and CUSOLVER handles */ 17 PetscErrorCode PetscCUBLASGetHandle(cublasHandle_t *handle) 18 { 19 PetscDeviceContext dctx; 20 21 PetscFunctionBegin; 22 PetscValidPointer(handle, 1); 23 PetscCall(PetscDeviceContextGetCurrentContextAssertType_Internal(&dctx, PETSC_DEVICE_CUDA)); 24 PetscCall(PetscDeviceContextGetBLASHandle_Internal(dctx, handle)); 25 PetscFunctionReturn(0); 26 } 27 28 PetscErrorCode PetscCUSOLVERDnGetHandle(cusolverDnHandle_t *handle) 29 { 30 PetscDeviceContext dctx; 31 32 PetscFunctionBegin; 33 PetscValidPointer(handle, 1); 34 PetscCall(PetscDeviceContextGetCurrentContextAssertType_Internal(&dctx, PETSC_DEVICE_CUDA)); 35 PetscCall(PetscDeviceContextGetSOLVERHandle_Internal(dctx, handle)); 36 PetscFunctionReturn(0); 37 } 38