Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8b5666e

Browse files
committedJun 26, 2024··
Add infrastructure for working with concepts
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.
1 parent b3f0d86 commit 8b5666e

File tree

11 files changed

+100
-6
lines changed

11 files changed

+100
-6
lines changed
 

‎.github/ci_setup.sh

+32
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@
1010
# Usage: source .github/ci_setup.sh <platform name>
1111
#
1212

13+
# Function to compare version numbers. Returns a true-like value if the first
14+
# argument is a smaller or equal version to the second. Taken from:
15+
# https://stackoverflow.com/a/25731924
16+
verleq() {
17+
printf "%s\n%s" $1 $2 | sort -Ct '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g
18+
}
19+
20+
# Regex to match NVCC versions
21+
NVCC_VERSION_REGEX="Cuda compilation tools, release ([0-9]+\.[0-9]+)"
22+
23+
# Regex to match CMake versions
24+
CMAKE_VERSION_REGEX="cmake version ([0-9]+\.[0-9]+\.[0-9]+)"
25+
1326
# The platform name.
1427
PLATFORM_NAME=$1
28+
CXX_STANDARD=$2
1529

1630
# Make sure that the build and CTest would use all available cores.
1731
export CMAKE_BUILD_PARALLEL_LEVEL=`nproc`
@@ -23,4 +37,22 @@ if [ "${PLATFORM_NAME}" = "SYCL" ]; then
2337
if [ -f "/opt/intel/oneapi/setvars.sh" ]; then
2438
source /opt/intel/oneapi/setvars.sh --include-intel-llvm
2539
fi
40+
elif [ "${PLATFORM_NAME}" = "CUDA" ]; then
41+
if verleq 20 $CXX_STANDARD; then
42+
if [[ $(nvcc --version) =~ $NVCC_VERSION_REGEX ]]; then
43+
nvcc_version="${BASH_REMATCH[1]}"
44+
45+
if [[ $(cmake --version) =~ $CMAKE_VERSION_REGEX ]]; then
46+
cmake_version="${BASH_REMATCH[1]}"
47+
48+
if verleq 12.0 $nvcc_version && verleq $cmake_version 3.25.2; then
49+
export CUDAFLAGS="-std=c++20 $CUDAFLAGS"
50+
fi
51+
else
52+
echo "Warning: CMake version didn't match regex '$CMAKE_VERSION_REGEX'"
53+
fi
54+
else
55+
echo "Warning: NVCC version didn't match regex '$NVCC_VERSION_REGEX'"
56+
fi
57+
fi
2658
fi

‎.github/workflows/builds.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: CPU
3636
container: ghcr.io/acts-project/ubuntu2404:48
3737
cxx_standard: "20"
38-
options: -DTRACCC_USE_ROOT=FALSE
38+
options: -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
3939
- name: HIP
4040
container: ghcr.io/acts-project/ubuntu2004_rocm:47
4141
cxx_standard: "17"
@@ -47,7 +47,7 @@ jobs:
4747
- name: CUDA
4848
container: ghcr.io/acts-project/ubuntu2204_cuda:48
4949
cxx_standard: "20"
50-
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE
50+
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
5151
- name: SYCL
5252
container: ghcr.io/acts-project/ubuntu2004_oneapi:47
5353
cxx_standard: "17"
@@ -84,7 +84,7 @@ jobs:
8484
- uses: actions/checkout@v3
8585
- name: Configure
8686
run: |
87-
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
87+
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
8888
cmake \
8989
-DCMAKE_BUILD_TYPE=${{ matrix.build }} \
9090
-DCMAKE_CXX_STANDARD=${{ matrix.platform.cxx_standard }} \
@@ -97,7 +97,7 @@ jobs:
9797
-B build
9898
- name: Build
9999
run: |
100-
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
100+
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
101101
cmake --build build
102102
- name: Download data files
103103
if: "matrix.platform.name == 'CPU'"
@@ -106,7 +106,7 @@ jobs:
106106
if: "matrix.platform.name == 'CPU'"
107107
run: |
108108
cd build
109-
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }}
109+
source ${GITHUB_WORKSPACE}/.github/ci_setup.sh ${{ matrix.platform.name }} ${{ matrix.platform.cxx_standard }}
110110
ctest --output-on-failure
111111
- name: FP64 Compliance
112112
if: "matrix.platform.name == 'CUDA' && matrix.build == 'Debug'"

‎.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stages:
1414
before_script:
1515
- git clone $CLONE_URL src
1616
- git -C src checkout $HEAD_SHA
17-
- source ./src/.github/ci_setup.sh ${TRACCC_BUILD_TYPE}
17+
- source ./src/.github/ci_setup.sh ${TRACCC_BUILD_TYPE} 17
1818

1919
# Build job template.
2020
.build_template: &build_job

‎CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ option( TRACCC_BUILD_EXAMPLES "Build the examples of traccc" TRUE )
6666
option( TRACCC_USE_SYSTEM_LIBS "Use system libraries be default" FALSE )
6767
option( TRACCC_USE_ROOT "Use ROOT in the build (if needed)" TRUE )
6868

69+
# Flag enforcing concept usage.
70+
option( TRACCC_ENFORCE_CONCEPTS "Throw an error if concepts are not available" FALSE )
71+
6972
# Clean up.
7073
unset( TRACCC_BUILD_CUDA_DEFAULT )
7174

‎core/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ traccc_add_library( traccc_core core TYPE SHARED
1515
"include/traccc/definitions/primitives.hpp"
1616
"include/traccc/definitions/common.hpp"
1717
"include/traccc/definitions/qualifiers.hpp"
18+
# Compiler checks.
19+
"src/compiler_checks.cpp"
1820
# Event data model.
1921
"include/traccc/edm/details/container_base.hpp"
2022
"include/traccc/edm/details/container_element.hpp"
@@ -110,3 +112,11 @@ target_link_libraries( traccc_core
110112
# CUDA or HIP backend with SYCL.
111113
target_compile_definitions( traccc_core
112114
PUBLIC $<$<COMPILE_LANGUAGE:SYCL>:EIGEN_NO_CUDA EIGEN_NO_HIP> )
115+
116+
if ( TRACCC_ENFORCE_CONCEPTS )
117+
target_compile_definitions(
118+
traccc_core
119+
PUBLIC
120+
TRACCC_ENFORCE_CONCEPTS
121+
)
122+
endif ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#pragma once
10+
11+
#if __cpp_concepts >= 201907L
12+
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
13+
#elif defined(TRACCC_ENFORCE_CONCEPTS)
14+
#error \
15+
"`TRACCC_ENFORCE_CONCEPTS` is set, but concepts are not available. This constitutes a fatal error."
16+
#else
17+
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
18+
#endif

‎core/src/compiler_checks.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#include "traccc/definitions/concepts.hpp"

‎device/cuda/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
2828
"src/utils/opaque_stream.cpp"
2929
"src/utils/utils.hpp"
3030
"src/utils/utils.cpp"
31+
# Compiler checks.
32+
"src/compiler_checks.cu"
3133
# Seed finding code.
3234
"include/traccc/cuda/seeding/track_params_estimation.hpp"
3335
"src/seeding/track_params_estimation.cu"

‎device/cuda/src/compiler_checks.cu

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#include "traccc/definitions/concepts.hpp"

‎device/sycl/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ traccc_add_library( traccc_sycl sycl TYPE SHARED
2525
"include/traccc/sycl/utils/queue_wrapper.hpp"
2626
"include/traccc/sycl/utils/calculate1DimNdRange.hpp"
2727
"include/traccc/sycl/utils/make_prefix_sum_buff.hpp"
28+
# Compiler checks.
29+
"src/compiler_checks.sycl"
2830
# implementation files
2931
"src/clusterization/clusterization_algorithm.sycl"
3032
"src/clusterization/spacepoint_formation_algorithm.sycl"

‎device/sycl/src/compiler_checks.sycl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#include "traccc/definitions/concepts.hpp"

0 commit comments

Comments
 (0)
Please sign in to comment.