Skip to content

Commit 8e55bd4

Browse files
committed
More cuda error checking
1 parent 7a41bfd commit 8e55bd4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/torchcodec/_core/CudaDeviceInterface.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void CudaDeviceInterface::initialize(
192192
const AVRational& timeBase,
193193
const FrameDims& outputDims) {
194194
TORCH_CHECK(!ctx_, "FFmpeg HW device context already initialized");
195+
TORCH_CHECK(codecContext != nullptr, "codecContext is null");
195196

196197
timeBase_ = timeBase;
197198
outputDims_ = outputDims;
@@ -222,8 +223,7 @@ void CudaDeviceInterface::convertAVFrameToFrameOutput(
222223
// first, and do the color conversion there.
223224
//
224225
// TODO: If we're going to keep this around, we should probably cache it?
225-
auto cpuDevice = torch::Device(torch::kCPU);
226-
auto cpuInterface = createDeviceInterface(cpuDevice);
226+
auto cpuInterface = createDeviceInterface(torch::Device(torch::kCPU));
227227
TORCH_CHECK(
228228
cpuInterface != nullptr, "Failed to create CPU device interface");
229229
cpuInterface->initialize(
@@ -294,6 +294,8 @@ void CudaDeviceInterface::convertAVFrameToFrameOutput(
294294
"The AVFrame's hw_frames_ctx does not have a device_ctx. ");
295295
auto cudaDeviceCtx =
296296
static_cast<AVCUDADeviceContext*>(hwFramesCtx->device_ctx->hwctx);
297+
TORCH_CHECK(cudaDeviceCtx != nullptr, "The hardware context is null");
298+
297299
at::cuda::CUDAEvent nvdecDoneEvent;
298300
at::cuda::CUDAStream nvdecStream = // That's always the default stream. Sad.
299301
c10::cuda::getStreamFromExternal(cudaDeviceCtx->stream, deviceIndex);

0 commit comments

Comments
 (0)