Skip to content

Fix empty PatchMatch results on Blackwell GPUs (sm_100+) - #4213

Merged
ahojnnes merged 3 commits into
mainfrom
user/jsch/blackwell-patch-match-cuda-bug
Apr 2, 2026
Merged

ahojnnes merged 3 commits into
mainfrom
user/jsch/blackwell-patch-match-cuda-bug

Conversation

@ahojnnes

@ahojnnes ahojnnes commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #3514. PatchMatch stereo produces empty/noisy depth maps and all-zero normal maps on Blackwell GPUs (RTX 5070, 5090, B200 — CUDA compute >= 100).

The root cause is a known NVCC compiler bug that miscompiles complex kernels when generating native SASS for sm_100+ at -O2/-O3. The same bug affects other projects including ggml-org/llama.cpp#18331, TensorRT-LLM, and CCCL.

When Blackwell architectures are detected in CMAKE_CUDA_ARCHITECTURES, the build system now removes sm_100+ entries for the colmap_mvs_cuda target and adds 90-virtual (PTX). Blackwell GPUs JIT-compile the PTX at first launch, bypassing the buggy native codegen path.

Detection handles:

  • Explicit numeric architectures (e.g., 120, 100-real, 89;120)
  • native / all / all-major — queries nvidia-smi at configure time

This workaround can be removed once NVIDIA ships a fixed NVCC.

Trade-offs

  • One-time JIT compilation delay on first kernel launch (cached by the CUDA driver afterwards)
  • JIT'd code may miss some Blackwell-specific scheduling optimizations, though PatchMatch is texture-read bound so the impact should be minimal
  • Affects all CUDA files in colmap_mvs_cuda, not just patch_match_cuda.cu, since CMake doesn't support per-file CUDA_ARCHITECTURES

Fixes #3514. PatchMatch stereo produces empty/noisy depth maps and all-zero normal maps on Blackwell GPUs (RTX 5070, 5090, B200 — CUDA compute >= 100).

The root cause is a known NVCC compiler bug that miscompiles complex kernels when generating native SASS for sm_100+ at -O2/-O3. The same bug affects other projects including ggml-org/llama.cpp#18331, TensorRT-LLM, and CCCL.

When Blackwell architectures are detected in CMAKE_CUDA_ARCHITECTURES, the build system now removes sm_100+ entries for the colmap_mvs_cuda target and adds 90-virtual (PTX). Blackwell GPUs JIT-compile the PTX at first launch, bypassing the buggy native codegen path.

Detection handles:
- Explicit numeric architectures (e.g., 120, 100-real, 89;120)
- native / all / all-major — queries nvidia-smi at configure time

This workaround can be removed once NVIDIA ships a fixed NVCC.

**Trade-offs**
- One-time JIT compilation delay on first kernel launch (cached by the CUDA driver afterwards)
- JIT'd code may miss some Blackwell-specific scheduling optimizations, though PatchMatch is texture-read bound so the impact should be minimal
- Affects all CUDA files in colmap_mvs_cuda, not just patch_match_cuda.cu, since CMake doesn't support per-file CUDA_ARCHITECTURES
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical compilation issue affecting NVIDIA Blackwell GPUs, which caused incorrect output for PatchMatch stereo. By intelligently modifying the CUDA build process to generate PTX instead of native SASS for these specific architectures, it ensures the application functions correctly on the latest hardware, mitigating a significant bug without requiring a compiler fix from NVIDIA.

Highlights

  • Blackwell GPU Compatibility Fix: Implemented a workaround for a known NVCC compiler bug that miscompiles complex kernels on Blackwell GPUs (sm_100+) when generating native SASS at -O2/-O3 optimization levels, which previously led to empty/noisy depth maps and all-zero normal maps in PatchMatch stereo.
  • CMake Build System Modification: Modified the CMake build system to detect Blackwell architectures (sm_100+) based on CMAKE_CUDA_ARCHITECTURES (explicit numeric values or keywords like 'native', 'all', 'all-major') and dynamically adjust the CUDA compilation flags for the colmap_mvs_cuda target.
  • PTX Generation for Blackwell: When a Blackwell GPU is detected, the build system now removes sm_100+ entries for colmap_mvs_cuda and adds 90-virtual (PTX) to CUDA_ARCHITECTURES. This forces Blackwell GPUs to JIT-compile the PTX at first launch, bypassing the buggy native codegen path.
  • User Notification: Added a message(WARNING) during CMake configuration to inform users if a Blackwell GPU is detected and the workaround is being applied.
  • Code Documentation: Included a detailed comment in src/colmap/mvs/patch_match_cuda.cu explaining the NVCC miscompilation issue and the implemented workaround.
Changelog
  • src/colmap/mvs/CMakeLists.txt
    • Added logic to detect Blackwell GPUs (sm_100+ compute capability) using CMAKE_CUDA_ARCHITECTURES and nvidia-smi.
    • Implemented conditional modification of CUDA_ARCHITECTURES for the colmap_mvs_cuda target, replacing sm_100+ with 90-virtual (PTX) when Blackwell is detected.
    • Added a CMake warning message to inform users about the applied workaround.
  • src/colmap/mvs/patch_match_cuda.cu
    • Added a multi-line comment explaining the NVCC miscompilation issue on Blackwell GPUs and how the CMake build system provides a workaround by emitting PTX.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a workaround for an NVCC compiler bug on Blackwell GPUs by modifying the CUDA architectures at build time. The implementation in CMakeLists.txt has a logic bug in the detection of Blackwell architectures that can lead to incorrect build configurations under certain conditions. I've provided a comment with a suggested fix to make the detection logic more robust. The explanatory comment added to patch_match_cuda.cu is clear and helpful.

Comment thread src/colmap/mvs/CMakeLists.txt Resolved
@ahojnnes
ahojnnes marked this pull request as ready for review April 2, 2026 09:30
@ahojnnes
ahojnnes merged commit 9b4190b into main Apr 2, 2026
15 of 18 checks passed
@ahojnnes
ahojnnes deleted the user/jsch/blackwell-patch-match-cuda-bug branch April 2, 2026 13:13
ahojnnes added a commit that referenced this pull request Apr 6, 2026
Fixes #3514. PatchMatch stereo produces empty/noisy depth maps and
all-zero normal maps on Blackwell GPUs (RTX 5070, 5090, B200 — CUDA
compute >= 100).

The root cause is a known NVCC compiler bug that miscompiles complex
kernels when generating native SASS for sm_100+ at -O2/-O3. The same bug
affects other projects including
ggml-org/llama.cpp#18331, TensorRT-LLM, and
CCCL.

When Blackwell architectures are detected in CMAKE_CUDA_ARCHITECTURES,
the build system now removes sm_100+ entries for the colmap_mvs_cuda
target and adds 90-virtual (PTX). Blackwell GPUs JIT-compile the PTX at
first launch, bypassing the buggy native codegen path.

Detection handles:
- Explicit numeric architectures (e.g., 120, 100-real, 89;120)
- native / all / all-major — queries nvidia-smi at configure time

This workaround can be removed once NVIDIA ships a fixed NVCC.

**Trade-offs**
- One-time JIT compilation delay on first kernel launch (cached by the
CUDA driver afterwards)
- JIT'd code may miss some Blackwell-specific scheduling optimizations,
though PatchMatch is texture-read bound so the impact should be minimal
- Affects all CUDA files in colmap_mvs_cuda, not just
patch_match_cuda.cu, since CMake doesn't support per-file
CUDA_ARCHITECTURES
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.

Empty patch match results on CUDA compute >= 100

2 participants