Skip to content

Commit d2d846b

Browse files
authored
Merge pull request #210 from alicevision/ci/moreImages
[cmake] add support for cuda 12
2 parents 7e2ef3c + ee7a02d commit d2d846b

File tree

4 files changed

+215
-20
lines changed

4 files changed

+215
-20
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ on:
1919
jobs:
2020
build:
2121
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
container: [ "alicevision/cctag-deps:cuda11.8.0-ubuntu20.04", "alicevision/cctag-deps:cuda12.1.0-ubuntu22.04" ]
25+
build_type: [ "Release", "Debug" ]
26+
2227
container:
23-
image: alicevision/cctag-deps:cuda11.8.0-ubuntu20.04
28+
image: ${{ matrix.container }}
29+
2430
env:
2531
DEPS_INSTALL_DIR: /opt/
26-
BUILD_TYPE: Release
32+
BUILD_TYPE: ${{ matrix.build_type }}
2733
CTEST_OUTPUT_ON_FAILURE: 1
2834
steps:
2935
- uses: actions/checkout@v2

CMakeLists.txt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ if(BUILD_SHARED_LIBS)
135135
endif()
136136

137137
if(CCTAG_WITH_CUDA)
138+
set(CCTAG_MIN_CUDA_VERSION 9.0)
138139
message( STATUS "Try finding CUDA" )
139140
if(BUILD_SHARED_LIBS)
140141
message(STATUS "BUILD_SHARED_LIBS ON")
@@ -149,7 +150,7 @@ if(CCTAG_WITH_CUDA)
149150
set(CUDA_USE_STATIC_CUDA_RUNTIME ON)
150151
endif()
151152

152-
find_package(CUDA 9.0 REQUIRED)
153+
find_package(CUDA ${CCTAG_MIN_CUDA_VERSION} REQUIRED)
153154

154155
include(CheckNvccCompilerFlag)
155156

@@ -165,22 +166,26 @@ if(CCTAG_WITH_CUDA)
165166
message(STATUS "Building in release mode")
166167
endif()
167168

168-
set(CCTAG_CUDA_CC_LIST_INIT0 3.5 3.7 5.0 5.2)
169-
if( CUDA_VERSION VERSION_GREATER_EQUAL "9.0" )
170-
list(APPEND CCTAG_CUDA_CC_LIST_INIT0 6.0 6.1 7.0)
171-
endif()
172-
if( CUDA_VERSION VERSION_GREATER_EQUAL "10.0" )
173-
list(APPEND CCTAG_CUDA_CC_LIST_INIT0 7.5)
174-
endif()
175-
set(CCTAG_CUDA_CC_LIST_INIT ${CCTAG_CUDA_CC_LIST_INIT0} CACHE STRING "CUDA CCs as compile targets")
176-
169+
# if CCTAG_CUDA_CC_CURRENT_ONLY is specified only build for the current hardware architecture
177170
if(CCTAG_CUDA_CC_CURRENT_ONLY)
178171
set(CCTAG_CUDA_CC_LIST_BASIC Auto)
172+
CUDA_SELECT_NVCC_ARCH_FLAGS(CCTAG_CUDA_GENCODE_FLAGS ${CCTAG_CUDA_CC_LIST_BASIC})
179173
else()
180-
set(CCTAG_CUDA_CC_LIST_BASIC ${CCTAG_CUDA_CC_LIST_INIT})
174+
# otherwise build for all the architectures that are compatible with the current version of CUDA
175+
# or those that are provided by the user setting CCTAG_CUDA_CC_LIST
176+
include(ChooseCudaCC)
177+
if(NOT DEFINED CCTAG_CUDA_CC_LIST)
178+
chooseCudaCC(CCTAG_CUDA_CC_LIST_BASIC
179+
CCTAG_CUDA_GENCODE_FLAGS
180+
MIN_CC 30
181+
MIN_CUDA_VERSION ${CCTAG_MIN_CUDA_VERSION})
182+
set(CCTAG_CUDA_CC_LIST ${CCTAG_CUDA_CC_LIST_BASIC} CACHE STRING "CUDA CC versions to compile")
183+
else()
184+
getFlagsForCudaCCList(CCTAG_CUDA_CC_LIST CCTAG_CUDA_GENCODE_FLAGS)
185+
endif()
181186
endif()
182-
CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS ${CCTAG_CUDA_CC_LIST_BASIC})
183-
LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS})
187+
188+
list(APPEND CUDA_NVCC_FLAGS "${CCTAG_CUDA_GENCODE_FLAGS}")
184189

185190
if(NOT MSVC)
186191
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-std=c++${CCTAG_CXX_STANDARD}")
@@ -273,7 +278,7 @@ message(STATUS "Build tests: " ${CCTAG_BUILD_TESTS})
273278
message(STATUS "Build documentation: " ${CCTAG_BUILD_DOC})
274279
message(STATUS "Cuda support: " ${CCTAG_WITH_CUDA})
275280
if(CCTAG_WITH_CUDA)
276-
message(STATUS "Compiling for CUDA CCs: ${ARCH_FLAGS}")
281+
message(STATUS "Compiling for CUDA CCs: ${CCTAG_CUDA_GENCODE_FLAGS}")
277282
endif()
278283
message(STATUS "Enable Eigen alignment: " ${CCTAG_EIGEN_MEMORY_ALIGNMENT})
279284
message(STATUS "Enable AVX2 optimizations: " ${CCTAG_ENABLE_SIMD_AVX2})

Dockerfile_deps

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ RUN wget https://cmake.org/files/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION_FULL}.t
5050
rm -rf cmake
5151

5252

53-
ENV BOOST_VERSION="1.76.0"
54-
ENV BOOST_VERSION_FILENAME="1_76_0"
53+
ENV BOOST_VERSION="1.80.0"
54+
ENV BOOST_VERSION_FILENAME="1_80_0"
5555
WORKDIR /tmp/boost
5656
RUN wget https://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION_FILENAME}.tar.gz && \
5757
tar -xzf boost_${BOOST_VERSION_FILENAME}.tar.gz && \
@@ -74,7 +74,7 @@ RUN wget https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VERSION}/${EIGEN_VE
7474
rm -rf /tmp/eigen
7575

7676
# install opencv
77-
ENV OPENCV_VERSION="4.5.3"
77+
ENV OPENCV_VERSION="4.7.0"
7878
WORKDIR /tmp/opencv
7979
RUN wget https://github.com/opencv/opencv/archive/"${OPENCV_VERSION}".zip && \
8080
unzip ${OPENCV_VERSION}.zip && \
@@ -102,7 +102,7 @@ RUN wget https://github.com/opencv/opencv/archive/"${OPENCV_VERSION}".zip && \
102102
rm -r /tmp/opencv
103103

104104
# install tbb
105-
ENV TBB_VERSION="2021.5.0"
105+
ENV TBB_VERSION="2021.9.0"
106106
WORKDIR /tmp/tbb
107107
RUN wget https://github.com/oneapi-src/oneTBB/archive/refs/tags/v"${TBB_VERSION}".zip && \
108108
unzip v${TBB_VERSION}.zip && \

cmake/ChooseCudaCC.cmake

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#
2+
# This file contains two functions:
3+
# chooseCudaCC
4+
# getFlagsForCudaCCList
5+
#
6+
# Motivation:
7+
# CUDA hardware and SDKs are developing over time, different SDK support different
8+
# hardware, and supported hardware differs depending on platform even for the same
9+
# SDK version. This file attempts to provide a function that returns a valid selection
10+
# of hardware for the current SDK and platform. It will require updates as CUDA develops,
11+
# and it is currently not complete in terms of existing platforms that support CUDA.
12+
#
13+
14+
#
15+
# Return the minimal set of supported Cuda CC
16+
#
17+
# Usage:
18+
# chooseCudaCC(SUPPORTED_CC SUPPORTED_GENCODE_FLAGS
19+
# [MIN_CUDA_VERSION X.Y]
20+
# [MIN_CC XX ])
21+
#
22+
# SUPPORTED_CC out variable. Stores the list of supported CC.
23+
# SUPPORTED_GENCODE_FLAGS out variable. List of gencode flags to append to, e.g., CUDA_NVCC_FLAGS
24+
# MIN_CUDA_VERSION the minimal supported version of cuda (e.g. 7.5, default 7.0).
25+
# MIN_CC minimal supported Cuda CC by the project (e.g. 35, default 20)
26+
#
27+
# This function does not edit cache entries or variables in the parent scope
28+
# except for the variables whose names are supplied for SUPPORTED_CC and
29+
# SUPPORTED_GENCODE_FLAGS
30+
#
31+
# You may want to cache SUPPORTED_CC and append SUPPORTED_GENCODE_FLAGS to
32+
# CUDA_NVCC_FLAGS.
33+
# Like this:
34+
# set(MYCC ${MYCC} CACHE STRING "CUDA CC versions to compile")
35+
# end
36+
# set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};${MY_GENCODE_FLAGS}")
37+
#
38+
function(chooseCudaCC SUPPORTED_CC SUPPORTED_GENCODE_FLAGS)
39+
set(options "")
40+
set(oneValueArgs MIN_CUDA_VERSION MIN_CC)
41+
set(multipleValueArgs "")
42+
cmake_parse_arguments(CHOOSE_CUDA "${options}" "${oneValueArgs}" "${multipleValueArgs}" ${ARGN})
43+
44+
if(NOT DEFINED CHOOSE_CUDA_MIN_CC)
45+
set(CHOOSE_CUDA_MIN_CC 20)
46+
endif()
47+
if(NOT DEFINED CHOOSE_CUDA_MIN_CUDA_VERSION)
48+
set(CHOOSE_CUDA_MIN_CUDA_VERSION 7.0)
49+
endif()
50+
51+
find_package(CUDA ${CHOOSE_CUDA_MIN_CUDA_VERSION} REQUIRED)
52+
53+
if(NOT CUDA_FOUND)
54+
message(FATAL_ERROR "Could not find CUDA >= ${CHOOSE_CUDA_MIN_CUDA_VERSION}")
55+
endif()
56+
57+
#
58+
# Create a list of possible CCs for each host processor.
59+
# This may require tuning: CUDA cards exist in AIX machines with POWER CPUs,
60+
# it is possible that non-Tegra ARM systems exist as well.
61+
# For now, this is my best guess.
62+
#
63+
set(TEGRA_SUPPORTED_PROCESSORS "armv71;arm;aarch64")
64+
set(OTHER_SUPPORTED_PROCESSORS "i686;x86_64;AMD64")
65+
66+
set(CC_LIST_BY_SYSTEM_PROCESSOR "")
67+
if(CMAKE_SYSTEM_PROCESSOR IN_LIST OTHER_SUPPORTED_PROCESSORS)
68+
list(APPEND CC_LIST_BY_SYSTEM_PROCESSOR "20;21;30;35;50;52;60;61;70;75;80;86;89;90")
69+
endif()
70+
if(CMAKE_SYSTEM_PROCESSOR IN_LIST TEGRA_SUPPORTED_PROCESSORS)
71+
list(APPEND CC_LIST_BY_SYSTEM_PROCESSOR "32;53;62;72")
72+
endif()
73+
if(NOT CC_LIST_BY_SYSTEM_PROCESSOR)
74+
message(FATAL_ERROR "Unknown how to build for ${CMAKE_SYSTEM_PROCESSOR}")
75+
endif()
76+
77+
#
78+
# Default setting of the CUDA CC versions to compile.
79+
# Shortening the lists saves a lot of compile time.
80+
#
81+
82+
# The current version last time this list was updated was CUDA 12.1.
83+
if(CUDA_VERSION VERSION_GREATER_EQUAL 12)
84+
set(CUDA_MIN_CC 50)
85+
set(CUDA_MAX_CC 90)
86+
elseif(CUDA_VERSION VERSION_GREATER_EQUAL 11.8)
87+
set(CUDA_MIN_CC 35)
88+
set(CUDA_MAX_CC 90)
89+
elseif(CUDA_VERSION VERSION_GREATER_EQUAL 11.1)
90+
set(CUDA_MIN_CC 35)
91+
set(CUDA_MAX_CC 86)
92+
elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 11)
93+
set(CUDA_MIN_CC 35)
94+
set(CUDA_MAX_CC 80)
95+
elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 10)
96+
set(CUDA_MIN_CC 30)
97+
set(CUDA_MAX_CC 75)
98+
elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 9)
99+
set(CUDA_MIN_CC 30)
100+
set(CUDA_MAX_CC 72)
101+
elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 8)
102+
set(CUDA_MIN_CC 20)
103+
set(CUDA_MAX_CC 62)
104+
elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 7)
105+
set(CUDA_MIN_CC 20)
106+
set(CUDA_MAX_CC 53)
107+
else()
108+
message(FATAL_ERROR "We do not support a CUDA SDK below version 7.0")
109+
endif()
110+
if(${CHOOSE_CUDA_MIN_CC} GREATER ${CUDA_MIN_CC})
111+
set(CUDA_MIN_CC ${CHOOSE_CUDA_MIN_CC})
112+
endif()
113+
114+
set(CC_LIST "")
115+
foreach(CC ${CC_LIST_BY_SYSTEM_PROCESSOR})
116+
if( (${CC} GREATER_EQUAL ${CUDA_MIN_CC}) AND
117+
(${CC} LESS_EQUAL ${CUDA_MAX_CC}) )
118+
list(APPEND CC_LIST ${CC})
119+
endif()
120+
endforeach()
121+
122+
#
123+
# Add all requested CUDA CCs to the command line for offline compilation
124+
#
125+
set(GENCODE_FLAGS "")
126+
list(SORT CC_LIST)
127+
foreach(CC_VERSION ${CC_LIST})
128+
list(APPEND GENCODE_FLAGS "-gencode;arch=compute_${CC_VERSION},code=sm_${CC_VERSION}")
129+
endforeach()
130+
131+
#
132+
# Use the highest request CUDA CC for CUDA JIT compilation
133+
#
134+
list(LENGTH CC_LIST CC_LIST_LEN)
135+
MATH(EXPR CC_LIST_LEN "${CC_LIST_LEN}-1")
136+
list(GET CC_LIST ${CC_LIST_LEN} CC_LIST_LAST)
137+
list(APPEND GENCODE_FLAGS "-gencode;arch=compute_${CC_LIST_LAST},code=compute_${CC_LIST_LAST}")
138+
139+
#
140+
# Two variables are exported to the parent scope. One is passed through the
141+
# environment (CUDA_NVCC_FLAGS), the other is passed by name (SUPPORTED_CC)
142+
#
143+
set(${SUPPORTED_GENCODE_FLAGS} "${GENCODE_FLAGS}" PARENT_SCOPE)
144+
set(${SUPPORTED_CC} "${CC_LIST}" PARENT_SCOPE)
145+
endfunction()
146+
147+
#
148+
# Return the gencode parameters for a given list of CCs.
149+
#
150+
# Usage:
151+
# getFlagsForCudaCCList(INPUT_CC_LIST SUPPORTED_GENCODE_FLAGS)
152+
#
153+
# INPUT_CC_LIST in variable. Contains a list of supported CCs.
154+
# SUPPORTED_GENCODE_FLAGS out variable. List of gencode flags to append to, e.g., CUDA_NVCC_FLAGS
155+
#
156+
function(getFlagsForCudaCCList INPUT_CC_LIST SUPPORTED_GENCODE_FLAGS)
157+
set(CC_LIST "${${INPUT_CC_LIST}}")
158+
159+
#
160+
# Add all requested CUDA CCs to the command line for offline compilation
161+
#
162+
set(GENCODE_FLAGS "")
163+
list(SORT CC_LIST)
164+
foreach(CC_VERSION ${CC_LIST})
165+
list(APPEND GENCODE_FLAGS "-gencode;arch=compute_${CC_VERSION},code=sm_${CC_VERSION}")
166+
endforeach()
167+
168+
#
169+
# Use the highest request CUDA CC for CUDA JIT compilation
170+
#
171+
list(LENGTH CC_LIST CC_LIST_LEN)
172+
MATH(EXPR CC_LIST_LEN "${CC_LIST_LEN}-1")
173+
list(GET CC_LIST ${CC_LIST_LEN} CC_LIST_LAST)
174+
list(APPEND GENCODE_FLAGS "-gencode;arch=compute_${CC_LIST_LAST},code=compute_${CC_LIST_LAST}")
175+
176+
message(STATUS "Setting gencode flags: ${GENCODE_FLAGS}")
177+
178+
#
179+
# Two variables are exported to the parent scope. One is passed through the
180+
# environment (CUDA_NVCC_FLAGS), the other is passed by name (SUPPORTED_CC)
181+
#
182+
set(${SUPPORTED_GENCODE_FLAGS} "${GENCODE_FLAGS}" PARENT_SCOPE)
183+
endfunction()
184+

0 commit comments

Comments
 (0)