Skip to content

[SYCL][HIP][CUDA] Report errc::nd_range for oversized work-group size#22678

Open
zjin-lcf wants to merge 3 commits into
intel:syclfrom
zjin-lcf:sycl-hip-fix-gpu-max-wgs-error
Open

[SYCL][HIP][CUDA] Report errc::nd_range for oversized work-group size#22678
zjin-lcf wants to merge 3 commits into
intel:syclfrom
zjin-lcf:sycl-hip-fix-gpu-max-wgs-error

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

Summary

  • Throw a proper errc::nd_range exception when an oversized work-group size is requested on HIP/CUDA, instead of a generic/opaque failure.
  • Re-enable Regression/invalid_reqd_wg_size_correct_exception on HIP.

Test plan

  • Basic/gpu_max_wgs_error passes on gfx942
  • Regression/invalid_reqd_wg_size_correct_exception passes on gfx942

Relates to #22300

zjin-lcf and others added 2 commits July 19, 2026 10:51
handleInvalidWorkGroupSize only produced the expected "Total number of
work-items in a work-group cannot exceed ..." diagnostic (errc::nd_range)
for OpenCL. On HIP and CUDA the launch was rejected by the driver but the
runtime surfaced a generic error, so Basic/gpu_max_wgs_error.cpp failed.

Handle the HIP and CUDA backends explicitly and throw the same
errc::nd_range exception when the requested work-group size exceeds the
device maximum. Re-enables Basic/gpu_max_wgs_error.cpp on HIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
…on on HIP

This test passes on HIP (gfx942) with the current toolchain, so remove the
UNSUPPORTED: hip marker tracked by intel#22300.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

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.

Pull request overview

This PR improves SYCL runtime diagnostics for oversized work-group sizes on the CUDA/HIP backends by translating the underlying launch failure into a consistent sycl::errc::nd_range exception (matching the existing OpenCL behavior), and re-enables a previously-disabled HIP regression test.

Changes:

  • Add explicit CUDA/HIP handling in handleInvalidWorkGroupSize() to throw errc::nd_range when local_size total exceeds UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE.
  • Re-enable Regression/invalid_reqd_wg_size_correct_exception on HIP by removing UNSUPPORTED: hip.
  • Re-enable Basic/gpu_max_wgs_error on HIP by removing UNSUPPORTED: hip.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sycl/test-e2e/Regression/invalid_reqd_wg_size_correct_exception.cpp Re-enables the regression test on HIP.
sycl/test-e2e/Basic/gpu_max_wgs_error.cpp Re-enables the work-group-size diagnostic test on HIP (still disabled on CUDA).
sycl/source/detail/error_handling/error_handling.cpp Adds CUDA/HIP-specific translation of oversized work-group size failures into errc::nd_range.

Comment on lines 1 to 3
// REQUIRES: gpu
// UNSUPPORTED: cuda

The CUDA backend does report errc::nd_range for an oversized work-group, but
for the work-group size this test uses (max_work_item_sizes in every
dimension) the CUDA driver rejects the launch as
UR_RESULT_ERROR_OUT_OF_RESOURCES (register exhaustion), which is handled by
handleOutOfResources() and throws an nd_range exception with a different,
register-count message. Verified on an H100 that the "Total number of
work-items in a work-group cannot exceed" branch added in
handleInvalidWorkGroupSize() is reached (and matches) only when each dimension
is within limits but their product exceeds the max work-group size. Add an
explanation and tracker so the CUDA exclusion is documented.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zjin-lcf
zjin-lcf force-pushed the sycl-hip-fix-gpu-max-wgs-error branch from c756be2 to 97a1862 Compare July 20, 2026 16:06
@zjin-lcf

Copy link
Copy Markdown
Contributor Author

Not sure Copilot can continue the review.

Do you recommend the Runtime fix below ?

In handleOutOfResources(), inside the existing CUDA branch, check the work-group total against the device max before emitting the register
message:

  if (Backend == sycl::backend::ext_oneapi_cuda) {
    const size_t TotalNumberOfWIs = /* ... */;
    size_t MaxWGSize = 0;
    Adapter.call<UrApiKind::urDeviceGetInfo>(
        Device, UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE, sizeof(size_t),
        &MaxWGSize, nullptr);
    if (TotalNumberOfWIs > MaxWGSize)
      throw sycl::exception(
          make_error_code(errc::nd_range),
          "Total number of work-items in a work-group cannot exceed " +
              std::to_string(MaxWGSize));
    // ... existing register-exhaustion check (only a real register issue now) ...
  }

• The driver returns OUT_OF_RESOURCES when registers are exhausted and INVALID_WORK_GROUP_SIZE otherwise, so the "too many work-items" check now needs to live in both handlers. The PR already added it to handleInvalidWorkGroupSize(); this adds the symmetric case.
• Result: CUDA emits the exact message the test asserts for the max-size input, so you just delete // UNSUPPORTED: cuda. Cleanest, gives consistent cross-backend diagnostics.

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.

2 participants