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