Repository navigation
Fix round 2 for symforce#465: host-safe HIP compat header, Windows host compile - #3
Merged
Merged
Conversation
The HIP branch of cuda_to_hip.h included hip_cooperative_groups.h and hipcub/hipcub.hpp, and declared namespace cub = hipcub, unconditionally. Every generated kernel.h, caspar_mappings.h and solver.h includes cuda_to_hip.h, so a host translation unit built with the host C++ compiler that includes a generated header fails inside rocPRIM, for example with g++: "'__builtin_amdgcn_wavefrontsize' was not declared in this scope". A project that links a generated Caspar library and includes solver.h from its own .cc files cannot build. The CUDA branch already keeps cooperative groups and CUB behind __CUDACC__; the HIP branch now does the same behind __HIPCC__, which clang defines when it compiles HIP and the host compiler does not. Host code still gets the HIP runtime API and the cuda* spellings. The CUDA branch is unchanged. The HIP build of the *_cuda_test.cc tests compiled every test and generated .cc file as HIP, which is why it never saw this. They now stay with the host C++ compiler, as in the CUDA build, so caspar_solver_cuda_test.cc, caspar_tridiagonal_cuda_test.cc and both generated solver.cc files check that solver.h is includable from host code. Linking hip::hipcub would pass its hip::device options (-x hip, --offload-arch) to those host sources too, so the test runtime takes only the hipCUB and rocPRIM headers, which is all it needs. Without the header change, the six host objects of the four test targets fail to compile with the error above; with it, all four build and pass on an MI250X. Authored with Claude. Test Plan: ``` cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_HIP_ARCHITECTURES=gfx90a cmake --build build ctest --test-dir build -R caspar --output-on-failure ctest --test-dir build ```
The HIP test build compiles the generated solver.cc files with the host C++ compiler, as the CUDA build does. On Windows (clang++ over the MSVC STL and UCRT) both failed on names that only glibc and libstdc++ supply: sort_indices.h used uint, a glibc typedef it took from <sys/types.h>, and solver.cc called std::to_string without including <string>. Compiled as HIP they had built, because the HIP headers supply both. sort_indices.h now spells the type unsigned int and includes <cstddef> for size_t. The solver.cc template includes <string>, and also <cstdio> for printf and <utility> for std::swap, which it used without including either; the checked-in generated solvers are regenerated from it. The changes are type spellings and includes only: uint is unsigned int wherever it exists, so the declarations, their mangled names and the CUDA build are unchanged. To check on Linux, compile the generated solver.cc with uint, ushort and ulong defined to undeclared names after <sys/types.h> (which hides the glibc typedefs as Windows lacks them): both files fail before this change and build after it. Authored with Claude. Test Plan: ``` cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_HIP_ARCHITECTURES=gfx90a cmake --build build ctest --test-dir build -R caspar --output-on-failure ctest --test-dir build ```
jeffdaily
added a commit
to AMD-Ecosystem/moat
that referenced
this pull request
Nov 18, 2026
Collaborator
Author
|
To approve this fix round, leave a comment containing this line by itself: To send it back to the porter instead: Approving covers the commits on this branch and the section under '## Upstream reply' in the body, which is posted verbatim as a comment on the upstream pull request after the merge, behind a standing line disclosing that it was drafted by an AI assistant. |
Collaborator
Author
|
/moat approve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits on top of the published tip
e7e0b00c, for the open upstream PR symforce-org#465. Nobody upstream asked for this round: a HIP build of colmap's Caspar kernels with this PR applied showed that a host-compiled file including a generated header does not build.What changed
aa31e636Keep device-only HIP headers out of host compiles. The HIP branch ofcuda_to_hip.hincludedhip_cooperative_groups.handhipcub.hppunconditionally, so a.ccfile compiled by g++ that includes a generatedsolver.hfailed in rocPRIM (__builtin_amdgcn_wavefrontsizenot declared). They now sit under__HIPCC__, mirroring the__CUDACC__guard on the CUDA branch. The HIP test build now compiles the fourcaspar_*_cuda_test.ccfiles and both generatedsolver.ccfiles with the host compiler, as the CUDA build does, so the defect cannot come back unnoticed.c665e5ccFix host compile of generated solver.cc on Windows. Host-compiling those files on Windows exposed two portability gaps in shared code:sort_indices.hused the glibc typedefuint(nowunsigned int, and<cstddef>in place of<sys/types.h>), and thesolver.cctemplate usedprintf,std::to_stringandstd::swapwithout including<cstdio>,<string>and<utility>. The two checked-in generatedsolver.ccfiles are regenerated.The second commit touches code the CUDA build compiles. With nvcc 12.8 the six host objects are byte-identical before and after, and all 199 kernel code sections are byte-identical.
Validation at
c665e5ccrustfmt, a docs dependency).symengine_symforce_linter_test, wheremake lintrun by hand against the same build passes.aa31e636this build failed;c665e5ccis the fix.Known and not addressed here: host-compiling the generated
solver.ccfiles under HIP prints-Wunused-result/-Wunused-valuewarnings for ignoredhipError_treturn values (the same ignored returns that warned before when those files were compiled as HIP).Upstream reply
Two more small commits. Building another project's Caspar kernels against this branch showed that a host
.ccfile that includes a generatedsolver.hdid not compile in a HIP build: the HIP side ofcuda_to_hip.hstill pulled in cooperative groups and hipCUB unconditionally, which g++ can't parse. They are now included only when compiling HIP device code, the same way the CUDA side is guarded by__CUDACC__. To keep that covered, the HIP build of the tests now compiles thecaspar_*_cuda_test.ccfiles and the generatedsolver.ccfiles with the host compiler, as the CUDA build does.Doing that on Windows turned up two portability gaps that aren't specific to HIP:
sort_indices.huseduint, which only glibc defines (nowunsigned int), and the generatedsolver.ccusedprintf,std::to_stringandstd::swapwithout including<cstdio>,<string>and<utility>. The template and the two checked-insolver.ccfiles are updated. With CUDA 12.8 the object code is unchanged by this: the host objects are byte-identical and so is every kernel's code.Tested again on an AMD Instinct MI250X and an AMD Radeon PRO W7800 on Linux (the Caspar GPU tests, the codegen tests and the rest of the suite, apart from the same three tests that need tools those machines lack) and an AMD Radeon 8060S on Windows (the Caspar GPU tests).
Notes for the approver
The
[ROCm]prefix onc665e5ccis there because the commit gate requires it; the change itself is a shared-code portability fix. The cause of thePartiallyContainedTracksNaN seen in colmap is in colmap's vendored f32 kernels and is not part of this round.