Skip to content

Commit 9e33c7d

Browse files
authored
Add function to get C compiler used to build cuda.bindings (#1591)
* Add function to get C compiler * Fix Windows build
1 parent ea45bbf commit 9e33c7d

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

cuda_bindings/cuda/bindings/_internal/utils.pyx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44

@@ -8,6 +8,28 @@ from libcpp.utility cimport move
88
from cython.operator cimport dereference as deref
99

1010

11+
cdef extern from *:
12+
"""
13+
#if defined(__clang__)
14+
#define _COMPILER_VERSION ("Clang " __clang_version__)
15+
#elif defined(__GNUC__) || defined(__GNUG__)
16+
#define _COMPILER_VERSION ("GCC " __VERSION__)
17+
#elif defined(_MSC_VER)
18+
#define _COMPILER_VERSION ("MSVC " Py_STRINGIFY(_MSC_VER))
19+
#else
20+
#define _COMPILER_VERSION ("Unknown Compiler")
21+
#endif
22+
"""
23+
cdef char *_COMPILER_VERSION
24+
25+
26+
cpdef str get_c_compiler():
27+
"""
28+
Returns a string describing the C compiler used to build cuda.bindings
29+
"""
30+
return _COMPILER_VERSION.decode()
31+
32+
1133
cdef bint is_nested_sequence(data):
1234
if not cpython.PySequence_Check(data):
1335
return False

cuda_bindings/tests/test_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
import importlib
@@ -9,6 +9,7 @@
99

1010
import pytest
1111
from cuda.bindings import driver, runtime
12+
from cuda.bindings._internal.utils import get_c_compiler
1213
from cuda.bindings.utils import get_cuda_native_handle, get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver
1314

1415
have_cufile = importlib.util.find_spec("cuda.bindings.cufile") is not None
@@ -110,3 +111,9 @@ def test_cyclical_imports(module):
110111
subprocess.check_call( # noqa: S603
111112
[sys.executable, Path(__file__).parent / "utils" / "check_cyclical_import.py", f"cuda.bindings.{module}"],
112113
)
114+
115+
116+
def test_get_c_compiler():
117+
c_compiler = get_c_compiler()
118+
prefix = ("GCC", "Clang", "MSVC", "Unknown")
119+
assert sum(c_compiler.startswith(p) for p in prefix) == 1

0 commit comments

Comments
 (0)