[Bug]: AMDGPU DLPack zero-copy view segfaults on Genesis World 1.3.1
Bug Description
Genesis World 1.3.1 crashes with SIGSEGV when its AMDGPU backend consumes a Quadrants DLPack zero-copy view through PyTorch.
The same course workload ran successfully with genesis-world==0.4.6. The crash appeared after upgrading to Genesis World 1.3.1, which pins Quadrants 1.2.0.
Setting GS_ENABLE_ZEROCOPY=0 avoids the crash and allows the simulation to run.
Steps to Reproduce
Save the following script as repro.py:
import genesis as gs
gs.init(backend=gs.amdgpu)
scene = gs.Scene(show_viewer=False)
scene.add_entity(gs.morphs.Plane())
scene.add_entity(
gs.morphs.Box(
size=(0.1, 0.1, 0.1),
pos=(0.0, 0.0, 1.0),
)
)
scene.build()
Run it with zero-copy explicitly enabled:
GS_ENABLE_ZEROCOPY=1 python3 repro.py
The process terminates with SIGSEGV and exit status 139 during scene.build().
For comparison, the copy path completes successfully:
GS_ENABLE_ZEROCOPY=0 python3 repro.py
The failure can also be reproduced at the Quadrants–PyTorch interop layer without importing Genesis.
Save as quadrants_zerocopy_repro.py:
import quadrants as qd
qd.init(arch=qd.amdgpu)
x = qd.ndarray(qd.f32, shape=(6,))
x.fill(3.0)
qd.sync()
tensor = x.to_torch(copy=False)
print(
"view:",
tensor.shape,
tensor.stride(),
hex(tensor.data_ptr()),
flush=True,
)
# The process terminates with SIGSEGV here.
print(tensor.cpu(), flush=True)
Run:
python3 quadrants_zerocopy_repro.py
The process exits with status 139. Calling qd.sync() before exporting does not prevent the failure.
As a separate control test, replace the zero-copy conversion and subsequent prints with:
tensor = x.to_torch()
print(tensor.cpu(), flush=True)
The copied conversion completes successfully.
Expected Behavior
scene.build() can complete successfully with the AMDGPU backend.
A tensor returned by to_torch(copy=False) should remain valid when accessed or copied by PyTorch.
Screenshots/Videos
No response
Relevant log output
[Genesis] Running on [AMD Radeon AI PRO R9700] with backend gs.amdgpu.
[Genesis] Genesis initialized. version: 1.3.1
[Genesis] Building scene...
[Genesis] Preprocessing geom idx 1.
Fatal Python error: Segmentation fault
Current thread:
File "torch/utils/_device.py", line 103, in __torch_function__
File "genesis/utils/misc.py", line 408, in tensor_to_cpu
File "genesis/utils/misc.py", line 413, in tensor_to_array
File "genesis/utils/misc.py", line 778, in qd_to_numpy
File "genesis/engine/solvers/rigid/rigid_solver.py", line 817,
in _init_invweight_and_meaninertia
File "genesis/engine/solvers/rigid/rigid_solver.py", line 424, in build
File "genesis/engine/simulator.py", line 203, in build
File "genesis/engine/scene.py", line 910, in build
Minimal Quadrants output:
[Quadrants] version 1.2.0, llvm 22.1.0, commit 3d9af718, linux, python 3.12.3
[Quadrants] Starting on arch=amdgpu
view: torch.Size([6]) (1,) 0x...
Fatal Python error: Segmentation fault
Environment
- OS: Linux, kernel 6.17
- GPU: AMD Radeon AI PRO R9700 (
gfx1201) - Genesis World: 1.3.1
- Quadrants: 1.2.0
- LLVM: 22.1.0
- Python: 3.12.3
- PyTorch:
2.9.1+rocm7.13.0 - Previous working Genesis version: 0.4.6
Release version or Commit ID
- Genesis World: 1.3.1
- Quadrants: 1.2.0 (
3d9af718)
Additional Context
Genesis automatically enables zero-copy for the AMDGPU backend. On a non-CPU backend, qd_to_numpy() obtains a DLPack-backed PyTorch tensor and then calls .cpu().
Quadrants currently imports a raw DLPack capsule:
torch.utils.dlpack.from_dlpack(field.to_dlpack())
This bypasses DLPack's stream-aware __dlpack__(stream=...) protocol. However, calling qd.sync() before exporting does not prevent the observed crash, so missing stream synchronization alone may not fully explain the issue.
Current workaround:
export GS_ENABLE_ZEROCOPY=0
Closing this issue because the problem does not reproduce with the official ROCm 7.2.1 stack.
Using the same AMD Radeon AI PRO R9700 (gfx1201), Genesis World 1.3.1, and Quadrants 1.2.0 with PyTorch 2.9.1 + ROCm 7.2.1:
- Genesis builds successfully with zero-copy enabled.
- The standalone Quadrants–PyTorch DLPack reproducer passes.
- A Genesis scene completes 1,000 simulation steps with
gs.use_zerocopy == True.
The SIGSEGV only reproduces with the ROCm 7.13-based stack, so this appears to be a ROCm/PyTorch DLPack interoperability regression rather than a general Genesis issue.
I will report the ROCm 7.13 regression to the appropriate ROCm repository. Thanks!