Skip to content

Commit

Permalink
NVCC windows CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Oct 3, 2024
1 parent 08c7b6a commit c4a6f15
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
46 changes: 43 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ jobs:
cd build;
python -m pytest
nvcc:
nvcc-ubuntu:
runs-on: ubuntu-latest
container: nvidia/cuda:12.6.1-devel-ubuntu24.04
name: "Python 3 / NVCC (CUDA 12.2)"
container: nvidia/cuda:12.5.1-devel-ubuntu24.04
name: "Python 3 / NVCC (CUDA 12.6.1) / ubuntu-latest"

steps:
- name: Install dependencies
Expand All @@ -90,6 +90,46 @@ jobs:
cd build;
python3 -m pytest
nvcc-windows:
runs-on: windows-latest
name: "Python 3.12.7 / NVCC (CUDA 12.5.0) / windows-latest"

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

- uses: Jimver/cuda-toolkit@v0.2.17
id: cuda-toolkit
with:
cuda: '12.5.0'

- name: Setup Python 3.12.5
uses: actions/setup-python@v5
with:
python-version: 3.12.5
cache: 'pip'

- name: Install PyTest
run: |
python -m pip install pytest pytest-github-actions-annotate-failures typing_extensions
- name: Install NumPy
run: |
python -m pip install numpy scipy
- name: Configure
run: >
cmake -S . -B build -DNB_TEST_CUDA=ON
- name: Build C++
run: cmake --build build -j 2 --config Release

- name: Run tests
run: >
cd build;
python3 -m pytest
old-compilers:
strategy:
fail-fast: false
Expand Down
14 changes: 0 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,6 @@ else()
enable_language(CXX)
endif()

# ---------------------------------------------------------------------------
# Compile with a few more compiler warnings turned on
# ---------------------------------------------------------------------------

if (MSVC)
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
add_compile_options(/W4)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(-Wall -Wextra -Wno-unused-local-typedefs)
endif()

# ---------------------------------------------------------------------------
# Find the Python interpreter and development libraries
# ---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions cmake/nanobind-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ function (nanobind_build_library TARGET_NAME)

target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)
nanobind_set_visibility(${TARGET_NAME})

if (MSVC)
# warning #1388-D: base class dllexport/dllimport specification differs from that of the derived class
target_compile_options(${TARGET_NAME} PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe --diag_suppress=1388>)
endif()
endfunction()

# ---------------------------------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions include/nanobind/nb_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),
constexpr size_t
kwonly_pos_1 = index_1_v<std::is_same_v<kw_only, Extra>...>,
kwonly_pos_n = index_n_v<std::is_same_v<kw_only, Extra>...>;

// Arguments after nb::args are implicitly keyword-only even if there is no
// nb::kw_only annotation
constexpr bool explicit_kw_only = kwonly_pos_1 != sizeof...(Extra);
Expand Down Expand Up @@ -147,6 +148,8 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),
std::make_index_sequence<sizeof...(Extra)>())
: nargs;

(void) kwonly_pos_n;

if constexpr (explicit_kw_only) {
static_assert(kwonly_pos_1 == kwonly_pos_n,
"Repeated use of nb::kw_only annotation!");
Expand Down Expand Up @@ -253,15 +256,15 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),

PyObject *result;
if constexpr (std::is_void_v<Return>) {
#if defined(_WIN32) // temporary workaround for an internal compiler error in MSVC
#if defined(_WIN32) && !defined(__CUDACC__) // temporary workaround for an internal compiler error in MSVC
cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...);
#else
cap->func(in.template get<Is>().operator cast_t<Args>()...);
#endif
result = Py_None;
Py_INCREF(result);
} else {
#if defined(_WIN32) // temporary workaround for an internal compiler error in MSVC
#if defined(_WIN32) && !defined(__CUDACC__) // temporary workaround for an internal compiler error in MSVC
result = cast_out::from_cpp(
cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...),
policy, cleanup).ptr();
Expand Down Expand Up @@ -300,9 +303,10 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),

// Fill remaining fields of 'f'
size_t arg_index = 0;
(void) arg_index;
(func_extra_apply(f, extra, arg_index), ...);

(void) arg_index;

return nb_func_new((const void *) &f);
}

Expand Down
3 changes: 2 additions & 1 deletion include/nanobind/stl/bind_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class_<Map> bind_map(handle scope, const char *name, Args &&...args) {
using Key = typename Map::key_type;
using Value = typename Map::mapped_type;

using ValueRef = typename detail::iterator_value_access<typename Map::iterator>::result_type;
using ValueRef = typename detail::iterator_value_access<
typename Map::iterator>::result_type;

static_assert(
!detail::is_base_caster_v<detail::make_caster<Value>> ||
Expand Down
13 changes: 10 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ if (NB_TEST_SHARED_BUILD)
set(NB_EXTRA_ARGS ${NB_EXTRA_ARGS} NB_SHARED)
endif()

# Enable extra warning flags
# ---------------------------------------------------------------------------
# Compile with a few more compiler warnings turned on
# ---------------------------------------------------------------------------

if (MSVC)
add_compile_options(/W4)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
elseif (NOT NB_TEST_CUDA)
add_compile_options(/W4)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(-Wall -Wextra -Wno-unused-local-typedefs)
endif()

Expand Down
4 changes: 4 additions & 0 deletions tests/test_stl_bind_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ NB_MODULE(test_stl_bind_map_ext, m) {

nb::class_<E_nc>(m, "ENC").def(nb::init<int>()).def_rw("value", &E_nc::value);

// On Windows, NVCC has difficulties with the following code. My guess is that
// decltype() in the iterator_value_access macro used in bind_map.h loses a reference.
#if defined(_WIN32) && !defined(__CUDACC__)
// By default, the bindings produce a __getitem__ that makes a copy, which
// won't take this non-copyable type: (uncomment to verify build error)
//nb::bind_map<std::map<int, E_nc>>(m, "MapENC");
Expand Down Expand Up @@ -87,4 +90,5 @@ NB_MODULE(test_stl_bind_map_ext, m) {
nb::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>,
nb::rv_policy::reference_internal>(m, "UmapUmapENC");
m.def("get_numnc", &times_hundred<std::unordered_map<int, std::unordered_map<int, E_nc>>>);
#endif
}
3 changes: 3 additions & 0 deletions tests/test_stl_bind_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def test_map_string_double_const():


def test_maps_with_noncopyable_values():
if not hasattr(t, 'get_mnc'):
return

# std::map
mnc = t.get_mnc(5)
for i in range(1, 6):
Expand Down

0 comments on commit c4a6f15

Please sign in to comment.