Skip to content

Commit 61d4c7f

Browse files
committed
Add evenness checks before dividing by 2
1 parent 042a35e commit 61d4c7f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ UniqueAVFrame BetaCudaDeviceInterface::transferCpuFrameToGpuNV12(
729729
convertedHeight == height, "sws_scale failed for CPU->NV12 conversion");
730730

731731
int ySize = width * height;
732+
TORCH_CHECK(
733+
ySize % 2 == 0,
734+
"Y plane size must be even. Please report on TorchCodec repo.");
732735
int uvSize = ySize / 2; // NV12: UV plane is half the size of Y plane
733736
size_t totalSize = static_cast<size_t>(ySize + uvSize);
734737

@@ -767,6 +770,9 @@ UniqueAVFrame BetaCudaDeviceInterface::transferCpuFrameToGpuNV12(
767770
"Failed to copy Y plane to GPU: ",
768771
cudaGetErrorString(err));
769772

773+
TORCH_CHECK(
774+
height % 2 == 0,
775+
"height must be even. Please report on TorchCodec repo.");
770776
err = cudaMemcpy2D(
771777
gpuFrame->data[1],
772778
gpuFrame->linesize[1],

0 commit comments

Comments
 (0)