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