Skip to content

HIP cooperative kernel launch#22668

Open
zjin-lcf wants to merge 2 commits into
intel:syclfrom
zjin-lcf:hip-cooperative-kernel-launch
Open

HIP cooperative kernel launch#22668
zjin-lcf wants to merge 2 commits into
intel:syclfrom
zjin-lcf:hip-cooperative-kernel-launch

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

No description provided.

zjin-lcf and others added 2 commits July 18, 2026 07:51
Implement the cooperative-group-count occupancy query for the HIP (AMD)
adapter, which previously returned UR_RESULT_ERROR_UNSUPPORTED_FEATURE and
forced the SYCL runtime onto a coarse 0/1 host-side fallback for
kernel::ext_oneapi_get_info<max_num_work_groups>.

As noted in intel#21803, a direct port of the CUDA implementation does
not work: hipOccupancyMaxActiveBlocksPerMultiprocessor expects a host
function pointer, whereas our kernel handle (hKernel->get()) is a
module-loaded hipFunction_t. Use the module-occupancy entry point
hipModuleOccupancyMaxActiveBlocksPerMultiprocessor instead, mirroring the
existing hipModuleOccupancyMaxPotentialBlockSize usage in the adapter.

The total suggested group count is the per-CU occupancy multiplied by the
device multiprocessor (compute-unit) count. When the per-CU occupancy is 0,
fall back to reporting 1 group if the requested work-group size, dynamic
local memory, and per-block register usage all fit within device limits,
matching the CUDA adapter's semantics.

Closes: intel#21803

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

The HIP adapter previously ignored the UR_KERNEL_LAUNCH_FLAG_COOPERATIVE
launch property and always issued an ordinary launch, so the work-groups of
a root-group kernel were not guaranteed to be co-resident. In addition, the
amdgpu libspirv __spirv_ControlBarrier always emitted a work-group scope
barrier regardless of the requested execution scope, so a Device/CrossDevice
(root-group) barrier only synchronized within a work-group.

Issue a cooperative launch via hipModuleLaunchCooperativeKernel when the
COOPERATIVE flag is set, and lower a Device/CrossDevice execution scope
barrier to the ROCm device library grid synchronization (__ockl_grid_sync),
which is valid because the launch is now cooperative. This makes root-group
synchronization work end-to-end on AMD GPUs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zjin-lcf
zjin-lcf requested review from a team, Maetveis and wenju-he as code owners July 18, 2026 15:59
@zjin-lcf
zjin-lcf requested a review from pbalcer July 18, 2026 15:59

@wenju-he wenju-he 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.

libclc change LGTM

// A Device/CrossDevice execution scope corresponds to a root-group barrier
// that must synchronize every work-item in the grid, not just the work-group.
if (scope_execution == Device || scope_execution == CrossDevice) {
__ockl_grid_sync();

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.

Looks good to me for now. Long term, the __ockl_grid_sync implementation should be ported upstream clc folder at https://github.com/llvm/llvm-project/tree/main/libclc/clc/lib/amdgpu/synchronization and called from here.

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