Skip to content

Commit

Permalink
Fixes #13, regards #12:
Browse files Browse the repository at this point in the history
* Updated the compiler directives for suppressing relevant warnings to also properly work with NVCC.
* Test suite "replicated" for CUDA host-side compilation (by including the `.cpp` file from the `.cu` file)
* Test suite adapted for CUDA device-side testing - using some invocation wrappering machinery. It's a bit crude but it does the job.
* `CMakeLists.txt` for the tests reworked to support CUDA targets, architecture auto-detection, etc.

Caveat: At the moment, CUDA testing is only performed using single-block, single-thread grids.
  • Loading branch information
Eyal Rozenberg authored and eyalroz committed Oct 20, 2021
1 parent c785fd5 commit 6e84ee9
Show file tree
Hide file tree
Showing 4 changed files with 1,270 additions and 4 deletions.
43 changes: 42 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.18)

enable_language(CXX)

option(BUILD_CUDA_TESTS "Include tests for use of the printf library with CUDA host-side and device-side code" OFF)

set(test_targets test_suite autotest)

option(TEST_NONSTD_FORMATS "Include tests using non-standard-compliant format strings?" ON)
# ... don't worry, we'll suppress the compiler warnings for those.

set(cuda_tests)
if(BUILD_CUDA_TESTS)
enable_language(CUDA)
list(APPEND CMAKE_CUDA_FLAGS "--extended-lambda --expt-relaxed-constexpr -Xcudafe --display_error_number")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
cmake_policy(SET CMP0104 OLD)
endif()
include(FindCUDA/select_compute_arch)
list(APPEND cuda_tests cuda_test_suite_host cuda_test_suite_device)
if((NOT DEFINED CUDA_ARCH_FLAGS) OR ("${CUDA_ARCH_FLAGS}" STREQUAL ""))
cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS_1 Auto)
set(CUDA_ARCH_FLAGS ${CUDA_ARCH_FLAGS} CACHE STRING "CUDA -gencode parameters")
string(REPLACE ";" " " CUDA_ARCH_FLAGS_STR "${CUDA_ARCH_FLAGS}")
else()
set(CUDA_ARCH_FLAGS_STR "${CUDA_ARCH_FLAGS}")
endif()
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH_FLAGS_STR}")
endif()

foreach(tgt ${cuda_tests})
string(REPLACE "cuda_" "cuda/" source_file_prefix ${tgt})
add_executable(${tgt} "${source_file_prefix}.cu")
set_target_properties(
${tgt}
PROPERTIES
CUDA_STANDARD 11
CUDA_STANDARD_REQUIRED YES
CUDA_EXTENSIONS NO
)
endforeach()

if(BUILD_CUDA_TESTS)
target_link_libraries(cuda_test_suite_device cuda_printf)
target_include_directories(cuda_test_suite_device PRIVATE "$<BUILD_INTERFACE:${GENERATED_INCLUDE_DIR}>")
set_target_properties(cuda_test_suite_device PROPERTIES CUDA_SEPARABLE_COMPILATION YES)
endif()

set(tests test_suite ${cuda_tests})

foreach(tgt ${test_targets})
add_executable(${tgt} "${tgt}.cpp")
set_target_properties(
Expand Down
Loading

0 comments on commit 6e84ee9

Please sign in to comment.