Reach vendored GLM via -I flags instead of include_dirs (avoids hipify mutating GLM headers) - #21
Open
bjoernellens1 wants to merge 1 commit into
Conversation
…utation The ROCm branch of get_extensions() built an include_dirs list that never contained the vendored gsplat/cuda/csrc/third_party/glm submodule path at all (unlike the CUDA branch, which already includes it), so every cxx and hipcc invocation failed with "glm/gtc/type_ptr.hpp: No such file or directory". Simply adding glm to include_dirs is not enough: CUDAExtension() forwards its include_dirs kwarg into torch.utils.hipify.hipify_python.hipify(header_include_dirs=include_dirs), which walks every header reachable from those directories and rewrites CUDA-specific tokens in place (e.g. __CUDACC__ -> __HIPCC__). Doing that to glm's own glm/simd/platform.h flips its "#elif defined(__HIPCC__)" branch on before reaching its real "#elif defined(__HIP__)" branch, so glm concludes it's being compiled by an unversioned CUDA compiler and aborts with "GLM requires CUDA 7.0 or higher" / "GLM_COMPILER undefined", cascading into "no matching function" errors on every glm::mat/vec call in the HIP kernels. Fix: leave glm out of include_dirs (so hipify never touches it) and instead pass its path as an explicit -I flag on both extra_compile_args["cxx"] (plain .cpp path) and hipcc_flags, which is aliased into extra_compile_args["nvcc"] (.hip path via hipcc). Both compile paths now resolve glm's real, unmutated headers. Verified: full pip install run no longer produces any "glm/gtc/type_ptr.hpp: No such file" or "GLM requires CUDA" errors on gfx1151 (confirmed via git -C gsplat/cuda/csrc/third_party/glm diff showing zero mutation after a build).
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.
PR draft: reach vendored GLM via
-Iflags instead ofinclude_dirs(ROCm build)Problem
The ROCm branch of
get_extensions()insetup.pybuilds aninclude_dirslist for the HIP build that never contains the vendored
gsplat/cuda/csrc/third_party/glmsubmodule path at all — unlike the CUDAbranch a bit further down in the same file, which already has
glm_pathasthe first entry of its own
include_dirs. Everycxxandhipccinvocation on the ROCm path fails with:
Why the obvious fix fails
The obvious fix is to just add
glm_pathto the ROCm branch'sinclude_dirs, mirroring the CUDA branch. That resolves the "file notfound" error, but breaks the build a different way.
CUDAExtension()forwards itsinclude_dirskwarg straight intotorch.utils.hipify.hipify_python.hipify(header_include_dirs=include_dirs).That call walks every header reachable from those directories and rewrites
CUDA-specific tokens in place — not just in gsplat's own sources, but in
anything sitting under an
include_dirspath, including a vendoredthird-party submodule that has nothing to do with CUDA/HIP itself.
Concretely, hipify's token rewriting touches
glm/simd/platform.h's owncompiler-detection macros. Among other substitutions, it flips
__CUDACC__→__HIPCC__. That trips glm's#elif defined(__HIPCC__)branch before glm's real#elif defined(__HIP__)branch is reached, so glm concludes it is beingcompiled by an unversioned CUDA compiler and aborts with:
which cascades into "no matching function" errors on every
glm::mat/veccall in the HIP kernels. This is confirmed by diffing the glm submodule
after a build (
git -C third_party/glm diffshows the mutation inplatform.hwhenglm_pathsits ininclude_dirs).Note this is one of potentially several substitutions hipify makes inside
platform.hwhile walking the directory — the root cause is that hipify iswalking and mutating vendored third-party headers at all, not any single
token it happens to rewrite. A fix that keeps glm out of hipify's
header_include_dirsscan avoids all of them at once, rather than patchingaround individual token collisions as they're discovered.
Fix
Leave
glm_pathout ofinclude_dirson the ROCm branch (so hipify neverwalks it) and instead pass it as an explicit
-Iflag on bothextra_compile_args["cxx"](plain.cppsources) andhipcc_flags(aliased into
extra_compile_args["nvcc"], which is the flag list actuallyused for the
.hipcompile path viahipcc). Both compile paths resolveglm's real, unmutated headers this way, since
-Iflags only reach thecompiler invocation and are never passed to hipify's directory scan.
Verification
A full
pip installrun produces zeroglm/gtc/type_ptr.hpp: No such fileand zero
GLM requires CUDAerrors on gfx1151. Confirmed viagit -C gsplat/cuda/csrc/third_party/glm diffshowing no mutation of thesubmodule after a build with this change in place. The build proceeds past
glm entirely and continues to the actual kernel compilation.
Relevance to #17
#17 also touches GLM/HIP plumbing (adding
glm_pathtoinclude_dirsplus-DTORCH_HIP_VERSION=8000to satisfy glm's now-hipifiedCUDA_VERSION-based version gate). That's addressing a real, separatelyobserved symptom of the same underlying cause: hipify rewriting tokens
inside the vendored glm headers because they sit under
include_dirs. The-I-flag approach here sidesteps that class of problem at the root — glmis never handed to hipify's walk at all, so no downstream
-Dworkaroundis needed to compensate for whatever it rewrites.
Happy to have this folded into #17 directly if that's preferred, since it
touches the same lines, or opened as its own small standalone PR if #17's
author would rather keep the two concerns separate — whichever is easier to
review.