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

Return the absolute value of x.

acos

Return arccos of x in radians.

asin

Return arcsin of x in radians.

atan

Return the arctangent of x in radians.

atan2

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

cbrt

Return the cube root of x.

ceil

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

clamp

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

cos

Return the cosine of x in radians.

cosh

Return the cosh of x.

degrees

Convert x from radians into degrees.

erf

Return the error function of x.

erfc

Return the complementary error function of x.

erfcinv

Return the inverse complementary error function of x.

erfinv

Return the inverse error function of x.

exp

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

floor

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

frac

Retrieve the fractional part of x.

isfinite

Return True if a is a finite number, otherwise return False.

isinf

Return True if a is positive or negative infinity, otherwise return False.

isnan

Return True if a is NaN, otherwise return False.

log

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

log2

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

log10

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

max

Return the maximum of two scalars.

min

Return the minimum of two scalars.

nonzero

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

pow

Return the result of x raised to power of y.

radians

Convert x from degrees into radians.

rint

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

round

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

sign

Return -1 if x < 0, return 1 otherwise.

sin

Return the sine of x in radians.

sinh

Return the sinh of x.

sqrt

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

step

Return 1.0 if x < 0.0, return 0.0 otherwise.

tan

Return the tangent of x in radians.

tanh

Return the tanh of x.

trunc

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

Vector Math#

argmax

Return the index of the maximum element of a vector a.

argmin

Return the index of the minimum element of a vector a.

cross

Compute the cross product of two 3D vectors.

cw_div

Component-wise division of two vectors.

cw_mul

Component-wise multiplication of two vectors.

ddot

Compute the double dot product between two matrices.

determinant

Return the determinant of a 2x2 matrix a.

diag

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

dot

Compute the dot product between two vectors.

eig3

Compute the eigendecomposition of a 3x3 matrix A.

get_diag

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

identity

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

inverse

Return the inverse of a 2x2 matrix a.

length

Compute the length of a floating-point vector a.

length_sq

Compute the squared length of a vector a.

matrix

Construct a matrix.

matrix_from_cols

Construct a matrix from column vectors.

matrix_from_rows

Construct a matrix from row vectors.

norm_huber

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

norm_l1

Computes the L1 norm of a vector v.

norm_l2

Computes the L2 norm of a vector v.

norm_pseudo_huber

Computes 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

Normalizes 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

Return the trace of the matrix a.

transpose

Return the transpose of the 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 3x3 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 zero-initialized 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

Return the rotational part of a transform xform.

transform_get_translation

Return the translational part of a 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 the transform to a point point treating the homogeneous coordinate as w=1 (translation and rotation).

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 the transform to a vector vec treating the homogeneous coordinate as w=0 (rotation only).

transformation

Construct a rigid-body transformation with translation part p and rotation q.

Spatial Math#

spatial_adjoint

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

spatial_bottom

Return 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

spatial_mass

spatial_top

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

spatial_vector

Zero-initialize 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

Return 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, each element will be updated atomically.

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

With L such that LL^T = A, solve for x in Ax = y

tile_cholesky_solve_inplace

With L such that LL^T = A, 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

Loads a tile from a global memory array.

tile_load_indexed

Loads 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 unary function onto the tile.

tile_matmul

Computes the matrix product and accumulates out = alpha * a*b + beta * out.

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 the tile.

tile_reshape

Return 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

Return 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 using all threads in the block.

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

Return 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

Finds the closest points between two edges.

hash_grid_point_id

Return 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

Tests for intersection between two triangles (v0, v1, v2) and (u0, u1, u2) using Moller's method.

mesh_eval_face_normal

Evaluates the face normal the mesh given a face index.

mesh_eval_position

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

mesh_eval_velocity

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

mesh_get

Retrieves the mesh given its index.

mesh_get_group_root

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

mesh_get_index

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

mesh_get_point

Returns the point of the mesh given a index.

mesh_get_velocity

Returns the velocity of the mesh given a 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

Computes the furthest point on the mesh with identifier id to the given point in space.

mesh_query_point

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

mesh_query_point_no_sign

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

mesh_query_point_sign_normal

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

mesh_query_point_sign_parity

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

mesh_query_point_sign_winding_number

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

mesh_query_ray

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

mesh_query_ray_anyhit

Returns True immediately upon the first 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.

Utility#

array

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

Returns the number of threads in the current block.

breakpoint

Debugger breakpoint

cast

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

expect_near

Prints an error to stdout if a and b are not closer than tolerance in magnitude

len

Return 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 variable to stdout

printf

Allows printing formatted strings using C-style format specifiers.

reversed

Returns the range in reversed order.

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

Return the current thread index for a 1D kernel launch.

where

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

zeros

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

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

volume_lookup_f

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

volume_lookup_i

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

volume_lookup_index

Returns the index associated to the voxel with coordinates i, j, k.

volume_lookup_v

Returns 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 the gradient of a Perlin noise function.

noise

Non-periodic Perlin-style noise in 1D.

pnoise

Periodic Perlin-style noise in 1D.

poisson

Generate a random sample from a Poisson distribution.

rand_init

Initialize a new random number generator given a user-defined seed.

randf

Return a random float between [0.0, 1.0).

randi

Return a random integer in the range [-2^31, 2^31).

randn

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

randu

Return a random unsigned integer in the range [0, 2^32).

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.

Other#

lower_bound

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

Operators#

add

bit_and

bit_or

bit_xor

div

floordiv

invert

lshift

mod

Modulo operation using truncated division.

mul

neg

pos

rshift

sub

unot

Code Generation#

static

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