helion.language.zeros

helion.language.zeros(shape, dtype=torch.float32)[source]

Return a device-tensor filled with zeros.

Equivalent to hl.full(shape, 0.0 if dtype.is_floating_point else 0, dtype=dtype).

Note

Only use within hl.tile() loops for creating local tensors. For output tensor creation, use torch.zeros() with proper device placement.

Parameters:
  • shape (list[object]) – A list of sizes (or tile indices which are implicitly converted to sizes)

  • dtype (dtype) – Data type of the tensor (default: torch.float32)

Returns:

A device tensor of the given shape and dtype filled with zeros

Return type:

torch.Tensor

Examples

@helion.kernel
def process_kernel(input: torch.Tensor) -> torch.Tensor:
    result = torch.empty_like(input)

    for tile in hl.tile(input.size(0)):
        buffer = hl.zeros([tile], dtype=input.dtype)  # Local buffer
        buffer += input[tile]  # Add input values to buffer
        result[tile] = buffer

    return result

See also

  • full(): For filling with arbitrary values

  • arange(): For creating sequences