Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a52e562

Browse files
authored
Merge pull request NVIDIA#423 from ksimpson-work/linker-log-test
Add error log producing test
2 parents 03001e5 + 8f075da commit a52e562

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

cuda_core/tests/test_linker.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from cuda.core.experimental import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker
88
from cuda.core.experimental._module import ObjectCode
9+
from cuda.core.experimental._utils import CUDAError
910

1011
ARCH = "sm_" + "".join(f"{i}" for i in Device().compute_capability)
1112

@@ -21,6 +22,12 @@
2122
if not is_culink_backend:
2223
from cuda.bindings import nvjitlink
2324

25+
nvJitLinkError = nvjitlink.nvJitLinkError
26+
else:
27+
28+
class nvJitLinkError(Exception):
29+
pass
30+
2431

2532
@pytest.fixture(scope="function")
2633
def compile_ptx_functions(init_cuda):
@@ -135,10 +142,23 @@ def test_linker_link_invalid_target_type(compile_ptx_functions):
135142

136143
def test_linker_get_error_log(compile_ptx_functions):
137144
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'"
142162

143163

144164
def test_linker_get_info_log(compile_ptx_functions):

0 commit comments

Comments
 (0)