Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 2d4b69d

Browse files
committed
* CMake: Add support for detecting the compute archs of the GPUs in your system
at configure time. * gpuCI: Add a GPU node configuration that builds and tests as little as possible. * gpuCI: Cleanup logic for different build and test configurations. * gpuCI: Fix an unfortunate typo in `determine_build_parallelism.bash` which led to the parallelism level not being set.
1 parent 3300e98 commit 2d4b69d

5 files changed

Lines changed: 107 additions & 18 deletions

File tree

ci/common/build.bash

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ cd build
3737
# The Docker image sets up `${CXX}` and `${CUDACXX}`.
3838
CMAKE_FLAGS="-G Ninja -DCMAKE_CXX_COMPILER='${CXX}' -DCMAKE_CUDA_COMPILER='${CUDACXX}'"
3939

40-
if [ "${BUILD_MODE}" == "branch" ]; then
41-
# Post-commit build.
40+
if [ "${BUILD_TYPE}" == "cpu" ] && [ "${BUILD_MODE}" == "branch" ]; then
41+
# Post-commit CPU CI builds (greatest coverage).
4242
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_INCLUDE_CUB_CMAKE=ON"
4343
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_MULTICONFIG=ON"
4444
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP11=ON"
@@ -50,13 +50,8 @@ if [ "${BUILD_MODE}" == "branch" ]; then
5050
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_SYSTEM_OMP=ON"
5151
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA=ON"
5252
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_WORKLOAD=LARGE"
53-
else
54-
# Pre-commit build.
55-
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_DISABLE_ARCH_BY_DEFAULT=ON"
56-
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_50=ON"
57-
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_60=ON"
58-
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_70=ON"
59-
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_80=ON"
53+
elif [ "${BUILD_TYPE}" == "cpu" ] || [ "${BUILD_TYPE}" == "local" ]; then
54+
# Pre-commit CPU CI builds and local builds.
6055
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_INCLUDE_CUB_CMAKE=ON"
6156
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_MULTICONFIG=ON"
6257
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP11=ON"
@@ -68,6 +63,19 @@ else
6863
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_SYSTEM_OMP=ON"
6964
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA=ON"
7065
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_MULTICONFIG_WORKLOAD=SMALL"
66+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_AUTO_DETECT_COMPUTE_ARCHS=ON"
67+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_50=ON"
68+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_60=ON"
69+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_70=ON"
70+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_ENABLE_COMPUTE_80=ON"
71+
elif [ "${BUILD_TYPE}" == "gpu" ]; then
72+
# Pre- and post-commit GPU CI builds (least coverage).
73+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_INCLUDE_CUB_CMAKE=ON"
74+
CMAKE_FLAGS="${CMAKE_FLAGS} -DCUB_TEST_WORKLOAD=BASIC"
75+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_HOST_SYSTEM=CPP"
76+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_DEVICE_SYSTEM=CUDA"
77+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_CPP_DIALECT=14"
78+
CMAKE_FLAGS="${CMAKE_FLAGS} -DTHRUST_AUTO_DETECT_COMPUTE_ARCHS=ON"
7179
fi
7280

7381
CMAKE_BUILD_FLAGS="-j${PARALLEL_LEVEL}"
@@ -79,7 +87,11 @@ fi
7987
CTEST_FLAGS=""
8088

8189
if [ "${BUILD_TYPE}" == "cpu" ]; then
90+
# Pre- and post-commit CPU CI tests.
8291
CTEST_FLAGS="${CTEST_FLAGS} -E ^cub|^thrust.*cuda"
92+
elif [ "${BUILD_TYPE}" == "gpu" ]; then
93+
# Pre- and post-commit GPU CI tests (least coverage).
94+
CTEST_FLAGS="${CTEST_FLAGS} -E ^cub.*thorough|quicker$"
8395
fi
8496

8597
if [ ! -z "${@}" ]; then
@@ -102,15 +114,18 @@ ${CUDACXX} --version
102114
################################################################################
103115

104116
logger "Configure Thrust and CUB..."
117+
echo cmake .. ${CMAKE_FLAGS}
105118
cmake .. ${CMAKE_FLAGS}
106119

107120
logger "Build Thrust and CUB..."
121+
echo cmake --build . ${CMAKE_BUILD_FLAGS}
108122
cmake --build . ${CMAKE_BUILD_FLAGS}
109123

110124
################################################################################
111125
# TEST - Run Thrust and CUB examples and tests.
112126
################################################################################
113127

114128
logger "Test Thrust and CUB..."
129+
echo ctest ${CTEST_FLAGS}
115130
ctest ${CTEST_FLAGS}
116131

ci/common/determine_build_parallelism.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export MEM_BOUND_THREADS=$((${TOTAL_MEM_KB} / (2 * 1000 * 1000))) # 2 GB / Build
5858

5959
# Pick the smaller of the two as the default.
6060
if [ ${MEM_BOUND_THREADS} -lt ${CPU_BOUND_THREADS} ]; then
61-
export PARLLEL_LEVEL=${MEM_BOUND_THREADS}
61+
export PARALLEL_LEVEL=${MEM_BOUND_THREADS}
6262
else
63-
export PARLLEL_LEVEL=${CPU_BOUND_THREADS}
63+
export PARALLEL_LEVEL=${CPU_BOUND_THREADS}
6464
fi
6565

6666
if [ "${QUIET}" == 0 ]; then
@@ -69,6 +69,6 @@ if [ "${QUIET}" == 0 ]; then
6969
echo "Total Mem: ${TOTAL_MEM_KB} [kb]"
7070
echo "CPU Bound Threads: ${CPU_BOUND_THREADS} [threads]"
7171
echo "Mem Bound Threads: ${MEM_BOUND_THREADS} [threads]"
72-
echo "Parallel Level: ${PARLLEL_LEVEL} [threads]"
72+
echo "Parallel Level: ${PARALLEL_LEVEL} [threads]"
7373
fi
7474

ci/local/build.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ docker run --rm -it ${GPU_OPTS} \
193193
-v "${PASSWD_PATH}":/etc/passwd:ro \
194194
-v "${GROUP_PATH}":/etc/group:ro \
195195
-e "WORKSPACE=${REPOSITORY_PATH_IN_CONTAINER}" \
196-
-e "BUILD_TYPE=gpu" \
196+
-e "BUILD_TYPE=local" \
197197
-e "PARALLEL_LEVEL=${PARALLEL_LEVEL}" \
198198
-w "${BUILD_PATH_IN_CONTAINER}" \
199199
"${IMAGE}" bash -c "${COMMAND}"
200200

201+

cmake/ThrustCudaConfig.cmake

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ list(LENGTH THRUST_KNOWN_COMPUTE_ARCHS max_idx)
3636
math(EXPR max_idx "${max_idx} - 1")
3737
list(GET THRUST_KNOWN_COMPUTE_ARCHS ${max_idx} highest_arch)
3838

39+
option(THRUST_AUTO_DETECT_COMPUTE_ARCHS
40+
"If ON, CUDA architectures for all GPUs in the current system are enabled and all other CUDA architectures are disabled."
41+
OFF
42+
)
43+
44+
if (THRUST_AUTO_DETECT_COMPUTE_ARCHS)
45+
set(detect_compute_archs_source ${Thrust_SOURCE_DIR}/cmake/detect_compute_archs.cu)
46+
set(detect_compute_archs_exe ${PROJECT_BINARY_DIR}/detect_compute_archs)
47+
set(detect_compute_archs_error_log ${PROJECT_BINARY_DIR}/detect_compute_archs.stderr.log)
48+
execute_process(
49+
COMMAND ${CMAKE_CUDA_COMPILER}
50+
-std=c++11
51+
-o ${detect_compute_archs_exe}
52+
--run
53+
${detect_compute_archs_source}
54+
OUTPUT_VARIABLE detected_archs
55+
OUTPUT_STRIP_TRAILING_WHITESPACE
56+
ERROR_FILE ${detect_compute_archs_error_log})
57+
foreach (arch IN LISTS detected_archs)
58+
string(APPEND detected_message " sm_${arch}")
59+
endforeach()
60+
message(STATUS "Thrust: Automatically detected CUDA architectures:${detected_message}")
61+
endif()
62+
3963
set(option_init OFF)
4064
if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
4165
set(option_init ON)
@@ -46,15 +70,21 @@ option(THRUST_DISABLE_ARCH_BY_DEFAULT
4670
)
4771

4872
set(option_init ON)
49-
if (THRUST_DISABLE_ARCH_BY_DEFAULT)
73+
if (THRUST_DISABLE_ARCH_BY_DEFAULT OR THRUST_AUTO_DETECT_COMPUTE_ARCHS)
5074
set(option_init OFF)
5175
endif()
5276

5377
set(num_archs_enabled 0)
5478
foreach (arch IN LISTS THRUST_KNOWN_COMPUTE_ARCHS)
79+
set(this_option_init ${option_init})
80+
81+
if (${arch} IN_LIST detected_archs)
82+
set(this_option_init ON)
83+
endif()
84+
5585
option(THRUST_ENABLE_COMPUTE_${arch}
5686
"Enable code generation for tests for sm_${arch}"
57-
${option_init}
87+
${this_option_init}
5888
)
5989

6090
if (NOT THRUST_ENABLE_COMPUTE_${arch})
@@ -75,7 +105,7 @@ foreach (arch IN LISTS THRUST_KNOWN_COMPUTE_ARCHS)
75105
set(arch_flag "-gencode arch=compute_${arch},code=sm_${arch}")
76106
endif()
77107

78-
string(APPEND COMPUTE_MESSAGE " sm_${arch}")
108+
string(APPEND compute_message " sm_${arch}")
79109
string(APPEND THRUST_CUDA_FLAGS_NO_RDC " ${arch_flag}")
80110
if (NOT arch IN_LIST no_rdc_archs)
81111
string(APPEND THRUST_CUDA_FLAGS_RDC " ${arch_flag}")
@@ -91,11 +121,11 @@ if (NOT "Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
91121
string(APPEND THRUST_CUDA_FLAGS_BASE
92122
" -gencode arch=compute_${highest_arch},code=compute_${highest_arch}"
93123
)
94-
string(APPEND COMPUTE_MESSAGE " compute_${highest_arch}")
124+
string(APPEND compute_message " compute_${highest_arch}")
95125
endif()
96126
endif()
97127

98-
message(STATUS "Thrust: Enabled CUDA architectures:${COMPUTE_MESSAGE}")
128+
message(STATUS "Thrust: Enabled CUDA architectures:${compute_message}")
99129

100130
# RDC is off by default in NVCC and on by default in Feta. Turning off RDC
101131
# isn't currently supported by Feta. So, we default to RDC off for NVCC and

cmake/detect_compute_archs.cu

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2019-2020 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <cstdio>
18+
#include <set>
19+
#include <string>
20+
21+
int main(int argc, char** argv) {
22+
std::set<std::string> archs;
23+
int devices;
24+
if ((cudaGetDeviceCount(&devices) == cudaSuccess) && (devices > 0)) {
25+
for (int dev = 0; dev < devices; ++dev) {
26+
char buff[32];
27+
cudaDeviceProp prop;
28+
if(cudaGetDeviceProperties(&prop, dev) != cudaSuccess) continue;
29+
sprintf(buff, "%d%d", prop.major, prop.minor);
30+
archs.insert(buff);
31+
}
32+
}
33+
if (archs.empty()) {
34+
printf("ALL");
35+
} else {
36+
bool first = true;
37+
for(const auto& arch : archs) {
38+
printf(first ? "%s" : ";%s", arch.c_str());
39+
first = false;
40+
}
41+
}
42+
printf("\n");
43+
}

0 commit comments

Comments
 (0)