Repository navigation
[ROCm] Add HIP build, wave64 port, and MI300 backward kernel (gfx942, gfx950) - #1102
Open
deeksha-amd wants to merge 4 commits into
Open
deeksha-amd wants to merge 4 commits into
deeksha-amd wants to merge 4 commits into
Conversation
gsplat's build invokes nvcc and CUDA headers, so pip install fails against a ROCm PyTorch. This makes the same tree build with hipcc. Nothing changes for CUDA builds: all ROCm logic is either guarded by USE_ROCM / IS_ROCM or additive. - setup.py: auto-detect a ROCm torch (BUILD_ROCM=0/1 overrides), locate the ROCm SDK (system install or pip rocm-sdk-devel), pick offload archs (ROCM_ARCHS / PYTORCH_ROCM_ARCH), run the hipify post-fixups and build gsplat.csrc with hipcc. - JIT build.py files (cuda, geometry, scene, sensors, experimental): matching ROCm toolchain flags and include paths. - gsplat/cuda/include: Common.h/Common.cuh/ATenAtomic.cuh/Utils.cuh/ Utils.h/Cameras.cuh/Lidars.cuh get USE_ROCM branches (hip runtime, hipcub, rocprim, wave64 helpers, c10/hip headers); the CUDA branches are the unmodified upstream text. rocm_compat/ provides libcu++ stand-ins for SDKs that do not ship CCCL. - path.sh: environment helper for the pip ROCm SDK (hipcc / ROCM_PATH). - README_AMD.md: ROCm build, test and expected-results guide. The wheel builds with hipcc on MI300X (gfx942) and MI350X (gfx950), ROCm 10.1, torch 2.14, and a CUDA torch never enters the ROCm path. Signed-off-by: Karthik Kashyap Thatipamula <kthatipa@amd.com> Signed-off-by: Deeksha Goplani <deeksha.goplani@amd.com> Co-authored-by: Chandan Sharma <Chandan.Sharma2@amd.com> Co-authored-by: Vikas C Sajjan <Vikas.CSajjan@amd.com>
__shfl_sync, cg::reduce, and 32-bit shuffle masks assume a 32-lane warp. On gfx942 a wavefront is 64 lanes, so those reductions are wrong. This ports the gsplat CUDA kernels, sensors, and experimental inference kernels to wavefront-64 equivalents. All ROCm-specific code is under USE_ROCM / HIP guards; the CUDA code paths are unchanged. - Replace __shfl_*_sync / cg::reduce / cg::labeled_partition based reductions with wavefront-64 equivalents (shuffle reductions, dynamic labeled reductions, unsafeAtomicAdd) on ROCm. - hipFuncSetAttribute for dynamic shared memory, hipcub radix sort / scan, rocprim warp reductions. - 64-bit shuffle masks (WarpMask) and 32-lane logical warp helpers (WarpSync.h) for the experimental kernels and sensor reductions. - GET_CURRENT_STREAM / GSPLAT_GRID_CONSTANT / GSPLAT_LAUNCH_BOUNDS_CTA portability macros; host-only std::array::operator[] avoided in device code. - conftest.py: ROCm-specific xfail lists for tests whose numerical tolerances or CUDA-only features do not apply on AMD. Verified by the test suite on MI300X (gfx942) and MI350X (gfx950). The CUDA branches are untouched. Signed-off-by: Karthik Kashyap Thatipamula <kthatipa@amd.com> Signed-off-by: Deeksha Goplani <deeksha.goplani@amd.com> Co-authored-by: Bin Ding <Bin.Ding@amd.com> Co-authored-by: Karthik Kashyap Thatipamula <kthatipa@amd.com>
AMD Instinct wavefronts are 64 lanes wide. tile_size=8 is an 8x8 tile,
so one tile, one 64-thread block, and one wavefront line up, with one
pixel per lane. rasterize_bs64_to_pixels_3dgs_bwd_kernel is written for
that mapping:
- each lane owns one pixel. Per-gaussian id, xy+opacity, and conic stay
in registers and are broadcast with __shfl. Only the per-channel
colors go through LDS.
- gradient reductions use DPP row/bcast (v_mov_b32_dpp) and fold into
the consuming add, with no LDS scratch.
- the CDIM-wide v_colors reduction leaves element e in lane e % 64, so
the atomics are wave-coalesced instead of serialized on one lane.
Selected only on ROCm when the tile is 64 threads and the color LDS
fits in 64 KB. The batch is 64 gaussians for CDIM <= 32 and 32 above
that. The generic kernel is unchanged. The forward pass launches the
matching <8, 64> variant (one wavefront per tile, one pixel per
thread). CUDA still allows only tile sizes {4, 16}.
MI300X, 1920x1080, 300k gaussians, forward+backward, this kernel
against the generic tile_size=16 kernel: CDIM 32 is 6.1 ms versus
16.1 ms (2.6x); CDIM 3 is 1.9 ms versus 2.2 ms.
Also built and tested on MI350X (gfx950).
Signed-off-by: Deeksha Goplani <deeksha.goplani@amd.com>
Co-authored-by: Hashem Hashemi <hashem.hashemi@amd.com>
V1.6 merge to amd-main
Author
|
@liruilong940607 kindly help to review this PR. |
This branch has not been deployed
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.
Summary
gsplat builds only with CUDA, so it cannot be installed against a ROCm PyTorch, and its kernels assume a 32-lane warp. This PR makes that tree build and pass on AMD Instinct, then speeds up the 3DGS backward pass on MI300 by lining up one 8×8 tile, one 64-thread block, and one wavefront.
setup.pyand the JIT builders invokenvcc. They now detect a ROCm torch (BUILD_ROCM=0/1overrides), find the ROCm SDK (system or piprocm-sdk-devel), and compile withhipcc. Matching changes are in the JITbuild.pyfiles,USE_ROCMbranches ingsplat/cuda/include,rocm_compat/libcu++ stand-ins,path.sh, andREADME_AMD.md. CUDA builds take the original path. Result: the wheel and all JIT extensions build on MI300X (ROCm 10.1, torch 2.14) and on H100.__shfl_sync,cg::reduce, and 32-bit shuffle masks assume 32 lanes, which is wrong on gfx942 (a wavefront is 64 lanes). ROCm builds use 64-lane reductions,hipFuncSetAttribute, hipcub/rocprim, 64-bit masks, and 32-lane logical-warp helpers for the experimental and sensors kernels, plus ROCm xfail lists inconftest.py. CUDA sources are unchanged. Result: 2572 passed on MI300X.tile_size=8is an 8×8 tile, so one tile, one 64-thread block, and one wavefront line up, with one pixel per lane.rasterize_bs64_to_pixels_3dgs_bwd_kernelkeeps each gaussian's id, xy+opacity, and conic in registers and broadcasts them with__shfl; only colors use LDS. Gradients reduce with DPP (v_mov_b32_dpp), and thev_colorsatomics are spread across the wave (element ein lanee % 64) so they coalesce. It runs only on ROCm when the tile is 64 threads and the color LDS fits in 64 KB (batch of 64 gaussians for CDIM ≤ 32, 32 above that). The generic kernel is unchanged, and CUDA still allows only tile sizes 4 and 16. The forward pass uses the same<8, 64>launch.All ROCm code is behind
USE_ROCM/IS_ROCMor is additive. The CUDA branches of the shared headers are the unmodified upstream text (an earlier revision had hipify rewrites committed into them; those are restored).History was rewritten (squashed onto
512d366), sov1.6was force-pushed.MI300 performance
MI300X, 1920×1080, 300k gaussians, forward+backward.
tile_size=8is this kernel;tile_size=16is the generic kernel on the same GPU.tile_size=8tile_size=16Test plan
ROCm: MI300X (gfx942), ROCm 10.1.0,
torch 2.14.0+rocm10.1.0Wheel built with
BUILD_CAMERA_WRAPPERS=1, then all JIT extensions, thenpython -m pytest tests/ -q -rfE --tb=line --continue-on-collection-errors.import gsplattile_size=8path checked against the torch reference (test_rasterize_to_pixels, CDIM 3 and 32)The 8 failures:
tests/test_basic.py(test_projection[...-pinhole],test_fully_fused_projection_packed[...]). In each, exactly one element out of ~3.4e5-6.8e5 is just outside the test tolerance (relative error < 1e-2). This is float32 rounding noise on gfx942, not a logic error; the same tests pass on CUDA (H100).test_compression.py::test_png_compression- not a gsplat issue. It needs the optionalPLAS,imageio,torchpqandcupypackages. With all four installed (cupy built for ROCm), it still fails inside the third-partytorchpqK-means kernel (cupy.RawKernel.max_dynamic_shared_size_bytes->hipErrorUnknown), before reaching gsplat code.ROCm: MI350X (gfx950), ROCm 10.1.0, torch 2.14.0+rocm10.1.0
Wheel built with BUILD_CAMERA_WRAPPERS=1 and PYTORCH_ROCM_ARCH=gfx950 (device-gfx950 wheels), then all JIT extensions, then python -m pytest tests/ -q -rfE --tb=line --continue-on-collection-errors. Torch reference tests used nerfacc from AMD-Ecosystem/nerfacc gpinkert/mi450.
Wheel build and import gsplat
JIT extensions: geometry, sensors, scene, experimental render inference
Full suite: 18 failed, 2587 passed, 141 skipped, 14 xfailed, 2 xpassed (~11 min)
tile_size=8 path checked against the torch reference (test_rasterize_to_pixels, CDIM 3 and 32)
The 18 failures:
17 float32 tolerance mismatches in tests/test_basic.py (test_projection, test_fully_fused_projection_packed, including ortho and fisheye). In each, 1 element (2 in two v_scales cases) out of ~2.5e5–6.8e5 is just outside the test tolerance (relative error < 1e-2). Same float32 rounding noise as the MI300X failures.
test_compression.py::test_png_compression — same as MI300X, not a gsplat issue.
CUDA: NVIDIA H100 80GB (sm_90), CUDA 13.1 nvcc,
torch 2.9.1+cu130Same wheel build (
BUILD_CAMERA_WRAPPERS=1), then the full suite.import gsplat(ROCm logic stays inactive on a CUDA torch)The 5 failures:
test_png_compression– optionalPLAS/torchpq/cupydependencies not installed on that node.test_2dgs.py::test_rasterize_to_pixels_2dgs[batch_dims1-3],[batch_dims2-3]andtest_basic.py::test_rasterize_to_pixels_eval3d[3-batch_dims10-0-True-False-False-pinhole-8],[...batch_dims11-...-16]– pre-existing: plain upstream512d366built on the same node fails the same 4 tests on every run (3 runs each), so they are not caused by this PR.Note for the upstream PR
The 4 failing 2DGS / eval3d tests on H100 (
test_rasterize_to_pixels_2dgs[batch_dims1-3],[batch_dims2-3], andtest_rasterize_to_pixels_eval3d[3-batch_dims10-0-True-False-False-pinhole-8],[...batch_dims11-...-16]) also fail on plain upstreammain(512d366) with CUDA 13.1 / torch 2.9.1+cu130 on H100. They are not caused by this PR, so they are worth calling out in the upstream PR description.