From 06d5a0670087de4c8bbf02c2441c75f5fbfb1adb Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Thu, 26 Feb 2026 16:15:54 -0800 Subject: [PATCH 1/5] =?UTF-8?q?Revert=20"Revert=20"Fix=20get=5Fnested=5Fre?= =?UTF-8?q?source=5Fptr=20to=20accept=20both=20str=20and=20bytes=20inpu?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2d85f3eddc83e8e626b0881134d9168d6d13635a. --- cuda_bindings/cuda/bindings/_internal/utils.pyx | 9 ++++++++- cuda_bindings/tests/test_nvjitlink.py | 7 +++++++ cuda_bindings/tests/test_nvvm.py | 8 ++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_internal/utils.pyx b/cuda_bindings/cuda/bindings/_internal/utils.pyx index a56ef35357..879a10e621 100644 --- a/cuda_bindings/cuda/bindings/_internal/utils.pyx +++ b/cuda_bindings/cuda/bindings/_internal/utils.pyx @@ -120,7 +120,14 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj, nested_ptr.reset(nested_vec, True) for i, obj_i in enumerate(obj): if ResT is char: - obj_i_bytes = ((obj_i)).encode() + obj_i_type = type(obj_i) + if obj_i_type is str: + obj_i_bytes = obj_i.encode("utf-8") + elif obj_i_type is bytes: + obj_i_bytes = obj_i + else: + raise TypeError( + f"Expected str or bytes, got {obj_i_type.__name__}") str_len = (len(obj_i_bytes)) + 1 # including null termination deref(nested_res_vec)[i].resize(str_len) obj_i_ptr = (obj_i_bytes) diff --git a/cuda_bindings/tests/test_nvjitlink.py b/cuda_bindings/tests/test_nvjitlink.py index 3bfeb8d35a..9aa39de1ac 100644 --- a/cuda_bindings/tests/test_nvjitlink.py +++ b/cuda_bindings/tests/test_nvjitlink.py @@ -99,6 +99,13 @@ def test_create_and_destroy(option): nvjitlink.destroy(handle) +@pytest.mark.parametrize("option", ARCHITECTURES) +def test_create_and_destroy_bytes_options(option): + handle = nvjitlink.create(1, [f"-arch={option}".encode()]) + assert handle != 0 + nvjitlink.destroy(handle) + + @pytest.mark.parametrize("option", ARCHITECTURES) def test_complete_empty(option): handle = nvjitlink.create(1, [f"-arch={option}"]) diff --git a/cuda_bindings/tests/test_nvvm.py b/cuda_bindings/tests/test_nvvm.py index 05fec9767d..51151333ab 100644 --- a/cuda_bindings/tests/test_nvvm.py +++ b/cuda_bindings/tests/test_nvvm.py @@ -115,7 +115,9 @@ def test_get_buffer_empty(get_size, get_buffer): assert buffer == b"\x00" -@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"]]) +@pytest.mark.parametrize( + "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"], [b"-opt=3", b"-g"], ["-opt=3", b"-g"]] +) def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: F401, F811 with nvvm_program() as prog: nvvm.add_module_to_program(prog, minimal_nvvmir, len(minimal_nvvmir), "FileNameHere.ll") @@ -135,7 +137,9 @@ def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: assert ".visible .entry kernel()" in buffer.decode() -@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"]]) +@pytest.mark.parametrize( + "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"], [b"-opt=3", b"-g"], ["-opt=3", b"-g"]] +) def test_verify_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: F401, F811 with nvvm_program() as prog: nvvm.add_module_to_program(prog, minimal_nvvmir, len(minimal_nvvmir), "FileNameHere.ll") From e897743d68db46e781e517574df2be5b6d956286 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Thu, 26 Feb 2026 17:35:57 -0800 Subject: [PATCH 2/5] compiler error fix --- cuda_bindings/cuda/bindings/_internal/utils.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cuda_bindings/cuda/bindings/_internal/utils.pyx b/cuda_bindings/cuda/bindings/_internal/utils.pyx index 879a10e621..ded22f7841 100644 --- a/cuda_bindings/cuda/bindings/_internal/utils.pyx +++ b/cuda_bindings/cuda/bindings/_internal/utils.pyx @@ -3,6 +3,7 @@ # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE cimport cpython +from cpython.bytes cimport PyBytes_AsString from libc.stdint cimport intptr_t from libcpp.utility cimport move from cython.operator cimport dereference as deref @@ -130,7 +131,7 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj, f"Expected str or bytes, got {obj_i_type.__name__}") str_len = (len(obj_i_bytes)) + 1 # including null termination deref(nested_res_vec)[i].resize(str_len) - obj_i_ptr = (obj_i_bytes) + obj_i_ptr = PyBytes_AsString(obj_i_bytes) # cast to size_t explicitly to work around a potentially Cython bug deref(nested_res_vec)[i].assign(obj_i_ptr, obj_i_ptr + str_len) else: From 9211f8d6fc15d7838d91b037338dca9232fe19e9 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Tue, 3 Mar 2026 08:04:49 -0800 Subject: [PATCH 3/5] feedback --- cuda_bindings/cuda/bindings/_internal/utils.pyx | 3 +-- cuda_bindings/tests/test_nvjitlink.py | 5 ++--- cuda_bindings/tests/test_nvvm.py | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_internal/utils.pyx b/cuda_bindings/cuda/bindings/_internal/utils.pyx index ded22f7841..f7392bc394 100644 --- a/cuda_bindings/cuda/bindings/_internal/utils.pyx +++ b/cuda_bindings/cuda/bindings/_internal/utils.pyx @@ -3,7 +3,6 @@ # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE cimport cpython -from cpython.bytes cimport PyBytes_AsString from libc.stdint cimport intptr_t from libcpp.utility cimport move from cython.operator cimport dereference as deref @@ -131,7 +130,7 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj, f"Expected str or bytes, got {obj_i_type.__name__}") str_len = (len(obj_i_bytes)) + 1 # including null termination deref(nested_res_vec)[i].resize(str_len) - obj_i_ptr = PyBytes_AsString(obj_i_bytes) + obj_i_ptr = obj_i_bytes # cast to size_t explicitly to work around a potentially Cython bug deref(nested_res_vec)[i].assign(obj_i_ptr, obj_i_ptr + str_len) else: diff --git a/cuda_bindings/tests/test_nvjitlink.py b/cuda_bindings/tests/test_nvjitlink.py index 9aa39de1ac..3e7411c6ec 100644 --- a/cuda_bindings/tests/test_nvjitlink.py +++ b/cuda_bindings/tests/test_nvjitlink.py @@ -99,9 +99,8 @@ def test_create_and_destroy(option): nvjitlink.destroy(handle) -@pytest.mark.parametrize("option", ARCHITECTURES) -def test_create_and_destroy_bytes_options(option): - handle = nvjitlink.create(1, [f"-arch={option}".encode()]) +def test_create_and_destroy_bytes_options(): + handle = nvjitlink.create(1, [b"-arch=sm_80"]) assert handle != 0 nvjitlink.destroy(handle) diff --git a/cuda_bindings/tests/test_nvvm.py b/cuda_bindings/tests/test_nvvm.py index 51151333ab..85c0012f06 100644 --- a/cuda_bindings/tests/test_nvvm.py +++ b/cuda_bindings/tests/test_nvvm.py @@ -116,7 +116,7 @@ def test_get_buffer_empty(get_size, get_buffer): @pytest.mark.parametrize( - "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"], [b"-opt=3", b"-g"], ["-opt=3", b"-g"]] + "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"]] ) def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: F401, F811 with nvvm_program() as prog: @@ -137,9 +137,7 @@ def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: assert ".visible .entry kernel()" in buffer.decode() -@pytest.mark.parametrize( - "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"], [b"-opt=3", b"-g"], ["-opt=3", b"-g"]] -) +@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"]]) def test_verify_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: F401, F811 with nvvm_program() as prog: nvvm.add_module_to_program(prog, minimal_nvvmir, len(minimal_nvvmir), "FileNameHere.ll") From a491c78486362933db37017178b963370a7ff596 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Tue, 3 Mar 2026 08:05:57 -0800 Subject: [PATCH 4/5] adding back parens --- cuda_bindings/cuda/bindings/_internal/utils.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_bindings/cuda/bindings/_internal/utils.pyx b/cuda_bindings/cuda/bindings/_internal/utils.pyx index f7392bc394..879a10e621 100644 --- a/cuda_bindings/cuda/bindings/_internal/utils.pyx +++ b/cuda_bindings/cuda/bindings/_internal/utils.pyx @@ -130,7 +130,7 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj, f"Expected str or bytes, got {obj_i_type.__name__}") str_len = (len(obj_i_bytes)) + 1 # including null termination deref(nested_res_vec)[i].resize(str_len) - obj_i_ptr = obj_i_bytes + obj_i_ptr = (obj_i_bytes) # cast to size_t explicitly to work around a potentially Cython bug deref(nested_res_vec)[i].assign(obj_i_ptr, obj_i_ptr + str_len) else: From 8551e5b7fd541b3a74d66f701b7763ab3ed83004 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Tue, 3 Mar 2026 08:09:53 -0800 Subject: [PATCH 5/5] format --- cuda_bindings/tests/test_nvvm.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cuda_bindings/tests/test_nvvm.py b/cuda_bindings/tests/test_nvvm.py index 85c0012f06..f79428a230 100644 --- a/cuda_bindings/tests/test_nvvm.py +++ b/cuda_bindings/tests/test_nvvm.py @@ -115,9 +115,7 @@ def test_get_buffer_empty(get_size, get_buffer): assert buffer == b"\x00" -@pytest.mark.parametrize( - "options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"]] -) +@pytest.mark.parametrize("options", [[], ["-opt=0"], ["-opt=3", "-g"], [b"-opt=0"]]) def test_compile_program_with_minimal_nvvm_ir(minimal_nvvmir, options): # noqa: F401, F811 with nvvm_program() as prog: nvvm.add_module_to_program(prog, minimal_nvvmir, len(minimal_nvvmir), "FileNameHere.ll")