Skip to content

Commit

Permalink
Add infrastructure for working with concepts
Browse files Browse the repository at this point in the history
This commit adds the `TRACCC_CONSTRAINT` macro which acts as a concept
in C++20 builds, and simply acts as the `typename` keyword in builds
with older standards. It also adds the `TRACCC_ENFORCE_CONCEPTS` CMake
flag which will throw an error if concepts are not available.
  • Loading branch information
stephenswat committed Jun 26, 2024
1 parent b3f0d86 commit 1423328
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 6 deletions.
32 changes: 32 additions & 0 deletions .github/ci_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@
# Usage: source .github/ci_setup.sh <platform name>
#

# Function to compare version numbers. Returns a true-like value if the first
# argument is a smaller or equal version to the second. Taken from:
# https://stackoverflow.com/a/25731924
verleq() {
printf "%s\n%s" $1 $2 | sort -Ct '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g
}

# Regex to match NVCC versions
NVCC_VERSION_REGEX="Cuda compilation tools, release ([0-9]+\.[0-9]+)"

# Regex to match CMake versions
CMAKE_VERSION_REGEX="cmake version ([0-9]+\.[0-9]+\.[0-9]+)"

# The platform name.
PLATFORM_NAME=$1
CXX_STANDARD=$2

# Make sure that the build and CTest would use all available cores.
export CMAKE_BUILD_PARALLEL_LEVEL=`nproc`
Expand All @@ -23,4 +37,22 @@ if [ "${PLATFORM_NAME}" = "SYCL" ]; then
if [ -f "/opt/intel/oneapi/setvars.sh" ]; then
source /opt/intel/oneapi/setvars.sh --include-intel-llvm
fi
elif [ "${PLATFORM_NAME}" = "CUDA" ]; then
if verleq 20 $CXX_STANDARD; then
if [[ $(nvcc --version) =~ $NVCC_VERSION_REGEX ]]; then
nvcc_version="${BASH_REMATCH[1]}"

if [[ $(cmake --version) =~ $CMAKE_VERSION_REGEX ]]; then
cmake_version="${BASH_REMATCH[1]}"

if verleq $nvcc_version 11.99 && verleq $cmake_version 3.25.2; then
export CUDAFLAGS="-std=c++20 $CUDAFLAGS"
fi
else
echo "Warning: CMake version didn't match regex '$CMAKE_VERSION_REGEX'"
fi
else
echo "Warning: NVCC version didn't match regex '$NVCC_VERSION_REGEX'"
fi
fi
fi
10 changes: 5 additions & 5 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: CPU
container: ghcr.io/acts-project/ubuntu2404:48
cxx_standard: "20"
options: -DTRACCC_USE_ROOT=FALSE
options: -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
- name: HIP
container: ghcr.io/acts-project/ubuntu2004_rocm:47
cxx_standard: "17"
Expand All @@ -47,7 +47,7 @@ jobs:
- name: CUDA
container: ghcr.io/acts-project/ubuntu2204_cuda:48
cxx_standard: "20"
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
- name: SYCL
container: ghcr.io/acts-project/ubuntu2004_oneapi:47
cxx_standard: "17"
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
- uses: actions/checkout@v3
- name: Configure
run: |
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
cmake \
-DCMAKE_BUILD_TYPE=${{ matrix.build }} \
-DCMAKE_CXX_STANDARD=${{ matrix.platform.cxx_standard }} \
Expand All @@ -97,7 +97,7 @@ jobs:
-B build
- name: Build
run: |
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
cmake --build build
- name: Download data files
if: "matrix.platform.name == 'CPU'"
Expand All @@ -106,7 +106,7 @@ jobs:
if: "matrix.platform.name == 'CPU'"
run: |
cd build
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
ctest --output-on-failure
- name: FP64 Compliance
if: "matrix.platform.name == 'CUDA' && matrix.build == 'Debug'"
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stages:
before_script:
- git clone $CLONE_URL src
- git -C src checkout $HEAD_SHA
- source ./src/.github/ci_setup.sh ${TRACCC_BUILD_TYPE}
- source ./src/.github/ci_setup.sh ${TRACCC_BUILD_TYPE} 17

# Build job template.
.build_template: &build_job
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ option( TRACCC_BUILD_EXAMPLES "Build the examples of traccc" TRUE )
option( TRACCC_USE_SYSTEM_LIBS "Use system libraries be default" FALSE )
option( TRACCC_USE_ROOT "Use ROOT in the build (if needed)" TRUE )

# Flag enforcing concept usage.
option( TRACCC_ENFORCE_CONCEPTS "Throw an error if concepts are not available" FALSE )

# Clean up.
unset( TRACCC_BUILD_CUDA_DEFAULT )

Expand Down
10 changes: 10 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/definitions/primitives.hpp"
"include/traccc/definitions/common.hpp"
"include/traccc/definitions/qualifiers.hpp"
# Compiler checks.
"src/compiler_checks.cpp"
# Event data model.
"include/traccc/edm/details/container_base.hpp"
"include/traccc/edm/details/container_element.hpp"
Expand Down Expand Up @@ -110,3 +112,11 @@ target_link_libraries( traccc_core
# CUDA or HIP backend with SYCL.
target_compile_definitions( traccc_core
PUBLIC $<$<COMPILE_LANGUAGE:SYCL>:EIGEN_NO_CUDA EIGEN_NO_HIP> )

if ( TRACCC_ENFORCE_CONCEPTS )
target_compile_definitions(
traccc_core
PUBLIC
TRACCC_ENFORCE_CONCEPTS
)
endif ()
18 changes: 18 additions & 0 deletions core/include/traccc/definitions/concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* traccc library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

#if __cpp_concepts >= 201907L
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
#elif defined(TRACCC_ENFORCE_CONCEPTS)
#error \
"`TRACCC_ENFORCE_CONCEPTS` is set, but concepts are not available. This constitutes a fatal error."
#else
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
#endif
9 changes: 9 additions & 0 deletions core/src/compiler_checks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* traccc library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#include "traccc/definitions/concepts.hpp"
2 changes: 2 additions & 0 deletions device/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
"src/utils/opaque_stream.cpp"
"src/utils/utils.hpp"
"src/utils/utils.cpp"
# Compiler checks.
"src/compiler_checks.cu"
# Seed finding code.
"include/traccc/cuda/seeding/track_params_estimation.hpp"
"src/seeding/track_params_estimation.cu"
Expand Down
9 changes: 9 additions & 0 deletions device/cuda/src/compiler_checks.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* traccc library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#include "traccc/definitions/concepts.hpp"
2 changes: 2 additions & 0 deletions device/sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ traccc_add_library( traccc_sycl sycl TYPE SHARED
"include/traccc/sycl/utils/queue_wrapper.hpp"
"include/traccc/sycl/utils/calculate1DimNdRange.hpp"
"include/traccc/sycl/utils/make_prefix_sum_buff.hpp"
# Compiler checks.
"src/compiler_checks.sycl"
# implementation files
"src/clusterization/clusterization_algorithm.sycl"
"src/clusterization/spacepoint_formation_algorithm.sycl"
Expand Down
9 changes: 9 additions & 0 deletions device/sycl/src/compiler_checks.sycl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* traccc library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#include "traccc/definitions/concepts.hpp"

0 comments on commit 1423328

Please sign in to comment.