Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Haosulab ManiSkill BackendResolution

From Leeroopedia
Knowledge Sources
Domains Robotics, Simulation, Backend Configuration
Last Updated 2026-02-15 08:00 GMT

Overview

Concrete tool for resolving and configuring simulation and rendering backend devices (CPU/GPU) for ManiSkill environments.

Description

The backend.py module provides utilities for determining which physics simulation backend and rendering backend to use, and on which devices. It maps user-friendly backend names to internal SAPIEN backend identifiers and handles device selection.

BackendInfo dataclass: Holds the resolved configuration:

  • device -- torch.device for returning simulation data.
  • sim_device -- sapien.Device for physics simulation.
  • sim_backend -- Backend name string (e.g., "physx_cpu", "physx_cuda").
  • render_device -- sapien.Device for rendering (None to disable rendering).
  • render_backend -- Render backend name string (e.g., "sapien_cpu", "sapien_cuda").

Name mappings:

  • Simulation: "cpu" -> "physx_cpu", "cuda"/"gpu" -> "physx_cuda"
  • Rendering: "cpu" -> "sapien_cpu", "cuda"/"gpu" -> "sapien_cuda"

parse_sim_and_render_backend(): The main resolution function that:

  • Parses device IDs from backend strings (e.g., "cuda:1").
  • Maps user-provided backend names to SAPIEN internal names.
  • Handles MacOS by forcing CPU rendering.
  • Falls back to CPU rendering if CUDA device is not found.
  • Supports special device strings (e.g., PCI addresses for AMD GPUs).

Usage

Called internally during environment initialization to set up the simulation and rendering backends. Users specify backends via gym.make("Env-v1", sim_backend="cpu") or similar.

Code Reference

Source Location

Signature

@dataclass
class BackendInfo:
    device: torch.device
    sim_device: sapien.Device
    sim_backend: str
    render_device: Union[sapien.Device, None]
    render_backend: str

def parse_backend_device_id(backend: str) -> tuple[str, int]: ...
def parse_sim_and_render_backend(sim_backend: str, render_backend: str) -> BackendInfo: ...

Import

from mani_skill.envs.utils.system.backend import parse_sim_and_render_backend, BackendInfo

I/O Contract

Inputs

Name Type Required Description
sim_backend str Yes Simulation backend name ("cpu", "cuda", "gpu", "physx_cpu", "physx_cuda", or "cuda:N")
render_backend str Yes Render backend name ("cpu", "cuda", "gpu", "none", or device-specific string)

Outputs

Name Type Description
BackendInfo BackendInfo Resolved backend configuration with devices and backend names

Usage Examples

Basic Usage

from mani_skill.envs.utils.system.backend import parse_sim_and_render_backend

# CPU simulation with CPU rendering
info = parse_sim_and_render_backend("cpu", "cpu")
# info.device == torch.device("cpu")
# info.sim_backend == "physx_cpu"

# GPU simulation on device 0
info = parse_sim_and_render_backend("cuda:0", "cuda:0")
# info.device == torch.device("cuda:0")
# info.sim_backend == "physx_cuda"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment