Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/torchcodec/_core/CudaDeviceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ UniqueAVBufferRef getHardwareDeviceContext(const torch::Device& device) {

// Create hardware device context
c10::cuda::CUDAGuard deviceGuard(device);
// Valid values for the argument to cudaSetDevice are 0 to maxDevices - 1:
// https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE_1g159587909ffa0791bbe4b40187a4c6bb
// So we ensure the deviceIndex is not negative.
// We set the device because we may be called from a different thread than
// the one that initialized the cuda context.
cudaSetDevice(deviceIndex);
TORCH_CHECK(
cudaSetDevice(deviceIndex) == cudaSuccess, "Failed to set CUDA device");
AVBufferRef* hardwareDeviceCtxRaw = nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: I removed the comment above because it's now out of place, the deviceIndex was set to a proper value just above (currently line 54)

Separately, I'm not even sure we need the deviceGuard and the call to cudaSetDevice. I we should rely on PyTorch for that kind of stuff. Maybe it'll be worth revisiting in the future, for now, it's safe to keep as-is.

std::string deviceOrdinal = std::to_string(deviceIndex);

Expand Down
Loading