warp.build_experimental.add_native_type#

warp.build_experimental.add_native_type(ctype, *, native_name, fields=None, initializer=None)[source]#

Register an external C++ value type for use in Warp kernels.

Experimental: this API may change without deprecation in future releases.

The Python type must be a ctypes.Structure with the same size, alignment, and field layout as the C++ type. Warp verifies the size and alignment during compilation. CPU compilation also verifies exposed field offsets; CUDA compilation verifies exposed field sizes. The C++ type must be standard-layout and trivially copyable.

Parameters:
  • ctype (type[Structure]) – Host ABI description and Python value class.

  • native_name (str) – Exact qualified C++ type name.

  • fields (Mapping[str, type] | None) – Ordered mapping of public C++ data members to Warp types. Omit this for an opaque value type.

  • initializer (str | None) – Set to "aggregate" to allow construction from all fields in kernels. In this mode, fields must list every ctypes field in declaration order. Default construction is always allowed.

Returns:

ctype, which is used directly as the Warp annotation and array dtype.

Return type:

type[Structure]