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 contextCuda = CUPMContextCuda(); 8 PetscDeviceContext_(CUDA) *dci; 9 10 PetscFunctionBegin; 11 PetscCall(contextCuda.initialize()); 12 PetscCall(PetscNew(&dci)); 13 dctx->data = static_cast<decltype(dctx->data)>(dci); 14 PetscCall(PetscMemcpy(dctx->ops,&contextCuda.ops,sizeof(contextCuda.ops))); 15 PetscFunctionReturn(0); 16 } 17 18 /* Management of CUBLAS and CUSOLVER handles */ 19 PetscErrorCode PetscCUBLASGetHandle(cublasHandle_t *handle) 20 { 21 PetscDeviceContext dctx; 22 23 PetscFunctionBegin; 24 PetscValidPointer(handle,1); 25 PetscCall(PetscDeviceContextGetCurrentContextAssertType_Internal(&dctx,PETSC_DEVICE_CUDA)); 26 PetscCall(PetscDeviceContextGetBLASHandle_Internal(dctx,handle)); 27 PetscFunctionReturn(0); 28 } 29 30 PetscErrorCode PetscCUSOLVERDnGetHandle(cusolverDnHandle_t *handle) 31 { 32 PetscDeviceContext dctx; 33 34 PetscFunctionBegin; 35 PetscValidPointer(handle,1); 36 PetscCall(PetscDeviceContextGetCurrentContextAssertType_Internal(&dctx,PETSC_DEVICE_CUDA)); 37 PetscCall(PetscDeviceContextGetSOLVERHandle_Internal(dctx,handle)); 38 PetscFunctionReturn(0); 39 } 40