Skip to content

Commit b6500f3

Browse files
committed
Backport bytes compiler options support to CUDA 12
Carry forward the runtime behavior from #1665/#1698 with its nvJitLink regression and NVVM bytes-options case. Extracted from #3173 so source integration can be reviewed independently. Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent 0c73a57 commit b6500f3

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎cuda_bindings_12/cuda/bindings/_internal/utils.pyx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj,
9898
nested_ptr.reset(nested_vec, True)
9999
for i, obj_i in enumerate(obj):
100100
if ResT is char:
101-
obj_i_bytes = (<str?>(obj_i)).encode()
101+
obj_i_type = type(obj_i)
102+
if obj_i_type is str:
103+
obj_i_bytes = obj_i.encode("utf-8")
104+
elif obj_i_type is bytes:
105+
obj_i_bytes = obj_i
106+
else:
107+
raise TypeError(
108+
f"Expected str or bytes, got {obj_i_type.__name__}")
102109
str_len = <size_t>(len(obj_i_bytes)) + 1 # including null termination
103110
deref(nested_res_vec)[i].resize(str_len)
104111
obj_i_ptr = <char*>(obj_i_bytes)

‎cuda_bindings_12/tests/test_nvjitlink.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def test_create_and_destroy(option):
100100
nvjitlink.destroy(handle)
101101

102102

103+
@pytest.mark.human_authored
104+
def test_create_and_destroy_bytes_options():
105+
handle = nvjitlink.create(1, [b"-arch=sm_80"])
106+
assert handle != 0
107+
nvjitlink.destroy(handle)
108+
109+
103110
@pytest.mark.parametrize("option", ARCHITECTURES)
104111
def test_complete_empty(option):
105112
handle = nvjitlink.create(1, [f"-arch={option}"])

‎cuda_bindings_12/tests/test_nvvm.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_get_buffer_empty(get_size, get_buffer):
246246
assert buffer == b"\x00"
247247

248248

249-
@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"]])
249+
@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"]])
250250
def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options):
251251
with nvvm_program() as prog:
252252
nvvm.add_module_to_program(prog, minimal_nvvmir, len(minimal_nvvmir), "FileNameHere.ll")

0 commit comments

Comments
 (0)