Skip to content

Commit

Permalink
Merge Improve test install
Browse files Browse the repository at this point in the history
Provide multiple `test_install` improvements.

+ No more file duplication, everything uses one file.
+ Test most SpMV and solvers when building for accelerators (check against reference).
+ Keep multiple dedicated targets (`test_install_hip` and `test_install_cuda`) for simplicity of running tests in spack.
+ Install the test install into the directory `${CMAKE_INSTALL_PREFIX}/smoke_tests`.
+ Use proper RPATH information when installing the binaries such that they work without environment settings.

There is also some irrelevant Executor documentation fix.

Related PR: #721
  • Loading branch information
tcojean authored Apr 11, 2021
2 parents 9771e12 + dd7e36b commit 369362c
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 849 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ stages:
(( $(ctest -N | tail -1 | sed 's/Total Tests: //') != 0 )) || exit 1
- ctest -V
- ninja test_install
- pushd test_install
- ninja install
- popd
- |
if [ "${RUN_EXAMPLES}" == "ON" ]; then
export EX_ARG="reference"
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,15 @@ else()
set(GINKGO_TEST_INSTALL_HIP_COMMAND "${Ginkgo_BINARY_DIR}/test_install/test_install_hip")
endif()
endif()

file(MAKE_DIRECTORY ${Ginkgo_BINARY_DIR}/test_install)
add_custom_target(test_install
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -H${Ginkgo_SOURCE_DIR}/test_install
-B${Ginkgo_BINARY_DIR}/test_install
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_CONFIG_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
WORKING_DIRECTORY ${Ginkgo_BINARY_DIR}/test_install
# `--config cfg` is ignored by single-configuration generator.
# `$<CONFIG>` is always be the same as `CMAKE_BUILD_TYPE` in
# single-configuration generator.
Expand Down
6 changes: 3 additions & 3 deletions include/ginkgo/core/base/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ private: \
* int main() {
* // create executors
* auto omp = OmpExecutor::create();
* auto cuda = CudaExecutor::create(omp, 0);
* auto hip = HipExecutor::create(omp, 0);
* auto dpcpp = DpcppExecutor::create(omp, 0);
* auto cuda = CudaExecutor::create(0, omp);
* auto hip = HipExecutor::create(0, omp);
* auto dpcpp = DpcppExecutor::create(0, omp);
* auto ref = ReferenceExecutor::create();
*
* // create the operation
Expand Down
2 changes: 2 additions & 0 deletions test_exportbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if(MSVC)
endif()
endif()

# Here, we use test install without any data. We instantiate the
# interface only.
add_executable(test_exportbuild ../test_install/test_install.cpp)
target_compile_features(test_exportbuild PUBLIC cxx_std_14)
target_link_libraries(test_exportbuild PRIVATE Ginkgo::ginkgo)
46 changes: 42 additions & 4 deletions test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ find_package(Ginkgo REQUIRED
# Alternatively, use `cmake -DCMAKE_PREFIX_PATH=<ginkgo_install_dir>` to specify the install directory
)

# Copy the data to the build directory
configure_file(data/A.mtx data/A.mtx COPYONLY)
configure_file(data/b.mtx data/b.mtx COPYONLY)
configure_file(data/x0.mtx data/x0.mtx COPYONLY)

if(MSVC)
if(GINKGO_BUILD_SHARED_LIBS)
ginkgo_switch_to_windows_dynamic("CXX")
Expand All @@ -20,8 +25,13 @@ endif()
include(CheckLanguage)
check_language(CUDA)

set(HAS_REFERENCE 0)
if (GINKGO_BUILD_REFERENCE)
set(HAS_REFERENCE 1)
endif()
add_executable(test_install test_install.cpp)
target_compile_features(test_install PUBLIC cxx_std_14)
target_compile_definitions(test_install PRIVATE HAS_REFERENCE=${HAS_REFERENCE})
target_link_libraries(test_install PRIVATE Ginkgo::ginkgo)

if(GINKGO_BUILD_CUDA)
Expand All @@ -33,29 +43,57 @@ if(GINKGO_BUILD_CUDA)
ginkgo_switch_to_windows_static("CUDA")
endif()
endif()
add_executable(test_install_cuda test_install_cuda.cu)
configure_file(test_install.cpp test_install.cu COPYONLY)
add_executable(test_install_cuda ${CMAKE_CURRENT_BINARY_DIR}/test_install.cu)
target_compile_options(test_install_cuda
PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:${GINKGO_CUDA_ARCH_FLAGS}>")
target_compile_definitions(test_install_cuda PRIVATE HAS_CUDA=1)
target_compile_definitions(test_install_cuda PRIVATE HAS_REFERENCE=${HAS_REFERENCE})
target_link_libraries(test_install_cuda PRIVATE Ginkgo::ginkgo)
endif()

if(GINKGO_BUILD_HIP)
find_package(HIP REQUIRED)

set_source_files_properties(test_install.hip.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT TRUE)
set_source_files_properties(test_install.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT TRUE)
# The library was compiled with `-fPIC` when in shared library mode
if (GINKGO_BUILD_SHARED_LIBS)
set (GINKGO_PIC_OPTION "-fPIC")
set (GINKGO_CUDA_PIC_OPTION "-Xcompiler '-fPIC'")
endif()
hip_add_executable(test_install_hip test_install.hip.cpp
if (CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
set(TESTINSTALL_CUDA_ARCH_FLAGS "${GINKGO_CUDA_ARCH_FLAGS}")
endif()
hip_add_executable(test_install_hip test_install.cpp
HIPCC_OPTIONS "-std=c++14"
CLANG_OPTIONS "${GINKGO_PIC_OPTION}"
NVCC_OPTIONS "${GINKGO_CUDA_PIC_OPTION}")
NVCC_OPTIONS "${GINKGO_CUDA_PIC_OPTION}" "${TESTINSTALL_CUDA_ARCH_FLAGS}")

target_link_libraries(test_install_hip PRIVATE Ginkgo::ginkgo)
target_compile_definitions(test_install_hip PRIVATE HAS_HIP=1)
target_compile_definitions(test_install_hip PRIVATE HAS_REFERENCE=${HAS_REFERENCE})

# If we always link with CXX there is no RPATH issue
set_target_properties(test_install_hip PROPERTIES LINKER_LANGUAGE CXX)

# Instead of using CXX, it's possible to instead use
# target_link_libraries(test_install_hip PRIVATE ${GINKGO_INSTALL_RPATH_FOR_HIP})
endif()

# Installation step
set(TESTINSTALL_INSTALL_DIR "${GINKGO_INSTALL_PREFIX}/smoke_tests")
set(TESTINSTALL_INSTALL_DATADIR "${TESTINSTALL_INSTALL_DIR}/data")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)

set_target_properties(test_install PROPERTIES INSTALL_RPATH "${GINKGO_INSTALL_LIBRARY_DIR}")
install(TARGETS test_install RUNTIME DESTINATION ${TESTINSTALL_INSTALL_DIR})
if(GINKGO_BUILD_CUDA)
set_target_properties(test_install_cuda PROPERTIES INSTALL_RPATH "${GINKGO_INSTALL_LIBRARY_DIR}")
install(TARGETS test_install_cuda RUNTIME DESTINATION ${TESTINSTALL_INSTALL_DIR})
endif()
if(GINKGO_BUILD_HIP)
set_target_properties(test_install_hip PROPERTIES INSTALL_RPATH "${GINKGO_INSTALL_LIBRARY_DIR}")
install(TARGETS test_install_hip RUNTIME DESTINATION ${TESTINSTALL_INSTALL_DIR})
endif()
install(DIRECTORY "${TestInstall_BINARY_DIR}/data/"
DESTINATION "${TESTINSTALL_INSTALL_DATADIR}")
114 changes: 114 additions & 0 deletions test_install/data/A.mtx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
%%MatrixMarket matrix coordinate integer symmetric
%-------------------------------------------------------------------------------
% UF Sparse Matrix Collection, Tim Davis
% http://www.cise.ufl.edu/research/sparse/matrices/JGD_Trefethen/Trefethen_20b
% name: JGD_Trefethen/Trefethen_20b
% [Diagonal matrices with primes, Nick Trefethen, Oxford Univ.]
% id: 2203
% date: 2008
% author: N. Trefethen
% ed: J.-G. Dumas
% fields: name title A id date author ed kind notes
% kind: combinatorial problem
%-------------------------------------------------------------------------------
% notes:
% Diagonal matrices with primes, Nick Trefethen, Oxford Univ.
% From Jean-Guillaume Dumas' Sparse Integer Matrix Collection,
% http://ljk.imag.fr/membres/Jean-Guillaume.Dumas/simc.html
%
% Problem 7 of the Hundred-dollar, Hundred-digit Challenge Problems,
% SIAM News, vol 35, no. 1.
%
% 7. Let A be the 20,000 x 20,000 matrix whose entries are zero
% everywhere except for the primes 2, 3, 5, 7, . . . , 224737 along the
% main diagonal and the number 1 in all the positions A(i,j) with
% |i-j| = 1,2,4,8, . . . ,16384. What is the (1,1) entry of inv(A)?
%
% http://www.siam.org/news/news.php?id=388
%
% Filename in JGD collection: Trefethen/trefethen_20__19_minor.sms
%-------------------------------------------------------------------------------
19 19 83
1 1 3
2 1 1
3 1 1
5 1 1
9 1 1
17 1 1
2 2 5
3 2 1
4 2 1
6 2 1
10 2 1
18 2 1
3 3 7
4 3 1
5 3 1
7 3 1
11 3 1
19 3 1
4 4 11
5 4 1
6 4 1
8 4 1
12 4 1
5 5 13
6 5 1
7 5 1
9 5 1
13 5 1
6 6 17
7 6 1
8 6 1
10 6 1
14 6 1
7 7 19
8 7 1
9 7 1
11 7 1
15 7 1
8 8 23
9 8 1
10 8 1
12 8 1
16 8 1
9 9 29
10 9 1
11 9 1
13 9 1
17 9 1
10 10 31
11 10 1
12 10 1
14 10 1
18 10 1
11 11 37
12 11 1
13 11 1
15 11 1
19 11 1
12 12 41
13 12 1
14 12 1
16 12 1
13 13 43
14 13 1
15 13 1
17 13 1
14 14 47
15 14 1
16 14 1
18 14 1
15 15 53
16 15 1
17 15 1
19 15 1
16 16 59
17 16 1
18 16 1
17 17 61
18 17 1
19 17 1
18 18 67
19 18 1
19 19 71
21 changes: 21 additions & 0 deletions test_install/data/b.mtx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%%MatrixMarket matrix array real general
19 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
21 changes: 21 additions & 0 deletions test_install/data/x0.mtx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%%MatrixMarket matrix array real general
19 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Loading

0 comments on commit 369362c

Please sign in to comment.