Skip to content

Commit

Permalink
make test target_name aligned with binary name, split isai due to nvh…
Browse files Browse the repository at this point in the history
…pc limitation
  • Loading branch information
yhmtsai committed Dec 3, 2024
1 parent 0a1dde6 commit 306d06a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ option(GINKGO_TEST_NONDEFAULT_STREAM "Uses non-default streams in CUDA and HIP t
option(GINKGO_MIXED_PRECISION "Instantiate true mixed-precision kernels (otherwise they will be conversion-based using implicit temporary storage)" OFF)
option(GINKGO_ENABLE_HALF "Enable the use of half precision" ON)
# We do not support MSVC. SYCL will come later
# NVHPC 23.3 faces "termminated by signal 11" in reference/test/isal_kernel and core/config/preconditioner, so we don't support this version for half unfortunately.
if(MSVC OR GINKGO_BUILD_SYCL OR (CMAKE_CXX_COMPILER_ID MATCHES "PGI|NVHPC" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 23.3.0))
message(STATUS "HALF is not supported in MSVC, NVHPC 23.3, and later support in SYCL")
if(MSVC OR GINKGO_BUILD_SYCL)
message(STATUS "HALF is not supported in MSVC, and later support in SYCL")
set(GINKGO_ENABLE_HALF OFF CACHE BOOL "Enable the use of half precision" FORCE)
endif()
option(GINKGO_SKIP_DEPENDENCY_UPDATE
Expand Down
23 changes: 14 additions & 9 deletions cmake/create_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ set(gko_test_option_args "NO_RESOURCES;NO_GTEST_MAIN")

## Replaces / by _ to create valid target names from relative paths
function(ginkgo_build_test_name test_name target_name)
cmake_parse_arguments(PARSE_ARGV 2 build_test_name "" "${gko_test_single_args}" "")
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
set(test_binary_name ${test_name})
if (build_test_name_EXECUTABLE_NAME)
set(test_binary_name ${build_test_name_EXECUTABLE_NAME})
endif()
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_binary_name}")
set(${target_name} ${TEST_TARGET_NAME} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -127,7 +132,7 @@ endfunction()

## Normal test
function(ginkgo_create_test test_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
add_executable(${test_target_name} ${test_name}.cpp)
target_link_libraries(${test_target_name})
ginkgo_set_test_target_properties(${test_target_name} "_cpu" ${ARGN})
Expand All @@ -136,7 +141,7 @@ endfunction(ginkgo_create_test)

## Test compiled with dpcpp
function(ginkgo_create_dpcpp_test test_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
add_executable(${test_target_name} ${test_name}.dp.cpp)
target_compile_options(${test_target_name} PRIVATE ${GINKGO_DPCPP_FLAGS})
gko_add_sycl_to_target(TARGET ${test_target_name} SOURCES ${test_name}.dp.cpp)
Expand All @@ -151,7 +156,7 @@ endfunction(ginkgo_create_dpcpp_test)

## Test compiled with CUDA
function(ginkgo_create_cuda_test test_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
ginkgo_create_cuda_test_internal(${test_name} ${test_name}.cu ${test_target_name} ${ARGN})
endfunction(ginkgo_create_cuda_test)

Expand All @@ -177,7 +182,7 @@ endfunction(ginkgo_create_cuda_test_internal)

## Test compiled with HIP
function(ginkgo_create_hip_test test_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
ginkgo_create_hip_test_internal(${test_name} ${test_name}.hip.cpp ${test_target_name} ${ARGN})
endfunction(ginkgo_create_hip_test)

Expand All @@ -196,12 +201,12 @@ endfunction(ginkgo_create_hip_test_internal)

## Test compiled with OpenMP
function(ginkgo_create_omp_test test_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
ginkgo_create_omp_test_internal(${test_name} ${test_name}.cpp ${test_target_name} "" ${ARGN})
endfunction()

function(ginkgo_create_omp_test_internal test_name filename test_target_name)
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
add_executable(${test_target_name} ${test_name}.cpp)
target_compile_definitions(${test_target_name} PRIVATE GKO_COMPILING_OMP GKO_DEVICE_NAMESPACE=omp)
target_link_libraries(${test_target_name} PRIVATE OpenMP::OpenMP_CXX)
Expand Down Expand Up @@ -241,7 +246,7 @@ function(ginkgo_create_common_test_internal test_name exec_type exec)
else ()
set(test_resource_type sycl)
endif ()
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
string(TOUPPER ${exec} exec_upper)

# set up actual test
Expand All @@ -267,7 +272,7 @@ endfunction(ginkgo_create_common_test_internal)
## Common test compiled with the device compiler, one target for each enabled backend
function(ginkgo_create_common_device_test test_name)
cmake_parse_arguments(PARSE_ARGV 1 common_device_test "" "${gko_test_single_args}" "${gko_test_multi_args}")
ginkgo_build_test_name(${test_name} test_target_name)
ginkgo_build_test_name(${test_name} test_target_name ${ARGN})
if(GINKGO_BUILD_SYCL)
ginkgo_create_common_test_internal(${test_name} DpcppExecutor dpcpp ${ARGN})
target_compile_options(${test_target_name}_dpcpp PRIVATE ${GINKGO_DPCPP_FLAGS})
Expand Down
6 changes: 6 additions & 0 deletions reference/test/preconditioner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ ginkgo_create_test(gauss_seidel)
ginkgo_create_test(ilu)
ginkgo_create_test(ic)
ginkgo_create_test(isai_kernels)
# need to split the isai_kernels due to NVHPC compilation limitation
if(CMAKE_CXX_COMPILER_ID MATCHES "PGI|NVHPC" AND GINKGO_ENABLE_HALF)
ginkgo_create_test(isai_kernels EXECUTABLE_NAME isai_kernels_half)
ginkgo_build_test_name(isai_kernels isai_half_target EXECUTABLE_NAME isai_kernels_half)
target_compile_definitions(${isai_half_target} PRIVATE "NVHPC_HALF")
endif()
ginkgo_create_test(jacobi)
ginkgo_create_test(jacobi_kernels)
ginkgo_create_test(sor_kernels)
20 changes: 20 additions & 0 deletions reference/test/preconditioner/isai_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,30 @@ class Isai : public ::testing::Test {
std::shared_ptr<Csr> spd_sparse_inv;
};

#ifdef __NVCOMPILER


// Due to NVHPC compilation limitation, we need to split it to two files.
#ifdef NVHPC_HALF
using HalfIndexTypes = gko::test::cartesian_type_product_t<
::testing::Types<gko::half, std::complex<gko::half>>,
gko::test::IndexTypes>;
TYPED_TEST_SUITE(Isai, HalfIndexTypes, PairTypenameNameGenerator);
#else
TYPED_TEST_SUITE(Isai, gko::test::ValueIndexTypes, PairTypenameNameGenerator);
#endif


#else


TYPED_TEST_SUITE(Isai, gko::test::ValueIndexTypesWithHalf,
PairTypenameNameGenerator);


#endif


TYPED_TEST(Isai, KernelGenerateA)
{
using Csr = typename TestFixture::Csr;
Expand Down

0 comments on commit 306d06a

Please sign in to comment.