8000 Add support for CUDA sparse BA solver by ahojnnes · Pull Request #2717 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for CUDA sparse BA solver #2717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2024
Merged

Add support for CUDA sparse BA solver #2717

merged 4 commits into from
Aug 19, 2024

Conversation

ahojnnes
Copy link
Contributor
@ahojnnes ahojnnes commented Aug 16, 2024

This PR implements enhancement: #2643. It builds upon Ceres' recent CUDA_SPARSE solver type.

Initial experiments show significant runtime improvements. On my machine with an Intel Core i9 10920X and an NVidia RTX 2070, I see a consistent 3x speedup for reconstructions with ~500-5000 images. For smaller problems with ~100 images, the runtime is roughly equivalent. These experiments were done using CUDA 12.5 and cudss 0.3.0.

For now, the feature is disabled by default and requires explicit enabling of the option. This is because no robustness is implemented against situations where the GPU does not have enough memory and some of the thresholds that determine the usage of sparse direct vs. indirect solvers need to be tuned in this new scenario.

@ahojnnes
Copy link
Contributor Author

@S-o-T FYI, since I believe you added this new feature to Ceres.

#if (CERES_VERSION_MAJOR >= 3 || \
(CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 2)) && \
!defined(CERES_NO_CUDSS) && defined(CUDA_ENABLED)
if (options_.use_gpu) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it might be worth experimentation/tuning to find problem size threshold to switch from CPU to GPU sparse backend, although it might be too sensitive to choice between suitesparse/eigen (until mkl sparse backend will be merged to ceres-solver).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the current parameters are not tuned. It will be difficult to find universal thresholds here that generalize across different CPU/GPU models. It was a little easier before, as we switched between algorithms that all run on the CPU. As such, I decided to expose the parameters now explicitly through the option manager for the bundle adjuster and we might need to do the same for the bundle adjustment that runs as part of the mapper. For now, this feature is disabled by default, as I want to gain some more experience with it over the next weeks.

@ahojnnes ahojnnes merged commit d2ee055 into main Aug 19, 2024
16 checks passed
@ahojnnes ahojnnes deleted the user/joschonb/ba-cuda branch August 19, 2024 08:01
@tineras
Copy link
tineras commented Nov 28, 2024

I'm getting the following when trying to use the ba_use_gpu flag:

W20241128 14:23:50.326298 19296 bundle_adjustment.cc:301] Requested to use GPU for bundle adjustment, but Ceres was compiled without CUDA support. Falling back to CPU-based dense solvers. W20241128 14:23:50.326341 19296 bundle_adjustment.cc:320] Requested to use GPU for bundle adjustment, but Ceres was compiled without cuDSS support. Falling back to CPU-based sparse solvers.

The only instance of ceres I know of on my machine is the ceres.dll inside of the colmap/bin folder. I am using CUDA 11.8.

fwiw, nvidia-smi tells me the CUDA version is 12.3

My CUDA_HOME, CUDA_PATH both point to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8

Am I missing something or using this incorrectly?

I am only trying this because I'm getting sudden crashes during bundle adjustment and have tried numerous, known working datasets that never crashed before and now everything I process crashes during BA and I am trying to pinpoint what dependencies on my system might have changed.

@ahojnnes
Copy link
Contributor Author

You need to custom compile the latest Ceres development version with CUDA support. This is not part of the current set of pre compiled colmap binaries.

@tineras
Copy link
tineras commented Nov 28, 2024

You need to custom compile the latest Ceres development version with CUDA support. This is not part of the current set of pre compiled colmap binaries.

Okay, I can certainly do that. I updated my original message, but I'll include it in this reply as well. Sorry to hijack this topic. I'm happy to open a new issues, but was trying to avoid that.

"I am only trying this because I'm getting sudden crashes during bundle adjustment and have tried numerous, known working datasets that never crashed before and now everything I process crashes during BA and I am trying to pinpoint what dependencies on my system might have changed."

Perhaps something in vcpkg from VCPKG_ROOT env variable?

@tineras
Copy link
tineras commented Nov 29, 2024

You need to custom compile the latest Ceres development version with CUDA support. This is not part of the current set of pre compiled colmap binaries.

Looks like ceres is causing the problem for me. I am doing another run now with a ceres dll (with CUDA support) that I built using vcpkg.

Faulting application name: colmap.exe, version: 0.0.0.0, time stamp: 0x67486f74
Faulting module name: ceres.dll, version: 0.0.0.0, time stamp: 0x6739347e
Exception code: 0xc0000005
Fault offset: 0x000000000001748e
Faulting process id: 0x0x39A0
Faulting application start time: 0x0x1DB41FC694ECFF6
Faulting application path: C:\proj\colmap_3_11_0\bin\colmap.exe
Faulting module path: C:\proj\colmap_3_11_0\bin\ceres.dll
Report Id: 699ead97-3e8e-4237-bbe0-3d4161d2b5e8
Faulting package full name:
Faulting package-relative application ID:

@ahojnnes
Copy link
Contributor Author

You'll have to recompile colmap from scratch. You cannot just recompile the ceres.dll and replace it. First of all, the colmap build system will detect CUDA support in ceres at compile and not at runtime. Second, C++ does not have a stable ABI, so you cannot mix and match different compiler or standard library versions. It will be difficult to match the exact combination of OS/compiler/stdlib/etc. on your system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0