Run a Warp example#
2026-11-05
3 min read time
These examples assume that Warp is installed as described in Install Warp. Run the examples in the same Docker container where Warp is installed.
Write and run a Warp kernel#
Warp kernels are Python functions decorated with @wp.kernel. They are
compiled for your AMD GPU the first time they are launched. AMD GPUs are
addressed through the cuda:N device names.
Save the following code snippet to a Python script named
warp_example.py.import numpy as np import warp as wp @wp.kernel def saxpy(a: float, x: wp.array(dtype=float), y: wp.array(dtype=float)): i = wp.tid() y[i] = a * x[i] + y[i] n = 1_000_000 device = wp.get_device("cuda:0") x = wp.array(np.arange(n, dtype=np.float32), device=device) y = wp.ones(n, dtype=float, device=device) wp.launch(saxpy, dim=n, inputs=[2.0, x, y], device=device) result = y.numpy() print(f"Ran on {device.name} ({device.arch_str})") print("y[:5] =", result[:5]) assert np.allclose(result, 2.0 * np.arange(n, dtype=np.float32) + 1.0) print("SAXPY result is correct")
Run the script.
python warp_example.pyAfter Warp prints its initialization banner, the output ends with lines similar to the following:
Ran on AMD Instinct MI355X (gfx950:sramecc+:xnack-) y[:5] = [1. 3. 5. 7. 9.] SAXPY result is correct
Compiled kernels are cached in
~/.cache/warp, so later runs start faster.
Run the built-in examples#
The warp/examples directory contains scripts, grouped into subdirectories, that show how to implement various simulation methods using the Warp API. Most examples write USD files with time-sampled animations to the current working directory.
Install the packages used by the examples.
pip install usd-core matplotlib
If
pipreports anexternally-managed-environmenterror, add--break-system-packagesto thepip installcommand.Run an example from the command line. Pass
--headlessso that examples that can open a plot window run without a display.python -m warp.examples.<example_subdir>.<example> --headless
For example, to run the discrete element method (DEM) simulation:
python -m warp.examples.core.example_dem --headless
This writes the animation to
example_dem.usd, which you can open in any USD viewer.
The following examples run on AMD Instinct GPUs:
Module |
Description |
|---|---|
|
Discrete element method (DEM) particle simulation with cohesion, using a hash grid for neighbor search |
|
Iso-surface extraction from a density field with marching cubes |
|
Position-based dynamics particles colliding with a deforming triangle mesh |
|
Basic ray tracer using the built-in |
|
Signed distance field (SDF) ray marching renderer |
|
Sampling points on a mesh surface using a cumulative distribution function |
|
Smoothed particle hydrodynamics (SPH) fluid simulation |
|
Optimizing the Rosenbrock function with the PyTorch Adam optimizer (requires PyTorch) |
|
2D wave equation solver with collision against a moving sphere |
|
Differentiable ray caster |
|
Coordinate-based multilayer perceptron (MLP) trained on an image with tile primitives |
Examples that use the OpenGL renderer, such as example_render_opengl,
might not work because AMD Instinct GPUs run headless.
Learn more#
For more information about the Warp API, interoperability with PyTorch, and differentiable simulation, see the upstream Warp documentation.