Skip to content

Commit

Permalink
CUDA: CURTN: fix internal error in cudaGetDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
atafra committed Mar 14, 2024
1 parent bc60159 commit d548568
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions devices/cuda/curtn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,21 @@ namespace curtn
if (device == nullptr)
return Runtime::setError(cudaErrorInvalidValue);

CUdevice deviceHandle;
CUresult result = cuCtxGetDevice(&deviceHandle);
CUcontext context;
CUresult result = cuCtxGetCurrent(&context);
if (result != CUDA_SUCCESS)
return Runtime::setError(result);

if (result == CUDA_SUCCESS)
if (context)
{
CUdevice deviceHandle;
result = cuCtxGetDevice(&deviceHandle);
if (result != CUDA_SUCCESS)
return Runtime::setError(result);

result = rt.getDeviceOrdinal(deviceHandle, *device);
}
else if (result == CUDA_ERROR_INVALID_CONTEXT)
else
{
// No current context, but it will be created lazily for device 0
*device = 0;
Expand Down

0 comments on commit d548568

Please sign in to comment.