Skip to content

Commit 1a6c800

Browse files
committed
Added cuda dev workflow
1 parent 9af6589 commit 1a6c800

File tree

5 files changed

+297
-14
lines changed

5 files changed

+297
-14
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Install Windows Dependencies with CUDA'
2+
description: 'Installs PCL, Qt, VTK, g2o and others'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Set up MSVC Developer Command Prompt
7+
uses: ilammy/msvc-dev-cmd@v1
8+
with:
9+
arch: x64
10+
11+
- name: Install CUDA
12+
uses: Jimver/cuda-toolkit@v0.2.30
13+
id: cuda-toolkit
14+
with:
15+
cuda: '13.0.0'
16+
cudnn: '9.x'
17+
18+
- name: Verify CUDA
19+
shell: bash
20+
run: |
21+
nvcc --version
22+
echo "CUDA Path: $CUDA_PATH"
23+
24+
- name: Cache vcpkg
25+
id: cache-vcpkg
26+
uses: actions/cache@v4
27+
with:
28+
path: ${{ runner.workspace }}/vcpkg_installed
29+
key: ${{ runner.os }}-vcpkg-export-66c0373d-x64-vs2022-cuda
30+
31+
- name: Download and Install vcpkg
32+
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
33+
shell: pwsh
34+
run: |
35+
$install_dir = "${{ runner.workspace }}\vcpkg_installed"
36+
$archivePath = "${{ runner.workspace }}\vcpkg-export.7z"
37+
38+
# The file has been built locally with bundle-windows-deps.bat
39+
$url = "https://github.com/introlab/rtabmap/releases/download/0.23.1/vcpkg-export-66c0373d-x64-vs2022-cuda.7z"
40+
41+
Invoke-WebRequest -Uri $url -OutFile $archivePath
42+
& 7z x $archivePath "-o$install_dir" -y
43+
44+
- name: Add vcpkg to PATH and env variable
45+
shell: pwsh
46+
run: |
47+
$vcpkg_path = "${{ runner.workspace }}\vcpkg_installed"
48+
echo "VCPKG_EXPORT_PATH=$vcpkg_path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
49+
echo "$vcpkg_path\installed\x64-windows-release\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
50+
echo "${{env.CUDA_PATH}}\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
51+
echo "${{env.CUDA_PATH}}\extras\CUPTI\lib64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
52+
echo "$vcpkg_path\installed\x64-windows-release\tools\python3\Lib\site-packages\torch\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Cleanup PR Artifacts
2+
on:
3+
pull_request:
4+
types: [closed]
5+
6+
jobs:
7+
delete-artifacts:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
actions: write
11+
steps:
12+
- name: Delete PR Artifacts
13+
uses: geekyeggo/delete-artifact@v5
14+
with:
15+
name: build-output-*

.github/workflows/cmake.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,40 @@ concurrency:
1717

1818
jobs:
1919
build:
20-
name: ${{ matrix.os }}
20+
name: ${{ matrix.build_name }}
2121
runs-on: ${{ matrix.os }}
2222
strategy:
2323
fail-fast: true
2424
matrix:
25-
os: [ubuntu-24.04, ubuntu-22.04, windows-2022]
25+
build_name: [ubuntu-24.04, ubuntu-22.04, windows-2022, windows-2022-cuda]
2626
include:
27-
- os: ubuntu-22.04
27+
- build_name: ubuntu-22.04
28+
os: ubuntu-22.04
2829
extra_deps: "libunwind-dev libceres-dev"
2930
extra_cmake_def: ""
30-
- os: ubuntu-24.04
31+
- build_name: ubuntu-24.04
32+
os: ubuntu-24.04
3133
extra_deps: "libg2o-dev libceres-dev"
3234
extra_cmake_def: "-DWITH_CERES=ON"
33-
- os: windows-2022
35+
- build_name: windows-2022
36+
os: windows-2022
3437
extra_deps: ""
35-
extra_cmake_def: '-DBUILD_AS_BUNDLE=ON -DWITH_PYTHON=ON'
38+
extra_cmake_def: '-DBUILD_AS_BUNDLE=ON -DWITH_PYTHON=ON -DWITH_TORCH=OFF'
39+
- build_name: windows-2022-cuda
40+
os: windows-2022
41+
extra_deps: ""
42+
extra_cmake_def: '-DBUILD_AS_BUNDLE=ON -DWITH_PYTHON=ON -DWITH_TORCH=ON'
3643

3744
steps:
3845
- uses: actions/checkout@v4
3946

4047
- name: Install Windows Dependencies
41-
if: matrix.os == 'windows-2022'
48+
if: matrix.build_name == 'windows-2022'
4249
uses: ./.github/actions/install-windows-deps
50+
51+
- name: Install Windows Dependencies with CUDA
52+
if: matrix.build_name == 'windows-2022-cuda'
53+
uses: ./.github/actions/install-windows-cuda-deps
4354

4455
- name: Install Linux Dependencies
4556
if: matrix.os != 'windows-2022'
@@ -58,7 +69,8 @@ jobs:
5869
-DVCPKG_MANIFEST_INSTALL=OFF `
5970
-DVCPKG_TARGET_TRIPLET=x64-windows-release `
6071
-DVCPKG_INSTALLED_DIR="${{env.VCPKG_EXPORT_PATH}}/installed" `
61-
-DCMAKE_TOOLCHAIN_FILE=${{env.VCPKG_EXPORT_PATH}}/scripts/buildsystems/vcpkg.cmake
72+
-DCMAKE_TOOLCHAIN_FILE=${{env.VCPKG_EXPORT_PATH}}/scripts/buildsystems/vcpkg.cmake `
73+
-DTorch_DIR=${{env.VCPKG_EXPORT_PATH}}/installed/x64-windows-release/tools/python3/Lib/site-packages/torch/share/cmake/Torch
6274
6375
- name: Configure CMake
6476
if: matrix.os != 'windows-2022'
@@ -84,6 +96,7 @@ jobs:
8496
name: RTABMap-Binaries # Give your artifact a recognizable name
8597
path: build/RTABMap-* # Supports wildcards for files and directories
8698
if-no-files-found: warn # Optional: warn, error, or ignore
99+
retention-days: ${{ github.event_name == 'pull_request' && 1 || 90 }}
87100

88101
# - name: Test
89102
# working-directory: ${{github.workspace}}/build

bundle_windows_deps.bat

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ for /d %%i in ("%EXPORT_DIR%\vcpkg-export-*") do set "FINAL_EXPORT_PATH=%%i"
5959
ren "%FINAL_EXPORT_PATH%" "%TARGET_NAME%" || exit /b %errorlevel%
6060
set "FINAL_EXPORT_PATH=%TARGET_FULL_PATH%"
6161

62+
:: We install numpy<2 to be compatible with SuperPoint and SuperGlue scripts
6263
%FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe -m ensurepip --upgrade || exit /b %errorlevel%
6364
%FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe -m pip install "numpy<2" || exit /b %errorlevel%
64-
:: %FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe -m pip install torch torchvision opencv-python-headless "numpy<2" || exit /b %errorlevel%
6565

6666
:: 4. Other dependencies not in vcpkg
6767
:: libnabo
@@ -76,7 +76,7 @@ if not exist libnabo (
7676
cd ..
7777
)
7878
cd libnabo
79-
cmake -S . -B build ^
79+
cmake -S . -B build -GNinja ^
8080
-DVCPKG_MANIFEST_INSTALL=OFF ^
8181
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
8282
-DVCPKG_INSTALLED_DIR="%FINAL_EXPORT_PATH%\installed" ^
@@ -103,7 +103,7 @@ if not exist libpointmatcher (
103103
cd ..
104104
)
105105
cd libpointmatcher
106-
cmake -S . -B build ^
106+
cmake -S . -B build -GNinja ^
107107
-DVCPKG_MANIFEST_INSTALL=OFF ^
108108
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
109109
-DVCPKG_INSTALLED_DIR="%FINAL_EXPORT_PATH%\installed" ^
@@ -136,12 +136,13 @@ if not exist gtsam (
136136
cd ..
137137
)
138138
cd gtsam
139-
cmake -S . -B build ^
139+
cmake -S . -B build -GNinja ^
140140
-DVCPKG_MANIFEST_INSTALL=OFF ^
141141
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
142142
-DVCPKG_INSTALLED_DIR="%FINAL_EXPORT_PATH%\installed" ^
143143
-DCMAKE_TOOLCHAIN_FILE="%FINAL_EXPORT_PATH%\scripts\buildsystems\vcpkg.cmake" ^
144144
-DCMAKE_INSTALL_PREFIX="%FINAL_EXPORT_PATH%\installed\%TRIPLET%" ^
145+
-DCMAKE_BUILD_TYPE=Release ^
145146
-DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF ^
146147
-DGTSAM_BUILD_TESTS=OFF ^
147148
-DGTSAM_BUILD_UNSTABLE=OFF ^
@@ -166,7 +167,7 @@ if not exist opengv (
166167
cd ..
167168
)
168169
cd opengv
169-
cmake -S . -B build ^
170+
cmake -S . -B build -GNinja ^
170171
-DVCPKG_MANIFEST_INSTALL=OFF ^
171172
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
172173
-DVCPKG_INSTALLED_DIR="%FINAL_EXPORT_PATH%\installed" ^
@@ -194,4 +195,29 @@ if %ERRORLEVEL% EQU 0 (
194195
echo [!] Success! Package created at %FINAL_ZIP%
195196
) else (
196197
echo [X] 7-Zip failed with error code %ERRORLEVEL%
197-
)
198+
)
199+
200+
201+
:: Example building rtabmap afterwards
202+
goto :EndComment
203+
204+
set VCPKG_UNZIPPED_EXPORT_PATH=%USERPROFILE%\Downloads\vcpkg-export-########-x64-vs2022
205+
set PATH=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\bin;%PATH%
206+
207+
cmake -B build -GNinja ^
208+
-DCMAKE_BUILD_TYPE=Release ^
209+
-DBUILD_AS_BUNDLE=ON -DWITH_PYTHON=ON ^
210+
-DWITH_ZED=OFF ^
211+
-DVCPKG_MANIFEST_INSTALL=OFF ^
212+
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
213+
-DVCPKG_INSTALLED_DIR="%VCPKG_UNZIPPED_EXPORT_PATH%/installed" ^
214+
-DCMAKE_TOOLCHAIN_FILE=%VCPKG_UNZIPPED_EXPORT_PATH%/scripts/buildsystems/vcpkg.cmake ^
215+
-DGTSAM_DIR=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\CMake
216+
217+
cmake --build build --config Release --target package
218+
219+
:: To install CPU pytorch inside rtabmap package afterwards.
220+
:: Note that python.exe is the one in the bin directory of the package, not the system one.
221+
python.exe -m pip install torch torchvision opencv-python-headless "numpy<2"
222+
223+
:EndComment

bundle_windows_deps_cuda.bat

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
:: CUDA Toolkit should be manually installed on the computer before running this script
5+
:: We assume also that cuDNN is merged into CUDA installed directory.
6+
where nvcc >nul 2>&1
7+
if !errorlevel! neq 0 (
8+
echo [ERROR] nvcc was not found in your PATH.
9+
pause
10+
exit /b
11+
)
12+
for /f "tokens=5" %%a in ('nvcc --version ^| findstr "release"') do (
13+
set "RAW_VER=%%a"
14+
:: This removes the trailing comma
15+
set "CUDA_VER=!RAW_VER:,=!"
16+
set "CUDA_VER_SHORT=!CUDA_VER:.=!"
17+
)
18+
if "!CUDA_VER!"=="" (
19+
echo [ERROR] Could not parse CUDA version.
20+
pause
21+
exit /b
22+
)
23+
echo Installed CUDA Toolkit: %CUDA_VER%
24+
25+
:: --- CONFIGURATION ---
26+
set "VCPKG_ROOT=%~dp0vcpkg"
27+
set "EXPORT_DIR=%~dp0vcpkg_binaries"
28+
set "TRIPLET=x64-windows-release"
29+
set "SEVENZIP_EXE=C:\Program Files\7-Zip\7z.exe"
30+
31+
set "VCPKG_JSON=%~dp0vcpkg.json"
32+
for /f "usebackq tokens=*" %%a in (`powershell -NoProfile -Command "(Get-Content '%VCPKG_JSON%' -Raw | ConvertFrom-Json).'builtin-baseline'"` ) do set "VCPKG_COMMIT=%%a"
33+
34+
if "%VCPKG_COMMIT%"=="" (
35+
echo [X] Error: Could not find 'builtin-baseline' in %VCPKG_JSON%
36+
pause
37+
exit /b 1
38+
)
39+
40+
set VCPKG_COMMIT_SHORT=%VCPKG_COMMIT:~0,8%
41+
set "VS_LOCATOR=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
42+
for /f "usebackq tokens=*" %%i in (`"%VS_LOCATOR%" -latest -property catalog_productLineVersion`) do set VS_YEAR=vs%%i
43+
set ORG_TARGET_NAME=vcpkg-export-%VCPKG_COMMIT_SHORT%-x64-%VS_YEAR%
44+
set TARGET_NAME=%ORG_TARGET_NAME%-cuda%CUDA_VER_SHORT%
45+
set VCPKG_EXPORT_PATH=%EXPORT_DIR%\%ORG_TARGET_NAME%
46+
set FINAL_EXPORT_PATH=%EXPORT_DIR%\%TARGET_NAME%
47+
48+
if not exist "%FINAL_EXPORT_PATH%" (
49+
if not exist "%VCPKG_EXPORT_PATH%" (
50+
call bundle_windows_deps.bat || exit /b %errorlevel%
51+
)
52+
echo [+] Copying %VCPKG_EXPORT_PATH% to %FINAL_EXPORT_PATH%
53+
xcopy "%VCPKG_EXPORT_PATH%" "%FINAL_EXPORT_PATH%\" /E /I /H /Y /Q || exit /b %errorlevel%
54+
echo [+] Remove opencv built by vcpkg
55+
rmdir /s /q "%FINAL_EXPORT_PATH%\installed\%TRIPLET%\include\opencv4" || exit /b %errorlevel%
56+
rmdir /s /q "%FINAL_EXPORT_PATH%\installed\%TRIPLET%\share\opencv4" || exit /b %errorlevel%
57+
rmdir /s /q "%FINAL_EXPORT_PATH%\installed\%TRIPLET%\share\opencv" || exit /b %errorlevel%
58+
del "%FINAL_EXPORT_PATH%\installed\%TRIPLET%\bin\opencv*" || exit /b %errorlevel%
59+
del "%FINAL_EXPORT_PATH%\installed\%TRIPLET%\lib\opencv*" || exit /b %errorlevel%
60+
)
61+
62+
:: pytorch deps
63+
%FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe -m pip install numpy packaging "cmake<4" setuptools pyyaml typing_extensions
64+
65+
:: pytorch, build with local cuda libraries to avoid duplicating them when we install rtabmap
66+
echo [+] Building pytorch with cuda support...
67+
if not exist pytorch (
68+
echo [+] Downloading pytorch...
69+
git config --global core.longpaths true
70+
git clone https://github.com/pytorch/pytorch || exit /b %errorlevel%
71+
cd pytorch
72+
:: Jan 21, 2026
73+
git checkout v2.10.0
74+
git submodule update --init --recursive || exit /b %errorlevel%
75+
cd ..
76+
)
77+
78+
cd pytorch
79+
set CMAKE_GENERATOR=Ninja
80+
set Python_ROOT_DIR=%FINAL_EXPORT_PATH%\installed\x64-windows-release
81+
set PYTHONHOME=%FINAL_EXPORT_PATH%\installed\x64-windows-release\tools\python3
82+
set BUILD_TEST=0
83+
set LIB="%LIB%;%FINAL_EXPORT_PATH%\installed\x64-windows-release\lib"
84+
set INCLUDE="%INCLUDE%;%FINAL_EXPORT_PATH%\installed\x64-windows-release\include"
85+
%FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe setup.py install || exit /b %errorlevel%
86+
cd ..
87+
88+
:: opencv_cuda
89+
echo [+] Building opencv with cuda support...
90+
if not exist opencv (
91+
echo [+] Downloading opencv...
92+
git clone https://github.com/opencv/opencv.git || exit /b %errorlevel%
93+
cd opencv
94+
:: 4.13.0 minimum required to be compatible with cuda 13
95+
:: Dec 31, 2025
96+
git checkout 4.13.0
97+
cd ..
98+
)
99+
if not exist opencv_contrib (
100+
echo [+] Downloading opencv_contrib...
101+
git clone https://github.com/opencv/opencv_contrib.git || exit /b %errorlevel%
102+
cd opencv
103+
:: 4.13.0 minimum required to be compatible with cuda 13
104+
:: Dec 31, 2025
105+
git checkout 4.13.0
106+
cd ..
107+
)
108+
cd opencv
109+
cmake -S . -B build -GNinja ^
110+
-DVCPKG_MANIFEST_INSTALL=OFF ^
111+
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
112+
-DVCPKG_INSTALLED_DIR="%FINAL_EXPORT_PATH%\installed" ^
113+
-DCMAKE_TOOLCHAIN_FILE="%FINAL_EXPORT_PATH%\scripts\buildsystems\vcpkg.cmake" ^
114+
-DCMAKE_INSTALL_PREFIX="%FINAL_EXPORT_PATH%\installed\%TRIPLET%" ^
115+
-DCMAKE_BUILD_TYPE=Release ^
116+
-DOPENCV_BIN_INSTALL_PATH="bin" ^
117+
-DOPENCV_LIB_INSTALL_PATH="lib" ^
118+
-DOPENCV_CONFIG_INSTALL_PATH="share/opencv" ^
119+
-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ^
120+
-DBUILD_SHARED_LIBS=ON ^
121+
-DBUILD_TESTS=OFF ^
122+
-DBUILD_PERF_TESTS=OFF ^
123+
-DOPENCV_ENABLE_NONFREE=ON ^
124+
-DBUILD_opencv_apps=OFF ^
125+
-DBUILD_opencv_python3=ON ^
126+
-DPYTHON_EXECUTABLE=%FINAL_EXPORT_PATH%/installed/%TRIPLET%/tools/python3/python.exe ^
127+
-DBUILD_opencv_java_bindings_generator=OFF ^
128+
-DWITH_CUDA=ON ^
129+
-DWITH_TBB=ON || exit /b %errorlevel%
130+
cmake --build build --config Release --target install || exit /b %errorlevel%
131+
cd ..
132+
133+
134+
:: 5. ZIP the folder
135+
echo [+] Creating final package with 7-Zip...
136+
:: Rip off pdb files
137+
cd /d "%FINAL_EXPORT_PATH%"
138+
del /s /q /f *.pdb >nul 2>&1
139+
140+
cd ..
141+
142+
set "FINAL_ZIP=%TARGET_NAME%.7z"
143+
144+
:: compress contents without the root folder
145+
"%SEVENZIP_EXE%" u -t7z -mx9 "%FINAL_ZIP%" "%FINAL_EXPORT_PATH%\*" -up0q0
146+
147+
if %ERRORLEVEL% EQU 0 (
148+
echo [!] Success! Package created at %FINAL_ZIP%
149+
) else (
150+
echo [X] 7-Zip failed with error code %ERRORLEVEL%
151+
)
152+
153+
:: Example building rtabmap with opencv cuda and libtorch afterwards
154+
goto :EndComment
155+
156+
set VCPKG_UNZIPPED_EXPORT_PATH=%USERPROFILE%\Downloads\vcpkg-export-########-x64-vs2022-cuda131
157+
set PATH=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\bin;%PATH%
158+
set PATH=%CUDA_PATH%\bin\x64;%PATH%
159+
set PATH=%CUDA_PATH%\extras\CUPTI\lib64;%PATH%
160+
set PATH=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\tools\python3\Lib\site-packages\torch\lib;%PATH%
161+
162+
cmake -B build_cuda -GNinja ^
163+
-DCMAKE_BUILD_TYPE=Release ^
164+
-DBUILD_AS_BUNDLE=ON ^
165+
-DWITH_PYTHON=ON ^
166+
-DWITH_TORCH=ON ^
167+
-DWITH_ZED=ON ^
168+
-DVCPKG_MANIFEST_INSTALL=OFF ^
169+
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
170+
-DVCPKG_INSTALLED_DIR="%VCPKG_UNZIPPED_EXPORT_PATH%/installed" ^
171+
-DCMAKE_TOOLCHAIN_FILE=%VCPKG_UNZIPPED_EXPORT_PATH%/scripts/buildsystems/vcpkg.cmake ^
172+
-DGTSAM_DIR=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\CMake ^
173+
-DTorch_DIR=%VCPKG_UNZIPPED_EXPORT_PATH%\installed\x64-windows-release\tools\python3\Lib\site-packages\torch\share\cmake\Torch
174+
175+
cmake --build build_cuda --config Release --target package
176+
177+
:EndComment

0 commit comments

Comments
 (0)