Handle unexpected struct_name in cuda.coop kernel codegen#8751
Open
randomizedcoder wants to merge 1 commit into
Open
Handle unexpected struct_name in cuda.coop kernel codegen#8751randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
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>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
python/cuda_cccl/cuda/coop/_types.py,Algorithm._kernel_source()assignsprovide_alloc_version,storage, andsynconly inside an if/elif chain that checks whetherself.struct_namestarts with"Warp"or"Block". If neither matches, all three variables are used unbound on subsequent lines, raisingUnboundLocalError.Currently only "Warp" and "Block" prefixes exist, so this doesn't trigger in practice. The fix adds an
elseclause with a clearValueErrorso the failure mode is explicit rather than a confusingUnboundLocalError.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
🤖 Generated with Claude Code