Skip to content

Handle unexpected struct_name in cuda.coop kernel codegen#8751

Open
randomizedcoder wants to merge 1 commit into
NVIDIA:mainfrom
randomizedcoder:fix/coop-types-unbound-vars-clean
Open

Handle unexpected struct_name in cuda.coop kernel codegen#8751
randomizedcoder wants to merge 1 commit into
NVIDIA:mainfrom
randomizedcoder:fix/coop-types-unbound-vars-clean

Conversation

@randomizedcoder
Copy link
Copy Markdown

Description

In python/cuda_cccl/cuda/coop/_types.py, Algorithm._kernel_source() assigns provide_alloc_version, storage, and sync only inside an if/elif chain that checks whether self.struct_name starts with "Warp" or "Block". If neither matches, all three variables are used unbound on subsequent lines, raising UnboundLocalError.

Currently only "Warp" and "Block" prefixes exist, so this doesn't trigger in practice. The fix adds an else clause with a clear ValueError so the failure mode is explicit rather than a confusing UnboundLocalError.

Change

             elif self.struct_name.startswith("Block"):
                 provide_alloc_version = True
                 storage = "__shared__ temp_storage_t temp_storage;"
                 sync = "__syncthreads();"
+            else:
+                raise ValueError(f"Unsupported struct_name: {self.struct_name!r}, expected 'Warp*' or 'Block*'")

Found via pylint 3.3.7 (E0606: possibly-used-before-assignment).

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

In Algorithm._kernel_source(), provide_alloc_version, storage, and sync
are only assigned when struct_name starts with "Warp" or "Block". If
neither matches, these variables are used unbound, raising
UnboundLocalError. Added an else clause with a clear ValueError.

Found via pylint 3.3.7 (E0606: possibly-used-before-assignment).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@randomizedcoder randomizedcoder requested a review from a team as a code owner April 30, 2026 00:54
@randomizedcoder randomizedcoder requested a review from tpn April 30, 2026 00:54
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented Apr 30, 2026

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.

@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 30, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

1 participant