Skip to content

[ROCm] Add HIP build, wave64 port, and MI300 backward kernel (gfx942, gfx950) - #1102

Open
deeksha-amd wants to merge 4 commits into
nerfstudio-project:mainfrom
AMD-Ecosystem:amd-main
Open

deeksha-amd wants to merge 4 commits into
nerfstudio-project:mainfrom
AMD-Ecosystem:amd-main

Conversation

@deeksha-amd

Copy link
Copy Markdown

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.

  1. Build. setup.py and the JIT builders invoke nvcc. They now detect a ROCm torch (BUILD_ROCM=0/1 overrides), find the ROCm SDK (system or pip rocm-sdk-devel), and compile with hipcc. Matching changes are in the JIT build.py files, USE_ROCM branches in gsplat/cuda/include, rocm_compat/ libcu++ stand-ins, path.sh, and README_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.
  2. Wave64 port. __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 in conftest.py. CUDA sources are unchanged. Result: 2572 passed on MI300X.
  3. MI300 backward kernel, one tile per wavefront. On MI300 a wavefront is 64 lanes. tile_size=8 is 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_kernel keeps 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 the v_colors atomics are spread across the wave (element e in lane e % 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_ROCM or 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), so v1.6 was force-pushed.

MI300 performance

MI300X, 1920×1080, 300k gaussians, forward+backward. tile_size=8 is this kernel; tile_size=16 is the generic kernel on the same GPU.

channels tile_size=8 tile_size=16 speedup
32 6.1 ms 16.1 ms 2.6×
3 1.9 ms 2.2 ms 1.2×

Test plan

ROCm: MI300X (gfx942), ROCm 10.1.0, torch 2.14.0+rocm10.1.0

Wheel built with BUILD_CAMERA_WRAPPERS=1, then all JIT extensions, then python -m pytest tests/ -q -rfE --tb=line --continue-on-collection-errors.

  • Wheel build and import gsplat
  • JIT extensions: geometry, sensors, scene, experimental render inference
  • Full suite: 8 failed, 2572 passed, 145 skipped, 14 xfailed, 2 xpassed (~15 min)
  • tile_size=8 path checked against the torch reference (test_rasterize_to_pixels, CDIM 3 and 32)

The 8 failures:

  • 7 single-element float32 tolerance mismatches in 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 optional PLAS, imageio, torchpq and cupy packages. With all four installed (cupy built for ROCm), it still fails inside the third-party torchpq K-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+cu130

Same wheel build (BUILD_CAMERA_WRAPPERS=1), then the full suite.

  • Wheel build and import gsplat (ROCm logic stays inactive on a CUDA torch)
  • Full suite: 5 failed, 2616 passed, 141 skipped

The 5 failures:

  • test_png_compression – optional PLAS / torchpq / cupy dependencies not installed on that node.
  • test_2dgs.py::test_rasterize_to_pixels_2dgs[batch_dims1-3], [batch_dims2-3] and test_basic.py::test_rasterize_to_pixels_eval3d[3-batch_dims10-0-True-False-False-pinhole-8], [...batch_dims11-...-16] – pre-existing: plain upstream 512d366 built 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], and test_rasterize_to_pixels_eval3d[3-batch_dims10-0-True-False-False-pinhole-8], [...batch_dims11-...-16]) also fail on plain upstream main (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.

deeksha-amd and others added 4 commits November 11, 2026 07:38
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>
@deeksha-amd

Copy link
Copy Markdown
Author

@liruilong940607 kindly help to review this PR.

This branch has not been deployed

No deployments
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.

1 participant