Repository navigation
Commit a8ebc34
committed
Make check_nvvm_compiler_options return False when nvvm is unavailable
check_nvvm_compiler_options() has two guards meant to answer "options not
supported" instead of failing when nvvm is missing. Neither one works.
1. The optional import.
try:
from cuda.bindings import nvvm
except ModuleNotFoundError as exc:
if exc.name == "nvvm":
return False
raise
`from <pkg> import <sub>` never raises ModuleNotFoundError for a missing
submodule: importlib swallows it in _handle_fromlist() and the IMPORT_FROM
opcode raises a plain ImportError. And ModuleNotFoundError.name is always
the fully qualified name, so even where one is raised it is
"cuda.bindings.nvvm", never "nvvm". In a tree where the nvvm extension has
not been built, the public API therefore raises
ImportError: cannot import name 'nvvm' from 'cuda.bindings'
Import via importlib.import_module(), which does raise
ModuleNotFoundError with name == "cuda.bindings.nvvm", and compare against
that. This mirrors cuda.pathfinder._optional_cuda_import, which already
uses the fully qualified name for the same "is the target module itself
missing, or one of its dependencies?" distinction. A missing dependency
still propagates, unchanged.
2. The libNVVM probe.
if _inspect_function_pointer("__nvvmCreateProgram") == 0:
return False
A zero pointer only covers "libNVVM is loaded but does not export the
symbol". _inspect_function_pointer() loads libNVVM lazily, so when it is
not installed at all the call raises DynamicLibNotFoundError instead of
returning 0. tests/test_utils.py already knows this: its
_is_libnvvm_available() helper wraps the identical call in
`except DynamicLibNotFoundError`. Catch it here too.
This is what test_check_nvvm_compiler_options_no_libnvvm asserts, and that
test errors out on a machine without libNVVM today. It is on the
always-skipped list in #2077, which is why nobody has seen it fail.
Adds three tests that simulate both conditions without needing an unbuilt
tree or a machine without libNVVM, so they run in CI.1 parent 3bd069a commit a8ebc34
2 files changed
Lines changed: 90 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | | - | |
| 57 | + | |
55 | 58 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
| 66 | + | |
61 | 67 | | |
62 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
0 commit comments