-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: support nvcc and test #2461
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
Changes from all commits
58c532f
11088dd
37ace8b
da1d2dc
424ea1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1483,7 +1483,14 @@ struct vectorize_arg { | |
|
||
template <typename Func, typename Return, typename... Args> | ||
struct vectorize_helper { | ||
|
||
// NVCC for some reason breaks if NVectorized is private | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly breaks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It claims NVectorize is private in this context and quits.
|
||
#ifdef __CUDACC__ | ||
public: | ||
#else | ||
private: | ||
#endif | ||
|
||
static constexpr size_t N = sizeof...(Args); | ||
static constexpr size_t NVectorized = constexpr_sum(vectorize_arg<Args>::vectorize...); | ||
static_assert(NVectorized >= 1, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools") | |
|
||
option(PYBIND11_WERROR "Report all warnings as errors" OFF) | ||
option(DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF) | ||
option(PYBIND11_CUDA_TESTS "Enable building CUDA tests (requires CMake 3.12+)" OFF) | ||
YannickJadoul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set(PYBIND11_TEST_OVERRIDE | ||
"" | ||
CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests") | ||
|
@@ -49,6 +50,14 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | |
"RelWithDebInfo") | ||
endif() | ||
|
||
if(PYBIND11_CUDA_TESTS) | ||
enable_language(CUDA) | ||
if(DEFINED CMAKE_CXX_STANDARD) | ||
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) | ||
endif() | ||
set(CMAKE_CUDA_STANDARD_REQUIRED ON) | ||
endif() | ||
|
||
# Full set of test files (you can override these; see below) | ||
set(PYBIND11_TEST_FILES | ||
test_async.cpp | ||
|
@@ -104,6 +113,16 @@ if((PYBIND11_TEST_FILES_ASYNC_I GREATER -1) AND (PYTHON_VERSION VERSION_LESS 3.5 | |
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_ASYNC_I}) | ||
endif() | ||
|
||
# Skip tests for CUDA check: | ||
# /pybind11/tests/test_constants_and_functions.cpp(125): | ||
# error: incompatible exception specifications | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "incompatible exception specification" mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's printed by NVCC when running. It doesn't like either |
||
list(FIND PYBIND11_TEST_FILES test_constants_and_functions.cpp PYBIND11_TEST_FILES_CAF_I) | ||
if((PYBIND11_TEST_FILES_CAF_I GREATER -1) AND PYBIND11_CUDA_TESTS) | ||
message( | ||
STATUS "Skipping test_constants_and_functions due to incompatible exception specifications") | ||
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_CAF_I}) | ||
endif() | ||
|
||
string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}") | ||
|
||
# Contains the set of test files that require pybind11_cross_module_tests to be | ||
|
@@ -195,14 +214,16 @@ endif() | |
function(pybind11_enable_warnings target_name) | ||
if(MSVC) | ||
target_compile_options(${target_name} PRIVATE /W4) | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)") | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT PYBIND11_CUDA_TESTS) | ||
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual | ||
-Wdeprecated) | ||
endif() | ||
|
||
if(PYBIND11_WERROR) | ||
if(MSVC) | ||
target_compile_options(${target_name} PRIVATE /WX) | ||
elseif(PYBIND11_CUDA_TESTS) | ||
target_compile_options(${target_name} PRIVATE "SHELL:-Werror all-warnings") | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)") | ||
target_compile_options(${target_name} PRIVATE -Werror) | ||
endif() | ||
|
@@ -239,12 +260,22 @@ foreach(t ${PYBIND11_CROSS_MODULE_GIL_TESTS}) | |
endif() | ||
endforeach() | ||
|
||
# Support CUDA testing by forcing the target file to compile with NVCC | ||
if(PYBIND11_CUDA_TESTS) | ||
set_property(SOURCE ${PYBIND11_TEST_FILES} PROPERTY LANGUAGE CUDA) | ||
endif() | ||
|
||
foreach(target ${test_targets}) | ||
set(test_files ${PYBIND11_TEST_FILES}) | ||
if(NOT "${target}" STREQUAL "pybind11_tests") | ||
set(test_files "") | ||
endif() | ||
|
||
# Support CUDA testing by forcing the target file to compile with NVCC | ||
if(PYBIND11_CUDA_TESTS) | ||
set_property(SOURCE ${target}.cpp PROPERTY LANGUAGE CUDA) | ||
endif() | ||
|
||
# Create the binding library | ||
pybind11_add_module(${target} THIN_LTO ${target}.cpp ${test_files} ${PYBIND11_HEADERS}) | ||
pybind11_enable_warnings(${target}) | ||
|
@@ -354,8 +385,10 @@ add_custom_command( | |
$<TARGET_FILE:pybind11_tests> | ||
${CMAKE_CURRENT_BINARY_DIR}/sosize-$<TARGET_FILE_NAME:pybind11_tests>.txt) | ||
|
||
# Test embedding the interpreter. Provides the `cpptest` target. | ||
add_subdirectory(test_embed) | ||
if(NOT PYBIND11_CUDA_TESTS) | ||
# Test embedding the interpreter. Provides the `cpptest` target. | ||
add_subdirectory(test_embed) | ||
|
||
# Test CMake build using functions and targets from subdirectory or installed location | ||
add_subdirectory(test_cmake_build) | ||
# Test CMake build using functions and targets from subdirectory or installed location | ||
add_subdirectory(test_cmake_build) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of this change, isn't there some way to
#pragma be quiet
NVCC?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's poorly documented, but yes, I think more recent NVCC versions support suppression if you can find the right code. But this will actually generate simpler/faster runtime code with 1-2 fewer checks, if this happens fairly often. We can move the sizeof check to compile time, too, I believe.
I also think the logic may be flawed; it might be good to rework with new logic. Also I'm surprised it's showing up with some very odd types; things like pointers were
static_cast
to an integer is not allowed (which is why it's using C-style casts); I guess this is used to covert pointer addresses to Python ints?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the new version out! Simpler logic (the tests here are pretty comprehensive, don't ask me how I know that 😊), with no more pointless comparisons.