Skip to content

Fix zero-extent GPU image launches - #6505

Open
arcusbuilds wants to merge 2 commits into
NVIDIA:mainfrom
arcusbuilds:fix/zero-extent-kernel-launches
Open

arcusbuilds wants to merge 2 commits into
NVIDIA:mainfrom
arcusbuilds:fix/zero-extent-kernel-launches

Conversation

@arcusbuilds

@arcusbuilds arcusbuilds commented Sep 22, 2026 •

Copy link
Copy Markdown

Category

Bug fix

Description

Return from the shared GPU Flip and color conversion launchers when a sample has zero pixels, before computing launch dimensions. This prevents host-side division by zero for zero-extent samples in a nonempty batch. Fixes #6504.

Additional information

The guards are in the launchers, so all callers use them. A mixed-batch GTest sends an empty sample and a normal RGB pixel through Flip and color conversion, then checks the BGR output. A second test checks that an unsupported conversion still fails for an empty sample.

Tests

  • New GTests: ColorSpaceConversionTest.ZeroExtentSampleGPU, ColorSpaceConversionTest.ZeroExtentUnsupportedConversionGPU
  • Run locally: no DALI build is available, and the Linux environment has no CUDA toolkit. CI results are pending.

Checklist

  • Documentation: N/A
  • DALI team requirements: N/A

REQ IDs: N/A
JIRA TASK: N/A

Skip zero-pixel samples in the shared color conversion and Flip launchers before computing launch dimensions. Add a mixed-batch regression test.

Fixes NVIDIA#6504

Signed-off-by: Srijan Keshri <212402043+arcusbuilds@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The runtime fix appears correct, but the explicit validation requirements and the outstanding test and copyright requirements should be addressed before merging.

Findings

  1. P2 Generic validation error ▶
  2. P2 Required test cases missing ▶
Summary

This PR prevents zero-extent GPU samples from producing zero launch dimensions in the shared Flip and color-conversion launchers. The latest revision preserves unsupported-conversion validation for empty samples and adds a regression test for that case.

  • Returns before computing CUDA launch dimensions when Flip receives a zero-volume sample.
  • Validates the conversion pair before returning for zero-pixel color conversions.
  • Tests a mixed empty/nonempty GPU batch and an unsupported empty conversion.

Reviews (2) · Last reviewed commit: "Preserve color conversion validation for..."

Comment thread dali/kernels/imgproc/color_manipulation/color_space_conversion_kernel.cuh Outdated
Comment on lines +64 to +100
TEST(ColorSpaceConversionTest, ZeroExtentSampleGPU) {
TensorList<CPUBackend> input;
input.Resize(TensorListShape<3>({{0, 2, 3}, {1, 1, 3}}), DALI_UINT8);
input.SetLayout("HWC");
auto *pixel = input.mutable_tensor<uint8_t>(1);
pixel[0] = 1;
pixel[1] = 2;
pixel[2] = 3;

Pipeline pipe(2, 1, 0);
pipe.AddExternalInput("input");
pipe.AddOperator(OpSpec("Flip")
.AddArg("device", "gpu")
.AddInput("input", StorageDevice::GPU)
.AddOutput("flipped", StorageDevice::GPU));
pipe.AddOperator(OpSpec("ColorSpaceConversion")
.AddArg("device", "gpu")
.AddArg("image_type", DALI_RGB)
.AddArg("output_type", DALI_BGR)
.AddInput("flipped", StorageDevice::GPU)
.AddOutput("output", StorageDevice::GPU));
pipe.Build(std::vector<std::pair<std::string, std::string>>{{"output", "gpu"}});
pipe.SetExternalInput("input", input);

Workspace ws;
pipe.Run();
pipe.Outputs(&ws);
TensorList<CPUBackend> output;
output.Copy(ws.Output<GPUBackend>(0));
EXPECT_EQ(output.num_samples(), 2);
EXPECT_EQ(output.tensor_shape(0), input.tensor_shape(0));
EXPECT_EQ(output.tensor_shape(1), input.tensor_shape(1));
const auto *converted = output.tensor<uint8_t>(1);
EXPECT_EQ(converted[0], 3);
EXPECT_EQ(converted[1], 2);
EXPECT_EQ(converted[2], 1);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Required test cases missing

This new operator test only covers a mixed GPU batch. The repository's test requirements also require new operator tests to cover empty input, batch_size=1, boundary values, CPU and GPU variants, and invalid-input rejection. Add the missing cases in the appropriate test suites before merging.

Rule Used: New operator tests must cover: empty input, single sample (batch_size=1), boundary values, CPU and GPU variants, and invalid-input rejection (via assert_raises(..., glob=...) with the expected message pattern). (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@arcusbuilds arcusbuilds Sep 22, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is a targeted C++ regression for zero-extent GPU samples: the new tests cover a mixed batch and a single zero-extent sample with an unsupported conversion. Existing tests cover ordinary CPU/GPU conversions. The new GPU tests have not run locally;

NVIDIA CI is awaiting workflow vetting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That context is reasonable. The mixed two-sample GPU test exercises the zero-extent early return together with a nonempty sample and verifies the converted result, while ZeroExtentUnsupportedConversionGPU confirms that the guard does not bypass conversion validation. Existing parameterized tests provide ordinary CPU/GPU conversion coverage, so requiring separate boundary-value, batch-size-one, and invalid-input matrices here was overly broad for this targeted regression. I’m withdrawing the “required test cases missing” request; the added tests are sufficient for this fix.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That’s fair. The existing typed GenericConversionTest suites already exercise the supported CPU/GPU conversion paths, while these additions specifically cover the new zero-extent GPU behavior: a mixed batch through both Flip and conversion, plus preservation of the unsupported-conversion error for an empty sample. The broader empty-input, boundary-value, and batch_size=1 matrix I requested is not necessary to validate this targeted launcher regression, so I’m withdrawing that comment.

@greptile-apps

This comment has been minimized.

Keep unsupported conversion pairs rejected when the pixel count is zero, and cover the case in the existing GPU operator test.

Signed-off-by: Srijan Keshri <212402043+arcusbuilds@users.noreply.github.com>
conversion != kYCbCr_TO_BGR && conversion != kYCbCr_TO_RGB &&
conversion != kYCbCr_TO_GRAY && conversion != kGRAY_TO_RGB &&
conversion != kGRAY_TO_BGR && conversion != kGRAY_TO_YCbCr) {
DALI_FAIL(make_string("conversion not supported ", in_type, " to ", out_type));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Generic validation error

The new zero-pixel validation uses DALI_FAIL for a user-facing input error and reports only conversion not supported <input> to <output>. Repository requirements say new validation must use a specific exception or typed DALI error, and the message must identify the operator or parameters, show the supported versus actual values, and end with a complete sentence. This requirement must be satisfied before merging.

Rule Used: assert is for internal invariants (compiled out in release). User-facing input validation must throw — prefer specific C++ exceptions (std::invalid_argument, std::out_of_range, std::runtime_error) or DALI errors that build on them (e.g., `dal... (source)

Knowledge Base Used: Core runtime and kernel library

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The zero-pixel path intentionally uses the same DALI_FAIL and message as the existing unsupported-conversion fallback in this launcher (line 217). That keeps the error behavior consistent for empty and non-empty inputs. Changing the exception type and message in both paths would be a separate change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That’s a valid clarification. The zero-pixel guard must still reject unsupported conversions before returning, since otherwise the early return would bypass the existing fallback at line 217. Reusing the same DALI_FAIL and message keeps behavior consistent between empty and non-empty inputs, so the validation concern does not apply here. I’m retracting this comment; no change is needed for this path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU Flip and color conversion divide by zero for zero-extent samples

3 participants