NVIDIA Warp for Particle Simulation
Overview
Section titled “Overview”NVIDIA Warp is a Python framework for writing high-performance simulation code. Warp takes regular Python functions and JIT compiles them to efficient kernel code that can run on the CPU or GPU. For particula, Warp enables GPU-accelerated aerosol dynamics simulations including coagulation, condensation, and particle transport.
Key Features
Section titled “Key Features”- Python-First: Write simulation code in Python with decorators
- GPU Acceleration: Automatic compilation to CUDA kernels
- Differentiable: Built-in support for automatic differentiation
- Efficient: Zero-copy interop with NumPy and other frameworks
Core Concepts
Section titled “Core Concepts”1. Kernels
Section titled “1. Kernels”Warp kernels are Python functions decorated with @wp.kernel that execute in parallel across particles. They are compiled to native code and can run on CPU or GPU.
import warp as wp
@wp.kerneldef update_particle_positions( positions: wp.array(dtype=wp.vec3), velocities: wp.array(dtype=wp.vec3), dt: float,): tid = wp.tid() positions[tid] = positions[tid] + velocities[tid] * dt2. Functions
Section titled “2. Functions”Warp functions are reusable code blocks decorated with @wp.func that can be called from kernels. They are automatically inlined during compilation.
@wp.funcdef brownian_displacement( diffusion_coeff: float, dt: float, random_val: wp.vec3,) -> wp.vec3: """Compute Brownian motion displacement for a particle.""" sigma = wp.sqrt(2.0 * diffusion_coeff * dt) return random_val * sigma3. Data Structures
Section titled “3. Data Structures”Warp provides efficient data structures optimized for parallel computation:
- Arrays: 1D, 2D, 3D typed arrays for particle properties
- Vectors:
wp.vec3for positions, velocities - Matrices:
wp.mat33for rotation, coagulation kernels - Custom Structs: Define
Particle,Aerosoltypes
Getting Started
Section titled “Getting Started”Installation
Section titled “Installation”pip install warp-langBasic Usage
Section titled “Basic Usage”Save the kernel/function definitions above and this block in one Python file.
Warp needs file-backed source for compilation. This standalone Warp example
is not a Particula Aerosol workflow. For native state and explicit transfers,
see GPU foundations.
import warp as wpimport numpy as np
# Initialize Warpwp.init()
# Choose Warp CPU explicitly; use "cuda" only on a supported CUDA device.device = "cpu"# Create particle arrays on that devicen_particles = 10000positions = wp.array(np.random.randn(n_particles, 3) * 1e-6, dtype=wp.vec3, device=device)velocities = wp.zeros(n_particles, dtype=wp.vec3, device=device)
# Launch kerneldt = 0.001 # 1 ms timestepwp.launch( update_particle_positions, dim=n_particles, inputs=[positions, velocities, dt], device=device,)
# Synchronize and get resultswp.synchronize()result = positions.numpy()Resources
Section titled “Resources”Table of Contents
Section titled “Table of Contents”- Kernels and Function Inlining - Writing parallel particle computations
- Data Structures - Particle and aerosol data types
- Examples
- Aerosol Dynamics - Coagulation, condensation, diffusion
- Particle Interactions - Collisions, wall losses
- GPU Benchmarks - Condensation & coagulation scaling results
Explore this topic: Warp implementation