Preserve literal arguments as constants during lowering #415
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.
Contributors can view more details about this message here.
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.
Contributors can view more details about this message here.
/ok to test 9b25ccec2253f1ed9c8c91d225f604114322a605
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/NVIDIA/numba-cuda-mlir/pull/415?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- recent_review_start -->
No actionable comments were generated in the recent review.
<details>
<summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
<dl>
<dd>
<!-- review_info_content -->
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
19fdbf4d-6c2a-4c85-9380-409643916fed</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
Reviewing files that changed from the base of the PR and between bd28aef6eef61e0fc0fd69257cf1b119925842b1 and 9b25ccec2253f1ed9c8c91d225f604114322a605.
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary>
<dl>
<dd>
src/numba_cuda_mlir/mlir_lowering.py
src/numba_cuda_mlir/tools.py
tests/test_literals.py</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
</dd>
</dl>
</details>
<!-- recent_review_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>Walkthrough</strong></summary>
<dl>
<dd>
Important: Integer and Boolean literal types now remain available for specialization. Lowering uses literal values as constants, and recursive calls with different argument types route through dispatcher compilation.
Changes: Literal specialization
|Layer / File(s)|Summary|
|:---|:---|
|Preserve and lower literal arguments <br> src/numba_cuda_mlir/tools.py, src/numba_cuda_mlir/mlir_lowering.py, tests/test_literals.py|Argument normalization preserves Boolean and integer literal types. Lowering assigns their specialized values as constants. Tests cover scalar literals and literal loop bounds.|
|Route calls by argument types <br> src/numba_cuda_mlir/mlir_lowering.py, tests/test_literals.py|Recursive calls use dispatcher compilation when folded argument types differ from the current function’s types. Tests cover literal-based dispatch and device-function calls.|
Suggested reviewers: atmnp
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<!-- change_assessment_start -->
<strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong>
<!-- change_assessment_commit:"9b25ccec2253f1ed9c8c91d225f604114322a605" -->
Change: Bug fix
<!-- change_assessment_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>9b25c</code></summary>
<dl>
<dd>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to 9b25c
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"9b25ccec2253f1ed9c8c91d225f604114322a605","coveredCommitId":"9b25ccec2253f1ed9c8c91d225f604114322a605","kind":"reviewed"} -->
No actionable issue is established for this change; it is mergeable after normal checks.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
Doc Preview CI
:---:
| <p></p> :rocket: View preview at <br> https://nvidia.github.io/numba-cuda-mlir/pr-preview/pr-415/ <br><br>
| <h6><br> Preview will be ready when the GitHub Pages deployment is complete. <br><br></h6>
<!-- Sticky Pull Request Commentpr-preview -->
Approved these changes.
Doc Preview CI
:---:
Preview removed because the pull request was closed or merged.
<!-- Sticky Pull Request Commentpr-preview -->
atmnp
tpn
Specialized integer and boolean arguments currently remain runtime values during MLIR lowering. A loop such as
for i in range(count)can therefore retain a dynamic bound even whencountisLiteral[int](8), preventing promotion of a per-thread local array into registers.Materialize these arguments through the existing constant-lowering path while retaining their ABI slots. Keep literal values in device-function symbols so different specializations cannot share a constant body, and route recursive calls to the specialization selected by their argument types.
Validation: six code-generation regressions fail before the fix; the focused compiler, literal-dispatch, extension, and device-function suites pass with 159 passed, 1 existing xfail. Tests cover literal constants, ordinary loop bounds, runtime arguments following literal arguments, distinct no-inline specializations, and recursion. Pre-commit checks pass. Local tests used current Python sources with existing v0.5.4 native assets; a fresh native build remains for CI.