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 committed Jul 11, 2021
1 parent 3c4630a commit 49114b2
Show file tree
Hide file tree
Showing 4 changed files with 1,870 additions and 25 deletions.
73 changes: 54 additions & 19 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.18)

enable_language(CXX)

add_executable(test_suite "test_suite.cpp")

set_target_properties(
test_suite
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

option(BUILD_CUDA_TESTS "Include tests for use of the printf library with CUDA host-side and device-side code" OFF)
option(TEST_BROKEN_FORMATS "Include tests using non-standard-compliant format strings?" ON)
# ... don't worry, we'll suppress the compiler warnings for those.
if (TEST_BROKEN_FORMATS)
target_compile_definitions(test_suite PRIVATE TEST_WITH_NON_STANDARD_FORMAT_STRINGS)

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()

target_link_libraries(test_suite PRIVATE mpaland-printf)
foreach(tgt ${cuda_tests})
add_executable(${tgt} "${tgt}.cu")
set_target_properties(
${tgt}
PROPERTIES
CUDA_STANDARD 11
CUDA_STANDARD_REQUIRED YES
CUDA_EXTENSIONS NO
)
endforeach()

set(tests test_suite ${cuda_tests})

add_executable(test_suite "test_suite.cpp")

foreach(tgt ${tests})
set_target_properties(
${tgt}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
if (TEST_BROKEN_FORMATS)
# ... don't worry, we'll suppress the compiler warnings for those.
target_compile_definitions(${tgt} PRIVATE TEST_WITH_NON_STANDARD_FORMAT_STRINGS)
endif()

target_link_libraries(test_suite PRIVATE mpaland-printf)
add_test(
NAME ${PROJECT_NAME}.${tgt}
COMMAND ${tgt} # ${TEST_RUNNER_PARAMS}
)
endforeach()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(test_suite PRIVATE /W4)
Expand Down Expand Up @@ -53,9 +92,5 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
endif()
endif()

add_test(
NAME ${PROJECT_NAME}.test_suite
COMMAND test_suite # ${TEST_RUNNER_PARAMS}
)


Loading

0 comments on commit 49114b2

Please sign in to comment.