-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add units tets for PIConGPU - build first test case to check particle shapes - call unit tests in the CI
- Loading branch information
1 parent
f19898f
commit a7587c5
Showing
10 changed files
with
486 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
################################################### | ||
# translate PIConGPU backend names into CMake Flags | ||
################################################### | ||
|
||
get_backend_flags() | ||
{ | ||
backend_cfg=(${1//:/ }) | ||
num_options="${#backend_cfg[@]}" | ||
if [ $num_options -gt 2 ] ; then | ||
echo "-b|--backend must be contain 'backend:arch' or 'backend'" >&2 | ||
exit 1 | ||
fi | ||
if [ "${backend_cfg[0]}" == "cuda" ] ; then | ||
result+=" -Dalpaka_ACC_GPU_CUDA_ENABLE=ON -Dalpaka_ACC_GPU_CUDA_ONLY_MODE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DCMAKE_CUDA_ARCHITECTURES=\"${backend_cfg[1]}\"" | ||
else | ||
result+=" -DCMAKE_CUDA_ARCHITECTURES=52" | ||
fi | ||
elif [ "${backend_cfg[0]}" == "omp2b" ] ; then | ||
result+=" -Dalpaka_ACC_CPU_B_OMP2_T_SEQ_ENABLE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DPMACC_CPU_ARCH=\"${backend_cfg[1]}\"" | ||
fi | ||
elif [ "${backend_cfg[0]}" == "serial" ] ; then | ||
result+=" -Dalpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DPMACC_CPU_ARCH=\"${backend_cfg[1]}\"" | ||
fi | ||
elif [ "${backend_cfg[0]}" == "tbb" ] ; then | ||
result+=" -Dalpaka_ACC_CPU_B_TBB_T_SEQ_ENABLE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DPMACC_CPU_ARCH=\"${backend_cfg[1]}\"" | ||
fi | ||
elif [ "${backend_cfg[0]}" == "threads" ] ; then | ||
result+=" -Dalpaka_ACC_CPU_B_SEQ_T_THREADS_ENABLE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DPMACC_CPU_ARCH=\"${backend_cfg[1]}\"" | ||
fi | ||
elif [ "${backend_cfg[0]}" == "hip" ] ; then | ||
result+=" -Dalpaka_ACC_GPU_HIP_ENABLE=ON -Dalpaka_ACC_GPU_HIP_ONLY_MODE=ON" | ||
if [ $num_options -eq 2 ] ; then | ||
result+=" -DGPU_TARGETS=\"${backend_cfg[1]}\"" | ||
else | ||
# If no architecture is given build for Radeon VII or MI50/60. | ||
result+=" -DGPU_TARGETS=gfx906" | ||
fi | ||
else | ||
echo "unsupported backend given '$1'" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "$result" | ||
exit 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
export code_DIR=$CI_PROJECT_DIR | ||
source $code_DIR/share/ci/backendFlags.sh | ||
|
||
# the default build type is Release | ||
# if neccesary, you can rerun the pipeline with another build type-> https://docs.gitlab.com/ee/ci/pipelines.html#manually-executing-pipelines | ||
# to change the build type, you must set the environment variable PIC_BUILD_TYPE | ||
if [[ ! -v PIC_BUILD_TYPE ]] ; then | ||
PIC_BUILD_TYPE=Release ; | ||
fi | ||
|
||
if [[ "$CI_RUNNER_TAGS" =~ .*cpuonly.* ]] ; then | ||
# In cases where the compile-only job is executed on a GPU runner but with different kinds of accelerators | ||
# we need to reset the variables to avoid compiling for the wrong architecture and accelerator. | ||
unset CI_GPUS | ||
unset CI_GPU_ARCH | ||
fi | ||
|
||
if [ -n "$CI_GPUS" ] ; then | ||
# select randomly a device if multiple exists | ||
# CI_GPUS is provided by the gitlab CI runner | ||
SELECTED_DEVICE_ID=$((RANDOM%CI_GPUS)) | ||
export HIP_VISIBLE_DEVICES=$SELECTED_DEVICE_ID | ||
export CUDA_VISIBLE_DEVICES=$SELECTED_DEVICE_ID | ||
echo "selected device '$SELECTED_DEVICE_ID' of '$CI_GPUS'" | ||
else | ||
echo "No GPU device selected because environment variable CI_GPUS is not set." | ||
fi | ||
|
||
if [[ "$PIC_BACKEND" =~ hip.* ]] ; then | ||
if [ -z "$CI_GPU_ARCH" ] ; then | ||
# In case the CI runner is not providing a GPU architecture e.g. a CPU runner set the architecture | ||
# to Radeon VII or MI50/60. | ||
export GPU_TARGETS="gfx906" | ||
fi | ||
export PIC_CMAKE_ARGS="$PIC_CMAKE_ARGS -DGPU_TARGETS=$GPU_TARGETS" | ||
fi | ||
|
||
################################################### | ||
# cmake config builder | ||
################################################### | ||
|
||
PIC_CONST_ARGS="" | ||
PIC_CONST_ARGS="${PIC_CONST_ARGS} -DCMAKE_BUILD_TYPE=${PIC_BUILD_TYPE}" | ||
CMAKE_ARGS="${PIC_CONST_ARGS} ${PIC_CMAKE_ARGS} -DCMAKE_CXX_COMPILER=${CXX_VERSION} -DBOOST_ROOT=/opt/boost/${BOOST_VERSION}" | ||
|
||
# check and activate if clang should be used as CUDA device compiler | ||
if [ -n "$CI_CLANG_AS_CUDA_COMPILER" ] ; then | ||
export PATH="$(agc-manager -b cuda)/bin:$PATH" | ||
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CUDA_COMPILER=${CXX_VERSION}" | ||
fi | ||
|
||
alpaka_backend=$(get_backend_flags ${PIC_BACKEND}) | ||
CMAKE_ARGS="$CMAKE_ARGS $alpaka_backend" | ||
|
||
################################################### | ||
# build and run unit tests | ||
################################################### | ||
|
||
# adjust number of parallel builds to avoid out of memory errors | ||
# PIC_BUILD_REQUIRED_MEM_BYTES is a configured variable in the CI web interface | ||
PIC_PARALLEL_BUILDS=$(($CI_RAM_BYTES_TOTAL/$PIC_BUILD_REQUIRED_MEM_BYTES)) | ||
|
||
# limit to number of available cores | ||
if [ $PIC_PARALLEL_BUILDS -gt $CI_CPUS ] ; then | ||
PIC_PARALLEL_BUILDS=$CI_CPUS | ||
fi | ||
|
||
# CI_MAX_PARALLELISM is a configured variable in the CI web interface | ||
if [ $PIC_PARALLEL_BUILDS -gt $CI_MAX_PARALLELISM ] ; then | ||
PIC_PARALLEL_BUILDS=$CI_MAX_PARALLELISM | ||
fi | ||
echo -e "\033[0;32m///////////////////////////////////////////////////" | ||
echo "PIC_BUILD_REQUIRED_MEM_BYTES-> ${PIC_BUILD_REQUIRED_MEM_BYTES}" | ||
echo "CI_RAM_BYTES_TOTAL -> ${CI_RAM_BYTES_TOTAL}" | ||
echo "CI_CPUS -> ${CI_CPUS}" | ||
echo "CI_MAX_PARALLELISM -> ${CI_MAX_PARALLELISM}" | ||
echo "number of processor threads -> $(nproc)" | ||
echo "number of parallel builds -> $PIC_PARALLEL_BUILDS" | ||
echo "cmake version -> $(cmake --version | head -n 1)" | ||
echo "build directory -> $(pwd)" | ||
echo "CMAKE_ARGS -> ${CMAKE_ARGS}" | ||
echo "accelerator -> ${PIC_BACKEND}" | ||
echo "input set -> ${PIC_TEST_CASE_FOLDER}" | ||
echo -e "/////////////////////////////////////////////////// \033[0m \n\n" | ||
|
||
|
||
## run unit tests | ||
export unitTest_folder=$HOME/buildPICUnitTest | ||
mkdir -p $unitTest_folder | ||
cd $unitTest_folder | ||
cmake $CMAKE_ARGS $code_DIR/share/picongpu/unit | ||
make -j $PIC_PARALLEL_BUILDS | ||
# execute on one device | ||
ctest -V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Copyright 2023 Rene Widera | ||
# | ||
# This file is part of PIConGPU. | ||
# | ||
# PIConGPU is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# PIConGPU is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PIConGPU. | ||
# If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.22.0) | ||
project("UnitTest") | ||
|
||
############################################################################### | ||
# Language Flags | ||
############################################################################### | ||
|
||
# enforce C++17 | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
|
||
################################################################################ | ||
# CMake policies | ||
# | ||
# Search in <PackageName>_ROOT: | ||
# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html | ||
################################################################################ | ||
if(POLICY CMP0074) | ||
cmake_policy(SET CMP0074 NEW) | ||
endif() | ||
|
||
################################################################################ | ||
# PMacc | ||
################################################################################ | ||
find_package(PMacc REQUIRED CONFIG PATHS "${CMAKE_CURRENT_SOURCE_DIR}/../../../include/pmacc") | ||
|
||
############################################################################### | ||
# Catch2 | ||
############################################################################### | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../../thirdParty/catch2 ${CMAKE_BINARY_DIR}/catch2) | ||
|
||
################################################################################ | ||
# MPI | ||
################################################################################ | ||
|
||
# MPI is provided by pmacc but to execute the binaries via root additional flags must be given to the execution command | ||
option(USE_MPI_AS_ROOT_USER "add --allow-run-as-root mpiexec used by ctest" OFF) | ||
|
||
if(USE_MPI_AS_ROOT_USER) | ||
set(MPI_RUNTIME_FLAGS "--allow-run-as-root") | ||
endif() | ||
|
||
# PIConGPU | ||
|
||
include_directories(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/../../../include") | ||
|
||
############################################################################### | ||
# Targets | ||
############################################################################### | ||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test) | ||
|
||
# CTest | ||
enable_testing() | ||
|
||
# Test cases | ||
# Each *UT.cpp file is an independent executable with one or more test cases | ||
file(GLOB_RECURSE TESTS *.cpp) | ||
foreach(dim 2 3) | ||
foreach(testCaseFilepath ${TESTS}) | ||
get_filename_component(testCaseFilename ${testCaseFilepath} NAME) | ||
string(REPLACE "UT.cpp" "" testCase ${testCaseFilename}) | ||
set(testExe "${PROJECT_NAME}-${testCase}-${dim}D") | ||
cupla_add_executable(${testExe} ${testCaseFilepath}) | ||
target_compile_definitions(${testExe} PRIVATE TEST_DIM=${dim}) | ||
target_link_libraries(${testExe} PUBLIC Catch2 Catch2WithMain) | ||
target_link_libraries(${testExe} PRIVATE pmacc::pmacc) | ||
add_test(NAME "${testCase}-${dim}D" COMMAND mpiexec ${MPI_RUNTIME_FLAGS} -n 1 ./${testExe}) | ||
endforeach() | ||
string(REPLACE "-DTEST_DIM=${dim}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PIConGPU unit test | ||
================== | ||
|
||
Test components in an as best as possible isolated environment. | ||
|
||
Example how to compile and execute the tests.compile | ||
|
||
.. code-block:: bash | ||
# compile for NVIDIA GPUs | ||
cmake <path_to_picongpu_source>/share/picongpu/unit/ -Dalpaka_ACC_GPU_CUDA_ENABLE=ON | ||
make -j | ||
ctest |
Oops, something went wrong.