Skip to content

Fix LaunchConfig.grid unit conversion when cluster is set - #868

Merged
leofang merged 9 commits into
mainfrom
copilot/fix-867
Aug 21, 2025
Merged

Fix LaunchConfig.grid unit conversion when cluster is set#868
leofang merged 9 commits into
mainfrom
copilot/fix-867

Conversation

Copilot AI commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

The LaunchConfig.grid parameter was incorrectly interpreted as blocks instead of clusters when .cluster is specified, causing a mismatch with the expected C++ behavior.

Problem

When using thread block clusters, the grid parameter should represent the number of clusters, not blocks. However, the original implementation treated it as blocks, leading to incorrect launch configurations.

Example from thread_block_cluster.py:

config = LaunchConfig(grid=4, cluster=2, block=32)
# Should mean: 4 clusters × 2 blocks/cluster = 8 total blocks
# But was producing: grid dim: (4, 1, 1) ❌ 

This doesn't match the C++ equivalent:

cudax::make_hierarchy(cudax::grid_dims(4), cudax::cluster_dims(2), cudax::block_dims(32));
// Where grid_dims(4) means 4 clusters, resulting in 8 total blocks

Solution

Modified _to_native_launch_config() to perform unit conversion when cluster is set, while preserving the original grid values in the LaunchConfig dataclass:

# In _to_native_launch_config()
if config.cluster:
    grid_blocks = (
        config.grid[0] * config.cluster[0],
        config.grid[1] * config.cluster[1],
        config.grid[2] * config.cluster[2]
    )
    drv_cfg.gridDimX, drv_cfg.gridDimY, drv_cfg.gridDimZ = grid_blocks

This approach maintains the dataclass contract - users can still access their original grid values transparently, but the conversion happens when interfacing with the CUDA driver.

Results

LaunchConfig object (preserved):

config = LaunchConfig(grid=4, cluster=2, block=32)
config.grid    # Returns (4, 1, 1) - original user input

Native CUDA configuration (converted):

grid dim: (8, 1, 1)      # Correct: 4 clusters × 2 blocks = 8 blocks
cluster dim: (2, 1, 1)
block dim: (32, 1, 1)

The fix handles all dimensionalities (1D, 2D, 3D) and preserves existing functionality for non-cluster configurations. The enhanced example now demonstrates and validates the correct behavior using pinned memory to verify the grid conversion works as expected.

Fixes #867.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author

@leofang 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 20, 2025
@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

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.

Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>
Copilot AI changed the title [WIP] LaunchConfig.grid is in the wrong unit if .cluster is set Fix LaunchConfig.grid unit conversion when cluster is set Aug 20, 2025
Copilot AI requested a review from leofang August 20, 2025 16:27

@leofang leofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • Please add a note to LaunchConfig's docstring, explaining the expectation that the units for the grid / cluster / block are the next object in the hierarchy (for grid it's cluster if present, otherwise block / block / thread)

  • Please add a release note entry to docs/source/release/0.X.Y.rst, and note that this is a breaking change. Make sure to follow the style we have (by checking how we wrote previous release notes).

Comment thread cuda_core/tests/test_launcher.py Outdated
Comment thread cuda_core/verify_cluster_fix.py Outdated
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in CCCL Aug 20, 2025
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

Copilot AI commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author
  • Please add a note to LaunchConfig's docstring, explaining the expectation that the units for the grid / cluster / block are the next object in the hierarchy (for grid it's cluster if present, othe...

Added note to LaunchConfig docstring explaining grid units (clusters when cluster is set, blocks otherwise) and created release note entry in 0.3.3-notes.rst documenting this as a breaking change. Changes committed in b9ca1bc.

Copilot AI requested a review from leofang August 20, 2025 17:03
Comment thread cuda_core/cuda/core/experimental/_launch_config.py Outdated
Comment thread cuda_core/cuda/core/experimental/_launch_config.py Outdated
Comment thread cuda_core/docs/source/release/0.3.3-notes.rst Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please rename this file to literally "0.X.Y-notes.rst", because we don't know yet what's the next release version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed the file to 0.X.Y-notes.rst in commit 681540b.

Comment thread cuda_core/tests/test_launcher.py Outdated
@leofang

leofang commented Aug 20, 2025

Copy link
Copy Markdown
Member

@copilot please update the PR based on the new review comments

…lify tests

Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

Copilot AI commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author

@copilot please update the PR based on the new review comments

Updated the PR based on all review comments in commit 681540b.

Copilot AI requested a review from leofang August 20, 2025 20:10

@leofang leofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot PTAL

Comment thread cuda_core/cuda/core/experimental/_launch_config.py Outdated
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

Copilot AI commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author

@copilot PTAL

Updated the PR based on the review feedback. The grid conversion has been moved from LaunchConfig.__post_init__ to _to_native_launch_config() to preserve the dataclass contract while still performing the necessary unit conversion when interfacing with CUDA drivers. Commit: 1c05792

@leofang leofang added the breaking Breaking changes are introduced label Aug 20, 2025
@leofang

leofang commented Aug 20, 2025

Copy link
Copy Markdown
Member

/ok to test 50866b8

@github-actions

This comment has been minimized.

@leofang leofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot could you check the pre-commit failures? Empty lines should not contain white spaces.

Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>

Copilot AI commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

@copilot could you check the pre-commit failures? Empty lines should not contain white spaces.

Fixed the pre-commit whitespace issues by removing trailing spaces from empty lines in the CUDA C++ code. Commit: 114f0f9

Copilot AI requested a review from leofang August 21, 2025 00:19

@leofang leofang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot

Comment thread cuda_core/docs/source/release/0.X.Y-notes.rst
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>
Copilot AI requested a review from leofang August 21, 2025 00:31
@leofang

leofang commented Aug 21, 2025

Copy link
Copy Markdown
Member

/ok to test 035c91b

@leofang
leofang marked this pull request as ready for review August 21, 2025 00:53
@leofang

leofang commented Aug 21, 2025

Copy link
Copy Markdown
Member

@pciolkosz could you also take a look? (Can't add you as a reviewer for some reason.)

@pciolkosz

Copy link
Copy Markdown

Looks good 👍

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Aug 21, 2025
@leofang
leofang merged commit bb1fe80 into main Aug 21, 2025
48 checks passed
@leofang
leofang deleted the copilot/fix-867 branch August 21, 2025 01:49
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Aug 21, 2025
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

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

Labels

breaking Breaking changes are introduced bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

LaunchConfig.grid is in the wrong unit if .cluster is set

4 participants