warp.address_of#

warp.address_of(expr)[source]#

Return the address of an addressable expression as a warp.uint64.

Only valid inside @warp.kernel and @warp.func bodies. The codegen intercepts this call and emits a pointer cast; it is not a normal Python function and cannot be called from regular Python code.

Accepted expressions: local variables, array elements (arr[i]), struct fields (s.field), and warp.ref[T] parameters. Literals and function-call results are rejected with a WarpCodegenError at compile time.

Use array.ptr for the base pointer of an entire warp.array. Use warp.address_of(arr[i]) when the pointer to a specific element is needed.

Returns:

The address of the expression’s storage.

Return type:

warp.uint64

Raises:

RuntimeError – Always, when called from regular Python (outside a kernel or func body).

Example:

@wp.func_native("*(int32_t*)ptr = 42;")
def set_via_ptr(ptr: wp.uint64): ...


@wp.kernel(enable_backward=False)
def my_kernel(result: wp.array[wp.int32]):
    val = wp.int32(0)
    set_via_ptr(wp.address_of(val))
    result[0] = val  # writes 42