helion.language.atomic_add#
- helion.language.atomic_add(target, index, value, sem='relaxed')[source]#
Atomically add a value to a target tensor.
Performs an atomic read-modify-write that adds
valuetotarget[index]. This is safe for concurrent access from multiple threads/blocks.- Parameters:
- Returns:
The previous value(s) stored at
target[index]before the update.- Return type:
Example
@helion.kernel def global_sum(x: torch.Tensor, result: torch.Tensor) -> torch.Tensor:
- for tile in hl.tile(x.size(0)):
hl.atomic_add(result, [0], x[tile].sum())
return result
Notes
Use for race-free accumulation across parallel execution.
Higher memory semantics may reduce performance.