Skip to content

Commit bdd37e5

Browse files
authored
Merge pull request #156 from alicevision/dev/cmake-lang-cuda
Update to Continuous integration and CMake/CUDA
2 parents 4b4b247 + a6f8113 commit bdd37e5

24 files changed

+187
-386
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
container: ["alicevision/popsift-deps:cuda10.2-ubuntu18.04", "alicevision/popsift-deps:cuda11.8.0-ubuntu20.04", "alicevision/popsift-deps:cuda12.1.0-ubuntu22.04"]
24+
container: ["alicevision/popsift-deps:cuda11.8.0-ubuntu20.04", "alicevision/popsift-deps:cuda12.1.0-ubuntu22.04"]
2525
build_tpe: ["Release", "Debug"]
2626
exclude:
2727
# excludes debug on this one as it has a segmentation fault during the compilation (!)
28-
- container: "alicevision/popsift-deps:cuda12.1.0-ubuntu22.04"
28+
- container: "alicevision/popsift-deps:cuda11.8.0-ubuntu20.04"
2929
build_tpe: "Debug"
3030

3131
container:

.travis.yml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dist: xenial
1+
dist: jammy
22

33
language: cpp
44
compiler: gcc
@@ -13,10 +13,8 @@ addons:
1313

1414
env:
1515
matrix:
16-
- CUDA_VERSION_MAJOR="8" CUDA_VERSION_MINOR="0" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.61-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
17-
- CUDA_VERSION_MAJOR="9" CUDA_VERSION_MINOR="2" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.148-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
18-
- CUDA_VERSION_MAJOR="10" CUDA_VERSION_MINOR="2" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.89-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
19-
- CUDA_VERSION_MAJOR="11" CUDA_VERSION_MINOR="0" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.2-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
16+
- CUDA_VERSION_MAJOR="11" CUDA_VERSION_MINOR="8" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.0-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
17+
- CUDA_VERSION_MAJOR="12" CUDA_VERSION_MINOR="5" CUDA_PKG_LONGVERSION="${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}.1-1" CUDA_PKG_VERSION="${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}"
2018

2119

2220
global:
@@ -34,7 +32,7 @@ env:
3432
- POPSIFT_APP_INSTALL_RELEASE=${POPSIFT_APP_BUILD_RELEASE}/install
3533
- POPSIFT_APP_INSTALL_DEBUG=${POPSIFT_APP_BUILD_DEBUG}/install
3634
# CMAKE
37-
- CMAKE_URL="https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz"
35+
- CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz"
3836
- CMAKE_ROOT=${TRAVIS_BUILD_DIR}/cmake
3937
- CMAKE_SOURCE=${CMAKE_ROOT}/source
4038
- CMAKE_INSTALL=${CMAKE_ROOT}/install
@@ -57,30 +55,12 @@ before_install:
5755
fi
5856
5957
install:
60-
- UBUNTU_VERSION=ubuntu1604
61-
- >
62-
if [ ${CUDA_VERSION_MAJOR} -lt 11 ]; then
63-
CUDA_REPO_PKG=cuda-repo-${UBUNTU_VERSION}_${CUDA_PKG_LONGVERSION}_amd64.deb
64-
wget http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/$CUDA_REPO_PKG
65-
travis_retry sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/7fa2af80.pub
66-
sudo dpkg -i $CUDA_REPO_PKG
67-
rm ${CUDA_REPO_PKG}
68-
travis_retry sudo apt-get -y update
69-
# cuda > 10.0 changed cublas naming
70-
if [ ${CUDA_VERSION_MAJOR} -lt 10 ]; then
71-
CUBLAS_PKG=cuda-cublas-dev-$CUDA_PKG_VERSION
72-
else
73-
CUBLAS_PKG=libcublas-dev
74-
fi
75-
travis_retry sudo apt-get install -y --no-install-recommends --allow-unauthenticated cuda-core-$CUDA_PKG_VERSION cuda-cudart-dev-$CUDA_PKG_VERSION ${CUBLAS_PKG} cuda-curand-dev-$CUDA_PKG_VERSION
76-
sudo ln -s /usr/local/cuda-${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} /usr/local/cuda
77-
else
78-
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-ubuntu1604.pin
79-
travis_retry sudo mv cuda-ubuntu1604.pin /etc/apt/preferences.d/cuda-repository-pin-600
80-
travis_retry sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
81-
travis_retry sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/ /"
82-
sudo apt-get update && sudo apt-get -y install cuda
83-
fi
58+
- UBUNTU_VERSION=ubuntu2204
59+
- wget https://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/cuda-${UBUNTU_VERSION}.pin
60+
- travis_retry sudo mv cuda-${UBUNTU_VERSION}.pin /etc/apt/preferences.d/cuda-repository-pin-600
61+
- travis_retry sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/3bf863cc.pub
62+
- travis_retry sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/ /"
63+
- sudo apt-get update && sudo apt-get -y install cuda
8464
# - CUDA_REPO_PKG=cuda-repo-${UBUNTU_VERSION}_${CUDA_PKG_LONGVERSION}_amd64.deb
8565
# - wget http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/$CUDA_REPO_PKG
8666

@@ -131,3 +111,4 @@ cache:
131111
apt: true
132112
directories:
133113
- ${CMAKE_INSTALL}
114+

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
## [1.0.0] - YYYY-MM-DD
1919

20+
## 2024
21+
22+
- CMake: CUDA as first-order language, different CC selection
23+
2024
### Added
2125
- Improved checks for CUDA textures [PR](https://github.com/alicevision/popsift/pull/89)
2226
- CMake: Improved support for all Cuda CC [PR](https://github.com/alicevision/popsift/pull/75)

CMakeLists.txt

Lines changed: 35 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
# CMake below 3.4 does not work with CUDA separable compilation at all
2-
cmake_minimum_required(VERSION 3.12)
1+
# First-order language CUDA requires at least CMake 3.18
2+
cmake_minimum_required(VERSION 3.24)
33

4-
project(PopSift VERSION 1.0.0 LANGUAGES CXX)
4+
project(PopSift VERSION 1.0.0 LANGUAGES CXX CUDA)
5+
6+
# Policy to support CUDA as a first-order language for CMake.
7+
# Since CMake 3.18. See https://cmake.org/cmake/help/latest/policy/CMP0104.html
8+
cmake_policy(SET CMP0104 NEW)
9+
10+
set(CMAKE_CUDA_ARCHITECTURES "all-major"
11+
CACHE
12+
STRING "Which CUDA CCs to support: native, all, all-major or an explicit list delimited by semicolons"
13+
FORCE)
514

615
# Set build path as a folder named as the platform (linux, windows, darwin...) plus the processor type
716
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
@@ -16,7 +25,6 @@ option(PopSift_USE_GRID_FILTER "Switch off grid filtering to massively reduce co
1625
option(PopSift_USE_NORMF "The __normf function computes Euclidean distance on large arrays. Fast but stability is uncertain." OFF)
1726
option(PopSift_NVCC_WARNINGS "Switch on several additional warning for CUDA nvcc" OFF)
1827
option(PopSift_USE_TEST_CMD "Add testing step for functional verification" OFF)
19-
option(PopSift_NO_DEPRECATED_CUDA_SM_WARNINGS "Suppress warnings about soon to be deprecated cuda SM" ON)
2028
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2129

2230
if(PopSift_USE_POSITION_INDEPENDENT_CODE AND NOT MSVC)
@@ -55,17 +63,15 @@ include(GNUInstallDirs)
5563

5664
if(BUILD_SHARED_LIBS)
5765
message(STATUS "BUILD_SHARED_LIBS ON")
58-
# Need to declare CUDA_USE_STATIC_CUDA_RUNTIME as an option to ensure that it is not overwritten in FindCUDA.
59-
option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF)
60-
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
61-
# Workaround to force deactivation of cuda static runtime for cmake < 3.10
62-
set(CUDA_cudart_static_LIBRARY 0)
66+
6367
# Auto-build dll exports on Windows
6468
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
69+
70+
set(CMAKE_CUDA_RUNTIME_LIBRARY Shared)
6571
else()
6672
message(STATUS "BUILD_SHARED_LIBS OFF")
67-
option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON)
68-
set(CUDA_USE_STATIC_CUDA_RUNTIME ON)
73+
74+
set(CMAKE_CUDA_RUNTIME_LIBRARY Static)
6975
endif()
7076

7177
# Require threads because of std::thread.
@@ -74,26 +80,15 @@ find_package(Threads REQUIRED)
7480
###################
7581
# CUDA
7682
###################
77-
find_package(CUDA 7.0 REQUIRED)
83+
include(CheckLanguage)
84+
check_language(CUDA)
7885

79-
if(NOT CUDA_FOUND)
80-
message(FATAL_ERROR "Could not find CUDA >= 7.0")
81-
endif()
86+
# Use this if necessary: "cmake -DCUDAToolkit_ROOT=/some/path"
87+
# target_link_libraries(binary_linking_to_cudart PRIVATE CUDA::cudart)
88+
find_package(CUDAToolkit)
8289

83-
message(STATUS "CUDA Version is ${CUDA_VERSION}")
84-
85-
include(ChooseCudaCC)
86-
if(NOT DEFINED PopSift_CUDA_CC_LIST)
87-
chooseCudaCC(PopSift_CUDA_CC_LIST_BASIC
88-
PopSift_CUDA_GENCODE_FLAGS
89-
MIN_CC 30
90-
MIN_CUDA_VERSION 7.0)
91-
set(PopSift_CUDA_CC_LIST ${PopSift_CUDA_CC_LIST_BASIC} CACHE STRING "CUDA CC versions to compile")
92-
else()
93-
getFlagsForCudaCCList(PopSift_CUDA_CC_LIST
94-
PopSift_CUDA_GENCODE_FLAGS)
95-
endif()
96-
list(APPEND CUDA_NVCC_FLAGS "${PopSift_CUDA_GENCODE_FLAGS}")
90+
message(STATUS "CUDA Version is ${CUDAToolkit_VERSION}")
91+
set(CUDA_VERSION ${CUDAToolkit_VERSION})
9792

9893
if(PopSift_USE_NVTX_PROFILING)
9994
message(STATUS "PROFILING CPU CODE: NVTX is in use")
@@ -104,46 +99,8 @@ if(PopSift_ERRCHK_AFTER_KERNEL)
10499
list(APPEND CUDA_NVCC_FLAGS "-DERRCHK_AFTER_KERNEL")
105100
endif()
106101

107-
set(CUDA_SEPARABLE_COMPILATION ON)
108-
109-
if(PopSift_NO_DEPRECATED_CUDA_SM_WARNINGS)
110-
list(APPEND CUDA_NVCC_FLAGS "-Wno-deprecated-gpu-targets")
111-
endif()
112-
113-
if(UNIX AND NOT APPLE)
114-
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler;-rdynamic")
115-
# set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xptxas;-v")
116-
# set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xptxas;-warn-double-usage")
117-
list(APPEND CUDA_NVCC_FLAGS_DEBUG "--keep")
118-
list(APPEND CUDA_NVCC_FLAGS_DEBUG "--source-in-ptx")
119-
endif()
120-
121-
# The following if should not be necessary, but apparently there is a bug in FindCUDA.cmake that
122-
# generate an empty string in the nvcc command line causing the compilation to fail.
123-
# see https://gitlab.kitware.com/cmake/cmake/issues/16411
124-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
125-
message(STATUS "Building in debug mode")
126-
list(APPEND CUDA_NVCC_FLAGS_DEBUG "-G")
127-
endif()
128-
list(APPEND CUDA_NVCC_FLAGS_RELEASE "-O3")
129-
130-
if(PopSift_USE_POSITION_INDEPENDENT_CODE AND NOT MSVC)
131-
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler;-fPIC")
132-
endif()
133-
134-
# this is to ensure that on MSVC the flags for the linker are properly propagate even to the intermediate
135-
# linking step. This seems not the case e.g. on vcpkg using ninja build.
136-
if(MSVC)
137-
if(BUILD_SHARED_LIBS)
138-
set(PopSift_MVSC_LINKER "/MD")
139-
else()
140-
set(PopSift_MVSC_LINKER "/MT")
141-
endif()
142-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
143-
set(PopSift_MVSC_LINKER "${PopSift_MVSC_LINKER}d")
144-
endif()
145-
list(APPEND CUDA_NVCC_FLAGS -Xcompiler ${PopSift_MVSC_LINKER})
146-
endif()
102+
# This may not be required any more.
103+
set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
147104

148105
# default stream per-thread implies that each host thread has one non-synchronizing 0-stream
149106
# currently, the code requires legacy mode
@@ -159,7 +116,7 @@ if(CUDA_VERSION VERSION_GREATER_EQUAL "7.5")
159116
endif()
160117
endif()
161118

162-
set(PopSift_CXX_STANDARD 14) # Thrust/CUB requires C++14 starting with CUDA SDK 11
119+
set(PopSift_CXX_STANDARD 17) # Thrust/CUB requires C++14 starting with CUDA SDK 11
163120
if(CUDA_VERSION_MAJOR LESS_EQUAL 8)
164121
set(PopSift_CXX_STANDARD 11)
165122
endif()
@@ -181,9 +138,9 @@ else()
181138
endif()
182139

183140
if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0")
184-
set(HAVE_SHFL_DOWN_SYNC 1)
141+
set(PopSift_HAVE_SHFL_DOWN_SYNC 1)
185142
else()
186-
set(HAVE_SHFL_DOWN_SYNC 0)
143+
set(PopSift_HAVE_SHFL_DOWN_SYNC 0)
187144
endif()
188145

189146
if(NOT PopSift_USE_GRID_FILTER)
@@ -193,12 +150,8 @@ else()
193150
set(DISABLE_GRID_FILTER 0)
194151
endif()
195152

196-
# library required for CUDA dynamic parallelism, forgotten by CMake 3.4
197-
cuda_find_library_local_first(CUDA_CUDADEVRT_LIBRARY cudadevrt "\"cudadevrt\" library")
198-
199153
if(PopSift_USE_NVTX_PROFILING)
200154
# library required for NVTX profiling of the CPU
201-
cuda_find_library_local_first(CUDA_NVTX_LIBRARY nvToolsExt "NVTX library")
202155
set(PopSift_USE_NVTX 1)
203156
else()
204157
set(PopSift_USE_NVTX 0)
@@ -245,9 +198,14 @@ message(STATUS "Use CUDA NVTX for profiling: " ${PopSift_USE_NVTX_PROFILING})
245198
message(STATUS "Synchronize and check CUDA error after every kernel: " ${PopSift_ERRCHK_AFTER_KERNEL})
246199
message(STATUS "Grid filtering: " ${PopSift_USE_GRID_FILTER})
247200
message(STATUS "Additional warning for CUDA nvcc: " ${PopSift_NVCC_WARNINGS})
248-
message(STATUS "Compiling for CUDA CCs: ${PopSift_CUDA_CC_LIST}")
249201
message(STATUS "Install path: " ${CMAKE_INSTALL_PREFIX})
250202
message(STATUS "Testing step: " ${PopSift_USE_TEST_CMD})
203+
204+
message(STATUS "CMAKE_CUDA_COMPILER = ${CMAKE_CUDA_COMPILER}")
205+
message(STATUS "CMAKE_CUDA_COMPILER_ID = ${CMAKE_CUDA_COMPILER_ID}")
206+
message(STATUS "CMAKE_CUDA_COMPILER_VERSION = ${CMAKE_CUDA_COMPILER_VERSION}")
207+
message(STATUS "CMAKE_CUDA_ARCHITECTURES = ${CMAKE_CUDA_ARCHITECTURES}")
208+
251209
if(PopSift_USE_TEST_CMD)
252210
message(STATUS "Path for test input: " ${PopSift_TESTFILE_PATH})
253211
endif()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ PopSift depends on:
2525

2626
Optionally, for the provided applications:
2727

28-
* Boost >= 1.55 (required components {atomic, chrono, date-time, system, thread}-dev)
28+
* Boost >= 1.71 (required components {atomic, chrono, date-time, system, thread}-dev)
2929

3030
* DevIL (libdevil-dev) can be used to load a broader range of image formats, otherwise only pgm is supported.
3131

appveyor.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#
2+
# Build system for the PopSift library, including its demo programs.
3+
#
14
version: '1.0.{build}'
25

3-
image: Visual Studio 2015
6+
image: Visual Studio 2022
47

58
platform:
69
- x64
@@ -14,6 +17,9 @@ configuration:
1417
# - DBUILD_SHARED_LIBS: 0
1518
# - DBUILD_SHARED_LIBS: 1
1619

20+
#
21+
# Check the separate file cudaInstallAppveyor for the installation of CUDA
22+
#
1723
install:
1824
- cmd: >-
1925
call cudaInstallAppveyor.cmd
@@ -23,10 +29,22 @@ install:
2329
--triplet %PLATFORM%-windows
2430
# devil
2531

32+
#
33+
# When updating to a new version of visual studio, change the generation string after
34+
# -G and find the suitable toolkit version that is listed after -T (v143 in this case).
35+
# The CUDA Toolkit and the VS version must match. The matches are found in the CUDA
36+
# documentation.
37+
# The platform in this case is x64. Apparently, you need in after -T for VS and after -A
38+
# for CUDA.
39+
# You can only have one -T parameter, but you can separate several options with a comma.
40+
#
41+
# PopSift_USE_GRID_FILTER is off in this build because the installation of CUDA Thrust
42+
# in cudaInstallAppveyor is not happening yet.
43+
#
2644
before_build:
2745
- md build
2846
- cd build
29-
- cmake -G "Visual Studio 14 2015" -A x64 -T v140,host=x64 -DBUILD_SHARED_LIBS=%DBUILD_SHARED_LIBS% -DPopSift_BUILD_DOCS:BOOL=OFF -DPopSift_USE_POSITION_INDEPENDENT_CODE:BOOL=%DBUILD_SHARED_LIBS% -DPopSift_BUILD_EXAMPLES:BOOL=ON -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake ..
47+
- cmake -G "Visual Studio 17 2022" -A x64 -T v143,host=x64,cuda="%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v12.5" -DBUILD_SHARED_LIBS:BOOL=ON -DPopSift_USE_NVTX_PROFILING:BOOL=OFF -DPopSift_USE_GRID_FILTER:BOOL=OFF -DPopSift_BUILD_DOCS:BOOL=OFF -DPopSift_USE_POSITION_INDEPENDENT_CODE:BOOL=ON -DPopSift_BUILD_EXAMPLES:BOOL=ON -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake ..
3048
- ls -l
3149

3250
build:

0 commit comments

Comments
 (0)