Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cuda_bindings/build_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def _build_cuda_bindings(debug=False):
that metadata queries do not require a CUDA toolkit installation.
"""
from Cython.Build import cythonize
from Cython.Compiler import Options as _CythonOptions

global _extensions

Expand Down Expand Up @@ -224,6 +225,7 @@ def get_static_libraries(f):
)

# Cythonize
_CythonOptions.warning_errors = True
cython_directives = {"language_level": 3, "embedsignature": True, "binding": True, "freethreading_compatible": True}
if compile_for_coverage:
cython_directives["linetrace"] = True
Expand Down
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_lib/windll.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cdef extern from "windows.h" nogil:
ctypedef const char *LPCSTR
ctypedef int BOOL

cdef DWORD LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
const DWORD LOAD_LIBRARY_SEARCH_SYSTEM32

HMODULE _LoadLibraryExW "LoadLibraryExW"(
LPCWSTR lpLibFileName,
Expand Down
6 changes: 3 additions & 3 deletions cuda_bindings/cuda/bindings/cudla.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# This code was automatically generated across versions from 1.5.0 to 13.3.0. Do not modify it directly.

# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=e64a78a1b3e010d167373d7c9635ff4637dfd1a6a38ffafb671dcde4e12aaaad
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b3303a34762cec1db0d9ab7662fe4a4a0f5b80350810cc0b646a04c9c6bb19c3
from libc.stdint cimport intptr_t

from .cycudla cimport *
Expand Down Expand Up @@ -44,10 +44,10 @@ cpdef intptr_t mem_register(intptr_t dev_handle, intptr_t ptr, size_t size, uint
cpdef intptr_t module_load_from_memory(intptr_t dev_handle, p_module, size_t module_size, uint32_t flags) except *
cpdef module_unload(intptr_t h_module, uint32_t flags)
cpdef submit_task(intptr_t dev_handle, intptr_t ptr_to_tasks, uint32_t num_tasks, intptr_t stream, uint32_t flags)
cpdef object device_get_attribute(intptr_t dev_handle, int attrib) except *
cpdef object device_get_attribute(intptr_t dev_handle, int attrib)
cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr)
cpdef int get_last_error(intptr_t dev_handle) except? 0
cpdef destroy_device(intptr_t dev_handle)
cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout)

cpdef module_get_attributes(intptr_t h_module, int attr_type) except *
cpdef module_get_attributes(intptr_t h_module, int attr_type)
6 changes: 3 additions & 3 deletions cuda_bindings/cuda/bindings/cudla.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

# This code was automatically generated across versions from 1.5.0 to 13.3.0. Do not modify it directly.
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b793aebd0586162e23d26c82e2bd54c21675584e3c23d6e443f3a83c61a8674c
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=ee04e18498a1e4e597afcdead5590bfe22af25afb2d43cd85b19089bee10a721


# <<<< PREAMBLE CONTENT >>>>
Expand Down Expand Up @@ -1776,7 +1776,7 @@ cpdef submit_task(intptr_t dev_handle, intptr_t ptr_to_tasks, uint32_t num_tasks
check_status(__status__)


cpdef object device_get_attribute(intptr_t dev_handle, int attrib) except *:
cpdef object device_get_attribute(intptr_t dev_handle, int attrib):
cdef DevAttribute p_attribute_py = DevAttribute()
cdef cudlaDevAttribute *p_attribute = <cudlaDevAttribute *><intptr_t>(p_attribute_py._get_ptr())
with nogil:
Expand Down Expand Up @@ -1810,7 +1810,7 @@ cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout):
check_status(__status__)


cpdef module_get_attributes(intptr_t h_module, int attr_type) except *:
cpdef module_get_attributes(intptr_t h_module, int attr_type):
"""Query module attributes, interpreting the cudlaModuleAttribute union
based on the requested attribute type.

Expand Down
76 changes: 76 additions & 0 deletions cuda_bindings/tests/test_cython_warning_cleanliness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Regression guards for cuda.bindings Cython warning cleanliness (#2450)."""

from __future__ import annotations

import ast
import re
from pathlib import Path

import pytest

_BINDINGS_ROOT = Path(__file__).resolve().parents[1]
_CUDA_BINDINGS = _BINDINGS_ROOT / "cuda" / "bindings"

# cpdef returning a Python object must not carry an exception clause; Cython
# warns (and with warning_errors, fails) that the clause is ignored.
_CPDEF_OBJECT_EXCEPT_RE = re.compile(
r"^\s*cpdef\s+object\s+\w+\s*\([^)]*\)\s+except\b",
re.MULTILINE,
)
_MODULE_GET_ATTRIBUTES_EXCEPT_RE = re.compile(
r"^\s*cpdef\s+module_get_attributes\s*\([^)]*\)\s+except\b",
re.MULTILINE,
)


@pytest.mark.agent_authored(model="grok-4.5")
def test_build_hooks_enable_cython_warning_errors():
"""Source builds must treat Cython warnings as errors."""
source = (_BINDINGS_ROOT / "build_hooks.py").read_text(encoding="utf-8")
tree = ast.parse(source)
assigned = {
node.targets[0].attr
for node in ast.walk(tree)
if isinstance(node, ast.Assign)
and len(node.targets) == 1
and isinstance(node.targets[0], ast.Attribute)
and isinstance(node.value, ast.Constant)
and node.value.value is True
}
assert "warning_errors" in assigned, "cuda_bindings/build_hooks.py must set Cython Options.warning_errors = True"


@pytest.mark.agent_authored(model="grok-4.5")
def test_windll_pxd_declares_load_library_flag_as_const():
"""Assignment in a ``.pxd`` is not executed; declare the Win32 flag as const."""
text = (_CUDA_BINDINGS / "_lib" / "windll.pxd").read_text(encoding="utf-8")
assert "LOAD_LIBRARY_SEARCH_SYSTEM32" in text
assert re.search(
r"^\s*const\s+DWORD\s+LOAD_LIBRARY_SEARCH_SYSTEM32\s*$",
text,
re.MULTILINE,
), "LOAD_LIBRARY_SEARCH_SYSTEM32 must be declared as const DWORD (no assignment)"
assert (
re.search(
r"LOAD_LIBRARY_SEARCH_SYSTEM32\s*=",
text,
)
is None
)


@pytest.mark.agent_authored(model="grok-4.5")
@pytest.mark.parametrize("filename", ["cudla.pxd", "cudla.pyx"])
def test_cudla_cpdef_python_returns_have_no_except_clause(filename):
"""Regression for cybind emitting ``except *`` on Python-returning cpdefs."""
text = (_CUDA_BINDINGS / filename).read_text(encoding="utf-8")
assert _CPDEF_OBJECT_EXCEPT_RE.search(text) is None, (
f"{filename} has cpdef object ... except ..., which Cython warns about"
)
# Declared without an explicit object return type, but returns Python values.
assert _MODULE_GET_ATTRIBUTES_EXCEPT_RE.search(text) is None, (
f"{filename}: cpdef module_get_attributes(...) except ... is invalid for Python returns"
)
Loading