|
6 | 6 |
|
7 | 7 | from cuda.core.experimental import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker |
8 | 8 | from cuda.core.experimental._module import ObjectCode |
| 9 | +from cuda.core.experimental._utils import CUDAError |
9 | 10 |
|
10 | 11 | ARCH = "sm_" + "".join(f"{i}" for i in Device().compute_capability) |
11 | 12 |
|
|
21 | 22 | if not is_culink_backend: |
22 | 23 | from cuda.bindings import nvjitlink |
23 | 24 |
|
| 25 | + nvJitLinkError = nvjitlink.nvJitLinkError |
| 26 | +else: |
| 27 | + |
| 28 | + class nvJitLinkError(Exception): |
| 29 | + pass |
| 30 | + |
24 | 31 |
|
25 | 32 | @pytest.fixture(scope="function") |
26 | 33 | def compile_ptx_functions(init_cuda): |
@@ -135,10 +142,23 @@ def test_linker_link_invalid_target_type(compile_ptx_functions): |
135 | 142 |
|
136 | 143 | def test_linker_get_error_log(compile_ptx_functions): |
137 | 144 | options = LinkerOptions(arch=ARCH) |
138 | | - linker = Linker(*compile_ptx_functions, options=options) |
139 | | - linker.link("cubin") |
140 | | - log = linker.get_error_log() |
141 | | - assert isinstance(log, str) |
| 145 | + |
| 146 | + replacement_kernel = """ |
| 147 | +extern __device__ int Z(); |
| 148 | +extern __device__ int C(int a, int b); |
| 149 | +__global__ void A() { int result = C(Z(), 1);} |
| 150 | +""" |
| 151 | + dummy_program = Program(replacement_kernel, "c++", ProgramOptions(relocatable_device_code=True)).compile("ptx") |
| 152 | + linker = Linker(dummy_program, *(compile_ptx_functions[1:]), options=options) |
| 153 | + try: |
| 154 | + linker.link("cubin") |
| 155 | + |
| 156 | + except (nvJitLinkError, CUDAError): |
| 157 | + log = linker.get_error_log() |
| 158 | + assert isinstance(log, str) |
| 159 | + # TODO when 4902246 is addressed, we can update this to cover nvjitlink as well |
| 160 | + if is_culink_backend: |
| 161 | + assert log.rstrip("\x00") == "error : Undefined reference to '_Z1Zv' in 'None_ptx'" |
142 | 162 |
|
143 | 163 |
|
144 | 164 | def test_linker_get_info_log(compile_ptx_functions): |
|
0 commit comments