Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the NVCC compiler #710

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,28 @@ jobs:
run: >
cd build;
python -m pytest

nvcc:
runs-on: ubuntu-latest
container: nvidia/cuda:12.2.0-devel-ubuntu22.04
name: "Python 3 / NVCC (CUDA 12.2)"

steps:
- name: Install dependencies
run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-pip libeigen3-dev && python3 -m pip install typing_extensions numpy

- uses: actions/checkout@v4
with:
submodules: true

- name: Configure
run: >
cmake -S . -B build -DNB_TEST_CUDA=ON

- name: Build C++
run: cmake --build build -j 2

- name: Run tests
run: >
cd build;
python3 -m pytest
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(NB_USE_SUBMODULE_DEPS "Use the nanobind dependencies shipped as a git s
option(NB_TEST "Compile nanobind tests?" ${NB_MASTER_PROJECT})
option(NB_TEST_STABLE_ABI "Test the stable ABI interface?" OFF)
option(NB_TEST_SHARED_BUILD "Build a shared nanobind library for the test suite?" OFF)
option(NB_TEST_CUDA "Force the use of the CUDA/NVCC compiler for testing purposes" OFF)

if (NOT MSVC)
option(NB_TEST_SANITZE "Build tests with address and undefined behavior sanitizers?" OFF)
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ below inherit that of the preceding release.
Version 2.2.0 (TBA)
-------------------

- The NVIDIA CUDA compiler (``nvcc``) is now explicitly supported and included
in nanobind's CI test suite.

- nanobind has always used `PEP 590 vector calls
<https://www.python.org/dev/peps/pep-0590>`__ to efficiently dispatch calls
to function and method bindings, but it lacked the ability to do so for
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ nanobinds depends on
- **Python 3.8+** or **PyPy 7.3.10+** (the *3.8* and *3.9* PyPy flavors are
supported, though there are :ref:`some limitations <pypy_issues>`).
- **CMake 3.15+**.
- **A C++17 compiler**: Clang 7+, GCC 8+, and MSVC2019+ are officially
supported. Others (MinGW, Intel, NVIDIA, ..) may work as well but will not
receive support.
- **A C++17 compiler**: Clang 7+, GCC 8+, MSVC2019+, and the CUDA NVCC compiler
are officially supported. Others (MinGW, Cygwin, Intel, ..) may work as well
but will not receive support.

.. only:: not latex

Expand Down
2 changes: 1 addition & 1 deletion src/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def check_party(self, module: str) -> Literal[0, 1, 2]:
return 1

if spec:
if spec.origin and "site-packages" in spec.origin:
if spec.origin and ("site-packages" in spec.origin or "dist-packages" in spec.origin):
return 1
else:
return 0
Expand Down
48 changes: 33 additions & 15 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,45 @@ if (UNIX AND (CMAKE_SIZEOF_VOID_P EQUAL 4) AND (CMAKE_SYSTEM_PROCESSOR STREQUAL
add_compile_options(-mfpmath=sse -msse2)
endif()

# Enforce the use of the CUDA NVCC compiler if requested
if (NB_TEST_CUDA)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()

if (NB_TEST_SANITIZE)
add_compile_options(-fsanitize=address,undefined)
add_link_options(-fsanitize=address,undefined)
endif()

set(TEST_NAMES
functions
classes
holders
stl
stl_bind_map
stl_bind_vector
chrono
enum
eval
ndarray
exception
make_iterator
typing
issue
intrusive
)

foreach (NAME ${TEST_NAMES})
nanobind_add_module(test_${NAME}_ext test_${NAME}.cpp ${NB_EXTRA_ARGS})

if (NB_TEST_CUDA)
set_property(SOURCE test_${NAME}.cpp PROPERTY LANGUAGE CUDA)
endif()
endforeach()

nanobind_add_module(test_functions_ext test_functions.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_classes_ext test_classes.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_holders_ext test_holders.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_stl_ext test_stl.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_bind_map_ext test_stl_bind_map.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_bind_vector_ext test_stl_bind_vector.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_chrono_ext test_chrono.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_enum_ext test_enum.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_eval_ext test_eval.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_ndarray_ext test_ndarray.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_intrusive_ext test_intrusive.cpp test_intrusive_impl.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_exception_ext test_exception.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_make_iterator_ext test_make_iterator.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_typing_ext test_typing.cpp ${NB_EXTRA_ARGS})
nanobind_add_module(test_issue_ext test_issue.cpp ${NB_EXTRA_ARGS})
target_sources(test_intrusive_ext PRIVATE test_intrusive_impl.cpp)

foreach (NAME functions classes ndarray stl enum typing make_iterator)
if (NAME STREQUAL typing)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stl_bind_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ NestMap *times_hundred(int n) {
return m;
}

NB_MODULE(test_bind_map_ext, m) {
NB_MODULE(test_stl_bind_map_ext, m) {
// test_map_string_double
nb::bind_map<std::map<std::string, double>>(m, "MapStringDouble");
nb::bind_map<std::unordered_map<std::string, double>>(m, "UnorderedMapStringDouble");
Expand Down
10 changes: 5 additions & 5 deletions tests/test_stl_bind_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import platform

import test_bind_map_ext as t
import test_stl_bind_map_ext as t


def test_map_string_double(capfd):
Expand Down Expand Up @@ -35,12 +35,12 @@ def test_map_string_double(capfd):
assert len(mm2) == 1
mm2.clear()
assert len(mm2) == 0
assert repr(mm) == "test_bind_map_ext.MapStringDouble({'a': 1.0, 'b': 2.5})"
assert repr(mm) == "test_stl_bind_map_ext.MapStringDouble({'a': 1.0, 'b': 2.5})"

with pytest.raises(TypeError):
mm2.update({"a" : "b"})
captured = capfd.readouterr().err.strip()
ref = "nanobind: implicit conversion from type 'dict' to type 'test_bind_map_ext.MapStringDouble' failed!"
ref = "nanobind: implicit conversion from type 'dict' to type 'test_stl_bind_map_ext.MapStringDouble' failed!"

# Work around Pytest-related flakiness (https://github.com/pytest-dev/pytest/issues/10843)
if platform.system() == 'Windows':
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_map_string_double(capfd):

assert t.MapStringDouble.__init__.__doc__ == \
"""__init__(self) -> None
__init__(self, arg: test_bind_map_ext.MapStringDouble) -> None
__init__(self, arg: test_stl_bind_map_ext.MapStringDouble) -> None
__init__(self, arg: %s[str, float], /) -> None

Overloaded function.
Expand All @@ -111,7 +111,7 @@ def test_map_string_double(capfd):

Default constructor

2. ``__init__(self, arg: test_bind_map_ext.MapStringDouble) -> None``
2. ``__init__(self, arg: test_stl_bind_map_ext.MapStringDouble) -> None``

Copy constructor

Expand Down
2 changes: 1 addition & 1 deletion tests/test_stl_bind_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace nb = nanobind;

NB_MODULE(test_bind_vector_ext, m) {
NB_MODULE(test_stl_bind_vector_ext, m) {
nb::bind_vector<std::vector<unsigned int>>(m, "VectorInt");
nb::bind_vector<std::vector<bool>>(m, "VectorBool");

Expand Down
6 changes: 3 additions & 3 deletions tests/test_stl_bind_vector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import platform

import test_bind_vector_ext as t
import test_stl_bind_vector_ext as t

def test01_vector_int(capfd):
v_int = t.VectorInt([0, 0])
Expand All @@ -11,7 +11,7 @@ def test01_vector_int(capfd):
# test construction from a generator
v_int1 = t.VectorInt(x for x in range(5))
assert t.VectorInt(v_int1) == t.VectorInt([0, 1, 2, 3, 4])
assert repr(v_int1) == "test_bind_vector_ext.VectorInt([0, 1, 2, 3, 4])"
assert repr(v_int1) == "test_stl_bind_vector_ext.VectorInt([0, 1, 2, 3, 4])"

v_int2 = t.VectorInt([0, 0])
assert v_int == v_int2
Expand Down Expand Up @@ -47,7 +47,7 @@ def test01_vector_int(capfd):
v_int2.extend([8, "a"])

captured = capfd.readouterr().err.strip()
ref = "nanobind: implicit conversion from type 'list' to type 'test_bind_vector_ext.VectorInt' failed!"
ref = "nanobind: implicit conversion from type 'list' to type 'test_stl_bind_vector_ext.VectorInt' failed!"

# Work around Pytest-related flakiness (https://github.com/pytest-dev/pytest/issues/10843)
if platform.system() == 'Windows':
Expand Down