-
Notifications
You must be signed in to change notification settings - Fork 266
[NVVM] Expose nvvm version detection in cuda.bindings.utils. #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abhilash1910
wants to merge
9
commits into
NVIDIA:main
Choose a base branch
from
abhilash1910:nvvm_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65fb587
refactor cuda bindings utils for nvvm
abhilash1910 10943c8
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] a7ef552
refresh
abhilash1910 4f3b442
renaming
abhilash1910 686c62a
exceptions
abhilash1910 3c5043c
refresh
abhilash1910 b1747af
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] d19960e
refresh
abhilash1910 4a7c3e9
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE | ||
|
|
||
| from typing import Sequence | ||
|
|
||
| _PRECHECK_NVVM_IR = """target triple = "nvptx64-unknown-cuda" | ||
| target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" | ||
|
|
||
| define void @dummy_kernel() {{ | ||
| entry: | ||
| ret void | ||
| }} | ||
|
|
||
| !nvvm.annotations = !{{!0}} | ||
| !0 = !{{void ()* @dummy_kernel, !"kernel", i32 1}} | ||
|
|
||
| !nvvmir.version = !{{!1}} | ||
| !1 = !{{i32 {major}, i32 {minor}, i32 {debug_major}, i32 {debug_minor}}} | ||
| """ | ||
|
|
||
|
|
||
| def check_nvvm_compiler_options(options: Sequence[str]) -> bool: | ||
| """ | ||
| Abstracted from https://github.com/NVIDIA/numba-cuda/pull/681 | ||
|
|
||
| Check if the specified options are supported by the current libNVVM version. | ||
|
|
||
| The options are a list of bytes, each representing a compiler option. | ||
|
|
||
| If the test program fails to compile, the options are not supported and False | ||
| is returned. | ||
|
|
||
| If the test program compiles successfully, True is returned. | ||
|
|
||
| cuda.bindings.nvvm returns exceptions instead of return codes. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| options : Sequence[bytes] | ||
| List of compiler options as bytes (e.g., [b"-arch=compute_90", b"-g"]). | ||
|
|
||
| Returns | ||
| ------- | ||
| bool | ||
| True if the options are supported, False otherwise. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from cuda.bindings.utils import check_nvvm_options | ||
| >>> check_nvvm_options([b"-arch=compute_90", b"-g"]) | ||
| True | ||
| """ | ||
| try: | ||
| from cuda.bindings import nvvm | ||
| except ModuleNotFoundError as exc: | ||
| if exc.name == "nvvm": | ||
| return False | ||
| raise | ||
|
|
||
| from cuda.bindings._internal.nvvm import _inspect_function_pointer | ||
|
|
||
| if _inspect_function_pointer("__nvvmCreateProgram") == 0: | ||
| return False | ||
|
|
||
| program = nvvm.create_program() | ||
| try: | ||
| major, minor, debug_major, debug_minor = nvvm.ir_version() | ||
| precheck_ir = _PRECHECK_NVVM_IR.format( | ||
| major=major, | ||
| minor=minor, | ||
| debug_major=debug_major, | ||
| debug_minor=debug_minor, | ||
| ) | ||
| precheck_ir_bytes = precheck_ir.encode("utf-8") | ||
| nvvm.add_module_to_program( | ||
| program, | ||
| precheck_ir_bytes, | ||
| len(precheck_ir_bytes), | ||
| "precheck.ll", | ||
| ) | ||
|
|
||
| nvvm.compile_program(program, len(options), options) | ||
| except nvvm.nvvmError as e: | ||
| if e.status == nvvm.Result.ERROR_INVALID_OPTION: | ||
| return False | ||
| raise | ||
| finally: | ||
| nvvm.destroy_program(program) | ||
| return True |
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
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.
Uh oh!
There was an error while loading. Please reload this page.