Skip to content

fix(cuda_core): use nvJitLink-compatible 0/1 values for boolean linker options - #3128

Open
lijinf2 wants to merge 3 commits into
NVIDIA:mainfrom
lijinf2:fix/6621758-nvjitlink-bool-to-int-options
Open

lijinf2 wants to merge 3 commits into
NVIDIA:mainfrom
lijinf2:fix/6621758-nvjitlink-bool-to-int-options

Conversation

@lijinf2

@lijinf2 lijinf2 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes nvbug 6621758.

nvJitLink's input validation was tightened upstream (CUDA Toolkit 13.6) to strictly require 0/1 for boolean-valued options and non-negative integers for -split-compile/-split-compile-extended.

cuda_core's LinkerOptions._prepare_nvjitlink_options() was emitting Python-style true/false strings and raw f"{bool}" ("True"/"False"), which the newer nvJitLink rejects with ERROR_UNRECOGNIZED_OPTION.

This PR changes the nvJitLink backend option formatting to:

  • -ftz, -prec-div, -prec-sqrt, -fma: emit 1/0 instead of true/false
  • -split-compile, -split-compile-extended: coerce value with int(...) so a bool is sent as 1/0 rather than the literal string "True"/"False"

The NVRTC backend (--ftz=true/false) and NVVM backend (-ftz=1/0, already correct) are untouched. This only affects the nvJitLink-specific option formatting.

Backward compatibility

Verified directly on nvJitLink 13.2.51, 13.4.92 (both released), and a 13.6.0 nightly build:

Option 13.2 / 13.4 (released) 13.6 (nightly, new validation)
-ftz=true / -ftz=1 both OK true FAILS, 1 OK
-split-compile=True / =1 both OK True FAILS, 1 OK

Released toolkits accept both the old and new formats, so always emitting 1/0 is backward compatible and does not regress any currently supported CUDA 13.x toolkit, while fixing compatibility with newer/nightly toolkits.

Testing

  • Reproduced and verified fix against nightly CUDA 13.6 toolkit on real GPU hardware: test_linker.py + test_program.py (241 tests) and test_program_cache.py (237 tests) pass with zero failures.

@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 2026

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.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Oct 16, 2026
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Boolean nvJitLink options for flush-to-zero, precise division, precise square root, and fused multiply-add are now serialized as 0 or 1 instead of false or true. Split-compilation option values are also formatted numerically. LTO-enabled links using these settings can now complete and return compiled object code.

nvJitLink boolean options now serialize as 0 or 1, and split-compile option values are converted to integers. Tests check the ftz serialization and an LTO-enabled cubin link.

Changes: nvJitLink Option Serialization

Layer / File(s) Summary
Format nvJitLink options
cuda_core/cuda/core/_linker.pyx, cuda_core/tests/test_linker.py
The linker formats ftz, prec-div, prec-sqrt, and fma as 0 or 1. It converts split_compile and split_compile_extended values to integers. Tests expect -ftz=1 and verify that linking with LTO and the four boolean options returns an ObjectCode.

Suggested reviewers: andy-jost

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to 746df

The linker formatting changes work as intended, but some serialized values are not pinned by tests. A future regression could escape detection on compatible nvJitLink versions or with boolean split-compile inputs, leaving a bounded test-coverage risk.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 36ecdafb-5184-41f1-a5f6-bad397b13885
📥 Commits

Reviewing files that changed from the base of the PR and between 2224499 and 0e5afde.

📒 Files selected for processing: 2
  • cuda_core/cuda/core/_linker.pyx
  • cuda_core/tests/test_linker.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_core/cuda/core/_linker.pyx
@lijinf2 lijinf2 self-assigned this Oct 16, 2026
@lijinf2 lijinf2 added the bug Something isn't working label Oct 16, 2026
@lijinf2 lijinf2 added this to the cuda.core 1.3.0 milestone Oct 16, 2026
@lijinf2

lijinf2 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c539cc2

@github-actions

Copy link
Copy Markdown
Contributor

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

I think this is a breaking change on the nvJitLink side. We should move the bug to their module and ask them to triage/fix.

@lijinf2

lijinf2 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

I think this is a breaking change on the nvJitLink side. We should move the bug to their module and ask them to triage/fix.

Agreed, This does look like a behavior change on the nvJitLink side. The old true/false format stopped being accepted starting with a recent build. Let me reach out to the nvJitLink team to understand why and report back before we decide how to proceed.

@lijinf2

lijinf2 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed with the nvJitLink team: only 0/1 has ever actually worked. Other values (true/false/True) can be set without error, but fail once an LTO-enabled link actually runs. Fix stays as emitting 0/1.

Added an LTO-enabled runtime test, which closes a gap in previous coverage (option-formatting checks alone don't catch this).

Ready for re-review.

@lijinf2

lijinf2 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 746df99

@lijinf2
lijinf2 requested a review from leofang October 19, 2026 22:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments: 2
cuda_core/tests/test_linker.py: 1

213-236: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

suggestion: Assert all four formatted options.

The LTO link checks acceptance only. It does not detect a regression to true/false on versions that accept both spellings. Add focused serialization assertions and keep the runtime link as the end-to-end check.

Suggested test assertion
-    options = LinkerOptions(arch="sm_80", debug=True, ftz=True, max_register_count=32)
+    options = LinkerOptions(
+        arch="sm_80",
+        debug=True,
+        ftz=True,
+        prec_div=True,
+        prec_sqrt=True,
+        fma=True,
+        max_register_count=32,
+    )
...
     assert "-ftz=1" in options_str
+    assert "-prec-div=1" in options_str
+    assert "-prec-sqrt=1" in options_str
+    assert "-fma=1" in options_str
cuda_core/cuda/core/_linker.pyx: 1

430-440: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

suggestion: Add direct serialization coverage for boolean split-compile inputs. bool is an int subtype, and the repository already uses ProgramOptions(split_compile=True). The current LinkerOptions tests use only integers and do not inspect serialized flags, so reverting int(...) would leave True and False regressions undetected.

+def test_linker_options_split_compile_serializes_booleans():
+    options = LinkerOptions(split_compile=True, split_compile_extended=False)
+    flags = options.as_bytes("nvjitlink")
+    assert b"-split-compile=1" in flags
+    assert b"-split-compile-extended=0" in flags

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: a3a7523f-7d13-4280-8400-4bda3c7dce70
📥 Commits

Reviewing files that changed from the base of the PR and between c539cc2 and 746df99.

📒 Files selected for processing: 1
  • cuda_core/tests/test_linker.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

This branch has not been deployed

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

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants