Enceladus v0.1.0 · alpha
Language builtinsReference pages
Language builtinsHost APIData types and tilesEnvironment variables

Reference

Language builtins

Every builtin in enceladus.language, imported as tl. Tile shapes must be compile-time powers of two. Most math and shape functions are also tile methods, for example x.exp(), x.sum(axis=0), x.to(tl.float16), and x.T.

Programs

tl.program_id(axis)

Returns the index of the current program along axis 0, 1, or 2.

tl.num_programs(axis)

Returns the number of programs in the grid along axis 0, 1, or 2.

Tile creation

Shapes must be compile-time powers of two.

tl.arange(start, end)

Returns an int32 tile of [start, end). The bounds are compile-time, and end - start is a power of two.

tl.full(shape, value, dtype)

Returns a tile filled with a scalar, which can be a literal or a runtime value.

tl.zeros(shape, dtype)

Returns a tile filled with zeros.

tl.full_like(input, value, dtype=None)

Returns a tile with the shape of input, filled with value.

tl.zeros_like(input)

Returns zeros with the shape and dtype of input.

Memory

tl.load(pointer, mask=None, other=None, boundary_check=(), padding_option='', cache_modifier='', eviction_policy='', volatile=False)

Loads through a pointer or pointer tile. Masked-off lanes return other, or 0. Cache and eviction hints are accepted and ignored.

tl.store(pointer, value, mask=None, boundary_check=(), cache_modifier='', eviction_policy='')

Stores where mask is true. The value is converted to the pointee dtype and broadcast.

tl.debug_barrier()

Waits for every thread of the program and makes their earlier device memory stores visible to all of them.

Tensor descriptors

tl.make_tensor_descriptor(base, shape, strides, block_shape, padding_option='zero')

Creates a bounds-checked block descriptor over a pointer. The last stride must be 1.

desc.load(offsets)

Loads the block at element offsets. Elements outside the array are zero.

desc.store(offsets, value)

Stores the block at element offsets and skips elements outside the array.

desc.dtype, desc.block_shape

The element type and the block shape of the descriptor.

Elementwise

Arguments broadcast to one shape.

tl.where(condition, x, y)

Picks x where condition is true and y elsewhere.

tl.maximum(x, y)

Returns the elementwise maximum. A NaN operand yields the other operand.

tl.minimum(x, y)

Returns the elementwise minimum. A NaN operand yields the other operand.

tl.clamp(x, min, max)

Returns minimum(maximum(x, min), max).

tl.fma(x, y, z)

Returns x * y + z with a single rounding.

tl.abs(x)

Returns the elementwise absolute value.

tl.cdiv(x, div)

Returns (x + div - 1) // div, the number of blocks that cover x.

Math

Float inputs only. 16-bit floats compute in float32 and round back. Each is also a tile method.

tl.exp(x), exp2(x)

Returns e or 2 raised to the power x.

tl.log(x), log2(x)

Returns the natural or base-2 logarithm.

tl.sqrt(x), tl.rsqrt(x)

Returns the square root or its reciprocal.

tl.sin(x), tl.cos(x)

Returns the sine or cosine of x in radians.

tl.tanh(x)

Returns the hyperbolic tangent.

tl.sigmoid(x)

Returns 1 / (1 + exp(-x)).

tl.erf(x)

Returns the Gauss error function.

tl.floor(x), tl.ceil(x)

Rounds down or up to an integer value.

Type conversion

tl.cast(x, dtype, bitcast=False, fp_downcast_rounding=None)

Converts x to dtype, or reinterprets its bits when bitcast is true. Float to integer truncates toward zero.

x.to(dtype)

Same as cast. Converting to int1 gives x != 0.

Shape

tl.broadcast_to(input, *shape)

Broadcasts input to shape.

tl.expand_dims(input, axis)

Inserts size-1 dimensions at axis, an int or a tuple of ints.

tl.reshape(input, *shape, can_reorder=False)

Reshapes in row-major order. Every dimension must be a power of two.

tl.trans(input, *dims)

Permutes dimensions, or reverses them when no dims are given. Same as x.T.

tl.permute(input, *dims)

Permutes dimensions into the order dims.

tl.join(a, b)

Stacks a and b along a new last dimension of size 2. Same as a.join(b).

tl.split(a)

Splits a along its last dimension, which must be 2, into (a[..., 0], a[..., 1]). Same as a.split().

Reductions

tl.sum(input, axis=None, keep_dims=False, dtype=None)

Sums along axis, or over all elements. 16-bit floats accumulate in float32.

tl.max(input, axis=None, return_indices=False, return_indices_tie_break_left=True, keep_dims=False)

Returns the maximum, and optionally the int32 index of the first maximum. NaNs are ignored.

tl.min(input, axis=None, return_indices=False, return_indices_tie_break_left=True, keep_dims=False)

Returns the minimum, and optionally the int32 index of the first minimum.

tl.argmax(input, axis, tie_break_left=True, keep_dims=False)

Returns the int32 index of the first maximum.

tl.argmin(input, axis, tie_break_left=True, keep_dims=False)

Returns the int32 index of the first minimum.

tl.reduce(input, axis, combine_fn, keep_dims=False)

Reduces a tile or tuple of tiles with an associative, commutative @jit combine_fn.

Scans

Inclusive prefix scans.

tl.cumsum(input, axis=0, reverse=False, dtype=None)

Returns the inclusive cumulative sum, or the suffix sum when reverse is true.

tl.associative_scan(input, axis, combine_fn, reverse=False)

Scans a tile or tuple of tiles with an associative @jit combine_fn.

Matrix multiplication

tl.dot(input, other, acc=None, input_precision=None, allow_tf32=None, max_num_imprecise_acc=None, out_dtype=tl.float32)

Returns input @ other + acc for 2D tiles of the same float dtype. The accumulator is float32 or float16, and K must be a multiple of 8. Launch options dot_warps and dot_backend control the lowering.

Atomics

Each returns the previous values, or 0 where mask is false. Ordering is relaxed.

tl.atomic_add(pointer, val, mask=None, sem=None, scope=None)

Adds val atomically. 16-bit floats aren't supported.

tl.atomic_max(pointer, val, mask=None, sem=None, scope=None)

Stores the maximum atomically. A NaN operand is ignored.

tl.atomic_min(pointer, val, mask=None, sem=None, scope=None)

Stores the minimum atomically. A NaN operand is ignored.

tl.atomic_xchg(pointer, val, mask=None, sem=None, scope=None)

Stores val atomically and returns the old values.

tl.atomic_and(pointer, val, mask=None, sem=None, scope=None)

Applies a bitwise AND atomically. Integers only.

tl.atomic_or(pointer, val, mask=None, sem=None, scope=None)

Applies a bitwise OR atomically. Integers only.

tl.atomic_xor(pointer, val, mask=None, sem=None, scope=None)

Applies a bitwise XOR atomically. Integers only.

tl.atomic_cas(pointer, cmp, val, sem=None, scope=None)

Stores val where memory equals cmp bitwise, and returns the old values. Takes no mask.

Compiler hints

Each returns its input unchanged. A false promise gives wrong results; ENCELADUS_DEBUG=1 checks it in the interpreter.

tl.multiple_of(input, values)

Promises that input holds multiples of values, or runs of consecutive values that start at one. Pointers count bytes.

tl.max_contiguous(input, values)

Promises that every aligned group of values elements holds consecutive values.

Loops and compile time

tl.range(start, end=None, step=None, num_stages=None, ...)

A runtime for-loop range. Triton pipelining hints are accepted and ignored.

tl.static_range(start, end=None, step=None)

A loop range that the compiler unrolls. The bounds must be compile-time values.

tl.static_assert(cond, msg='')

Raises CompilationError if the compile-time cond is false.

tl.static_print(*values, sep=' ')

Prints compile-time values while the kernel compiles.

tl.constexpr

Annotates a parameter as a compile-time constant, as in BLOCK: tl.constexpr.

Debugging

tl.device_print(prefix, *args, hex=False)

Prints runtime values, one line per element, to stderr when the stream synchronizes.

tl.device_assert(cond, msg='', mask=None)

Checks cond on the GPU when ENCELADUS_DEBUG=1 and raises DeviceAssertionError at the next sync.