Built-Ins#

Warp built-in types and functions.

Built-in types and functions are available within Warp kernels and optionally also from the Warp Python runtime API.

Each built-in function is tagged to indicate where it can be used:

  • Kernel - Can be called from inside a Warp kernel

  • Python - Can be called at the Python scope

  • Differentiable - Propagates gradients when used in reverse mode automatic differentiation

For a listing of the API that is exclusively intended to be used at the Python scope and run inside the CPython interpreter, see warp.

Scalar Math#

abs

Compute the absolute value of x.

acos

Compute arccos of x in radians.

asin

Compute arcsin of x in radians.

atan

Compute the arctangent of x in radians.

atan2

Compute the 2-argument arctangent, atan2, of the point (x, y) in radians.

cbrt

Compute the cube root of x.

ceil

Compute the smallest integer that is greater than or equal to x.

clamp

Clamp the value of x to the range [low, high].

cos

Compute the cosine of x in radians.

cosh

Compute the cosh of x.

degrees

Convert x from radians into degrees.

erf

Compute the error function of x.

erfc

Compute the complementary error function of x.

erfcinv

Compute the inverse complementary error function of x.

erfinv

Compute the inverse error function of x.

exp

Compute the value of the exponential function \(e^x\).

floor

Compute the largest integer that is less than or equal to x.

frac

Retrieve the fractional part of x.

isfinite

Check if all elements of a are finite.

isinf

Check if any element of a is positive or negative infinity.

isnan

Check if any element of a is NaN.

log

Compute the natural logarithm (base-e) of x, where x is positive.

log2

Compute the binary logarithm (base-2) of x, where x is positive.

log10

Compute the common logarithm (base-10) of x, where x is positive.

max

Compute the maximum value.

min

Compute the minimum value.

nonzero

Compute 1.0 if x is not equal to zero, otherwise 0.0.

pow

Compute x raised to the power of y.

radians

Convert x from degrees into radians.

rint

Compute the nearest integer value to x, rounding halfway cases to nearest even integer.

round

Compute the nearest integer value to x, rounding halfway cases away from zero.

sign

Compute the sign of x.

sin

Compute the sine of x in radians.

sinh

Compute the sinh of x.

sqrt

Compute the square root of x, where x is positive.

step

Compute 1.0 if x < 0.0, otherwise 0.0.

tan

Compute the tangent of x in radians.

tanh

Compute the tanh of x.

trunc

Compute the nearest integer that is closer to zero than x.

Vector Math#

argmax

Compute the index of the maximum element of vector a.

argmin

Compute the index of the minimum element of vector a.

cross

Compute the cross product of two 3D vectors.

cw_div

Compute the component-wise division of a by b.

cw_mul

Compute the component-wise product of a and b.

ddot

Compute the double dot product between two matrices.

determinant

Compute the determinant of matrix a.

diag

Construct a matrix with the components of vector vec on the diagonal.

dot

Compute the dot product.

eig3

Compute the eigendecomposition of a 3x3 matrix A.

get_diag

Extract a vector containing the diagonal elements of square matrix mat.

identity

Create an identity matrix with shape=(n,n) with the type given by dtype.

inverse

Compute the inverse of matrix a.

length

Compute the length of a.

length_sq

Compute the squared length of a.

matrix

Construct a matrix.

matrix_from_cols

Construct a matrix with each vector argument as a column.

matrix_from_rows

Construct a matrix with each vector argument as a row.

norm_huber

Compute the Huber norm of a vector v with a given delta.

norm_l1

Compute the L1 norm of a vector v.

norm_l2

Compute the L2 norm of a vector v.

norm_pseudo_huber

Compute the "pseudo" Huber norm of a vector v with a given delta.

normalize

Compute the normalized value of a.

outer

Compute the outer product a*b^T for two vectors.

qr3

Compute the QR decomposition of a 3x3 matrix A.

skew

Compute the skew-symmetric 3x3 matrix for a 3D vector vec.

smooth_normalize

Normalize a vector using the pseudo-Huber norm.

svd2

Compute the SVD of a 2x2 matrix A.

svd3

Compute the SVD of a 3x3 matrix A.

trace

Compute the trace of matrix a.

transpose

Compute the transpose of matrix a.

vector

Construct a vector of given length and dtype.

Quaternion Math#

quat_from_axis_angle

Construct a quaternion representing a rotation of angle radians around the given axis.

quat_from_matrix

Construct a quaternion from a matrix.

quat_identity

Construct an identity quaternion with zero imaginary part and real part of 1.0.

quat_inverse

Compute quaternion conjugate.

quat_rotate

Rotate a vector by a quaternion.

quat_rotate_inv

Rotate a vector by the inverse of a quaternion.

quat_rpy

Construct a quaternion representing a combined roll (z), pitch (x), yaw rotations (y) in radians.

quat_slerp

Linearly interpolate between two quaternions.

quat_to_axis_angle

Extract the rotation axis and angle radians a quaternion represents.

quat_to_matrix

Convert a quaternion to a 3x3 rotation matrix.

quaternion

Construct a quaternion.

Transformations#

transform_compose

Compose a 4x4 transformation matrix from a 3D position, quaternion orientation, and 3D scale.

transform_decompose

Decompose a 4x4 transformation matrix into 3D position, quaternion orientation, and 3D scale.

transform_from_matrix

Construct a transformation from a 4x4 matrix.

transform_get_rotation

Extract the rotational part of transform xform.

transform_get_translation

Extract the translational part of transform xform.

transform_identity

Construct an identity transform with zero translation and identity rotation.

transform_inverse

Compute the inverse of the transformation xform.

transform_multiply

Multiply two rigid body transformations together.

transform_point

Apply a transform to a point.

transform_set_rotation

Set the rotational part of a transform xform.

transform_set_translation

Set the translational part of a transform xform.

transform_to_matrix

Convert a transformation to a 4x4 matrix.

transform_vector

Apply a transform to a vector.

transformation

Construct a transformation.

Spatial Math#

spatial_adjoint

Construct a 6x6 spatial inertial matrix from two 3x3 diagonal blocks.

spatial_bottom

Extract the bottom (second) part of a 6D screw vector.

spatial_cross

Compute the cross product of two 6D screw vectors.

spatial_cross_dual

Compute the dual cross product of two 6D screw vectors.

spatial_dot

Compute the dot product of two 6D screw vectors.

spatial_jacobian

Compute the spatial Jacobian matrix for a kinematic chain.

spatial_mass

Compute the composite rigid-body mass matrix for a kinematic chain.

spatial_top

Extract the top (first) part of a 6D screw vector.

spatial_vector

Construct a 6D screw vector.

Tile Primitives#

tile

Construct a new tile from per-thread kernel values.

tile_arange

Generate a tile of linearly spaced elements.

tile_argmax

Cooperatively compute the index of the maximum element in the tile using all threads in the block.

tile_argmin

Cooperatively compute the index of the minimum element in the tile using all threads in the block.

tile_assign

Assign a tile to a subrange of a destination tile.

tile_astype

Create a new tile with the same data as the input tile, but with a different data type.

tile_atomic_add

Atomically add a tile onto the array a.

tile_atomic_add_indexed

Atomically add a tile to a global memory array, with storage along a specified axis mapped according to a 1D tile of indices.

tile_broadcast

Broadcast a tile.

tile_bvh_query_aabb

Construct an axis-aligned bounding box query against a BVH object for thread-block parallel traversal.

tile_bvh_query_next

Move to the next bound in a thread-block parallel BVH query and return results as a tile.

tile_bvh_query_ray

Construct a ray query against a BVH object for thread-block parallel traversal.

tile_cholesky

Compute the Cholesky factorization L of a matrix A.

tile_cholesky_inplace

Compute the Cholesky factorization L of a matrix A.

tile_cholesky_solve

Solve for x in Ax = y.

tile_cholesky_solve_inplace

Solve for x in Ax = y by overwriting y with x.

tile_diag_add

Add a square matrix and a diagonal matrix d represented as a 1D tile.

tile_extract

Extract a single element from the tile.

tile_fft

Compute the forward FFT along the second dimension of a 2D tile of data.

tile_full

Allocate a tile filled with the specified value.

tile_ifft

Compute the inverse FFT along the second dimension of a 2D tile of data.

tile_load

Load a tile from a global memory array.

tile_load_indexed

Load a tile from a global memory array, with loads along a specified axis mapped according to a 1D tile of indices.

tile_lower_solve

Solve for z in Lz = y, where L is a lower triangular matrix.

tile_lower_solve_inplace

Solve for z in Lz = y, where L is a lower triangular matrix by overwriting y with z.

tile_map

Apply a function to tile elements.

tile_matmul

Compute the matrix product a*b.

tile_max

Cooperatively compute the maximum of the tile elements using all threads in the block.

tile_mesh_query_aabb

Construct an axis-aligned bounding box query against a warp.Mesh for thread-block parallel traversal.

tile_mesh_query_aabb_next

Move to the next triangle in a thread-block parallel mesh AABB query and return results as a tile.

tile_min

Cooperatively compute the minimum of the tile elements using all threads in the block.

tile_ones

Allocate a tile of one-initialized items.

tile_randf

Generate a tile of random floats.

tile_randi

Generate a tile of random integers.

tile_reduce

Apply a custom reduction operator across a tile.

tile_reshape

Create a reshaped view of a tile with the same data.

tile_scan_exclusive

Exclusive scan (prefix sum) across the tile.

tile_scan_inclusive

Inclusive scan (prefix sum) across the tile.

tile_scan_max_inclusive

Inclusive max scan across the tile.

tile_scan_min_inclusive

Inclusive min scan across the tile.

tile_sort

Cooperatively sort the elements of two tiles in ascending order based on the keys, using all threads in the block.

tile_squeeze

Create a squeezed view of a tile with the same data.

tile_store

Store a tile to a global memory array.

tile_store_indexed

Store a tile to a global memory array, with storage along a specified axis mapped according to a 1D tile of indices.

tile_sum

Cooperatively compute the sum of the tile elements.

tile_transpose

Transpose a tile.

tile_upper_solve

Solve for x in Ux = z, where U is an upper triangular matrix.

tile_upper_solve_inplace

Solve for x in Ux = z, where U is an upper triangular matrix by overwriting z with x.

tile_view

Extract a slice of a given tile [offset, offset+shape], if shape is not specified it will be inferred from the unspecified offset dimensions.

tile_zeros

Allocate a tile of zero-initialized items.

untile

Convert a tile back to per-thread values.

Geometry#

bvh_get_group_root

Get the root of a group in a BVH.

bvh_query_aabb

Construct an axis-aligned bounding box query against a BVH object.

bvh_query_aabb_tiled

Construct an axis-aligned bounding box query against a BVH object for thread-block parallel traversal.

bvh_query_next

Move to the next bound returned by the query.

bvh_query_next_tiled

Move to the next bound in a thread-block parallel BVH query and return results as a tile.

bvh_query_ray

Construct a ray query against a BVH object.

bvh_query_ray_tiled

Construct a ray query against a BVH object for thread-block parallel traversal.

closest_point_edge_edge

Find the closest points between two edges.

hash_grid_point_id

Query the index of a point in the warp.HashGrid.

hash_grid_query

Construct a point query against a warp.HashGrid.

hash_grid_query_next

Move to the next point in the hash grid query.

intersect_tri_tri

Test for intersection between two triangles (v0, v1, v2) and (u0, u1, u2) using Möller's method.

mesh_eval_face_normal

Evaluate the face normal the mesh given a face index.

mesh_eval_position

Evaluate the position on the warp.Mesh given a face index and barycentric coordinates.

mesh_eval_velocity

Evaluate the velocity on the warp.Mesh given a face index and barycentric coordinates.

mesh_get

Retrieve the mesh given its index.

mesh_get_group_root

Get the root of a group in a warp.Mesh.

mesh_get_index

Query the point-index of the mesh given a face-vertex index.

mesh_get_point

Query the point of the mesh given an index.

mesh_get_velocity

Query the velocity of the mesh given an index.

mesh_query_aabb

Construct an axis-aligned bounding box query against a warp.Mesh.

mesh_query_aabb_next

Move to the next triangle whose bounding box overlaps the query bounding box.

mesh_query_aabb_next_tiled

Move to the next triangle in a thread-block parallel mesh AABB query and return results as a tile.

mesh_query_aabb_tiled

Construct an axis-aligned bounding box query against a warp.Mesh for thread-block parallel traversal.

mesh_query_furthest_point_no_sign

Compute the furthest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_point

Compute the closest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_point_no_sign

Compute the closest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_point_sign_normal

Compute the closest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_point_sign_parity

Compute the closest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_point_sign_winding_number

Compute the closest point on the warp.Mesh with identifier id to the given point in space.

mesh_query_ray

Compute the closest ray hit on the warp.Mesh with identifier id, returns True if a hit < max_t is found.

mesh_query_ray_anyhit

Check for any ray hit on the warp.Mesh with identifier id.

mesh_query_ray_count_intersections

Count the number of intersections between a ray and a warp.Mesh.

Volumes#

volume_index_to_world

Transform a point uvw defined in volume index space to world space given the volume's intrinsic affine transformation.

volume_index_to_world_dir

Transform a direction uvw defined in volume index space to world space given the volume's intrinsic affine transformation.

volume_lookup

Query the value of voxel with coordinates i, j, k for a volume of type dtype.

volume_lookup_f

Query the value of voxel with coordinates i, j, k.

volume_lookup_i

Query the int32 value of voxel with coordinates i, j, k.

volume_lookup_index

Query the index associated with the voxel at coordinates i, j, k.

volume_lookup_v

Query the vector value of voxel with coordinates i, j, k.

volume_sample

Sample the volume of type dtype given by id at the volume local-space point uvw.

volume_sample_f

Sample the volume given by id at the volume local-space point uvw.

volume_sample_grad

Sample the volume given by id and its gradient at the volume local-space point uvw.

volume_sample_grad_f

Sample the volume and its gradient given by id at the volume local-space point uvw.

volume_sample_grad_index

Sample the volume given by id and its gradient at the volume local-space point uvw.

volume_sample_i

Sample the int32 volume given by id at the volume local-space point uvw.

volume_sample_index

Sample the volume given by id at the volume local-space point uvw.

volume_sample_v

Sample the vector volume given by id at the volume local-space point uvw.

volume_store

Store value at the voxel with coordinates i, j, k.

volume_store_f

Store value at the voxel with coordinates i, j, k.

volume_store_i

Store value at the voxel with coordinates i, j, k.

volume_store_v

Store value at the voxel with coordinates i, j, k.

volume_world_to_index

Transform a point xyz defined in volume world space to the volume's index space given the volume's intrinsic affine transformation.

volume_world_to_index_dir

Transform a direction xyz defined in volume world space to the volume's index space given the volume's intrinsic affine transformation.

Random#

curlnoise

Divergence-free vector field based on Perlin noise.

noise

Non-periodic Perlin-style noise.

pnoise

Periodic Perlin-style noise.

poisson

Generate a random sample from a Poisson distribution.

rand_init

Initialize a random number generator.

randf

Generate a random float.

randi

Generate a random integer.

randn

Sample a normal (Gaussian) distribution of mean 0 and variance 1.

randu

Generate a random unsigned integer.

sample_cdf

Inverse-transform sample a cumulative distribution function.

sample_triangle

Uniformly sample a triangle.

sample_unit_cube

Uniformly sample a unit cube.

sample_unit_disk

Uniformly sample a disk in the xy plane.

sample_unit_hemisphere

Uniformly sample a unit hemisphere.

sample_unit_hemisphere_surface

Uniformly sample a unit hemisphere surface.

sample_unit_ring

Uniformly sample a ring in the xy plane.

sample_unit_sphere

Uniformly sample a unit sphere.

sample_unit_sphere_surface

Uniformly sample a unit sphere surface.

sample_unit_square

Uniformly sample a unit square.

Utility#

array

Construct an array from a memory pointer, shape, and data type.

atomic_add

Atomically adds value onto arr[i] and returns the original value of arr[i].

atomic_and

Atomically performs a bitwise AND between value and arr[i], atomically update the array, and return the old value.

atomic_cas

Atomically compare and swap value with arr[i] if arr[i] equals compare, and return the old value.

atomic_exch

Atomically exchange value with arr[i] and return the old value.

atomic_max

Compute the maximum of value and arr[i], atomically update the array, and return the old value.

atomic_min

Compute the minimum of value and arr[i], atomically update the array, and return the old value.

atomic_or

Atomically performs a bitwise OR between value and arr[i], atomically update the array, and return the old value.

atomic_sub

Atomically subtracts value onto arr[i] and returns the original value of arr[i].

atomic_xor

Atomically performs a bitwise XOR between value and arr[i], atomically update the array, and return the old value.

block_dim

Query the number of threads in the current block.

breakpoint

Trigger a debugger breakpoint.

cast

Reinterpret a value as a different type while preserving its bit pattern.

expect_near

Print an error to stdout if a and b differ by more than tolerance.

len

Query the number of elements in a vector.

lerp

Linearly interpolate two values a and b using factor t, computed as a*(1-t) + b*t.

print

Print a variable to stdout.

printf

Allows printing formatted strings using C-style format specifiers.

select

Select between two arguments, if cond is False then return value_if_false, otherwise return value_if_true.

smoothstep

Smoothly interpolate between two values a and b using a factor x, and return a result between 0 and 1 using a cubic Hermite interpolation after clamping.

tid

Query the current thread index or indices.

where

Select between two arguments, if cond is True then return value_if_true, otherwise return value_if_false.

zeros

Create a zero-initialized fixed-size array of the given shape and dtype.

Other#

lower_bound

Search a sorted array arr for the closest element greater than or equal to value.

Operators#

add

Add a and b.

bit_and

Compute the bitwise AND of a and b.

bit_or

Compute the bitwise OR of a and b.

bit_xor

Compute the bitwise XOR of a and b.

div

Divide two values.

floordiv

Divide two scalars using floor division.

invert

Compute the bitwise complement of a.

lshift

Compute a left-shifted by b bits.

mod

Modulo operation using truncated division.

mul

Multiply two values.

neg

Negate x.

pos

Pass x unchanged.

rshift

Compute a right-shifted by b bits.

sub

Subtract b from a.

unot

Compute logical NOT of a.

Code Generation#

static

Evaluate a static Python expression and replaces it with its result.