cuda.tile.wrapping_add#

cuda.tile.wrapping_add(x, y, /)#

Elementwise integer addition that wraps around on overflow.

Parameters:
  • x (Tile) – LHS tile.

  • y (Tile) – RHS tile.

The shape of x and y will be broadcasted. Unlike add(), the dtypes are not promoted: x and y must have the same integer dtype, and the result is computed modulo 2**bitwidth of that dtype. A loosely typed constant is converted to the dtype of the other operand, also modulo 2**bitwidth: for example, -1 becomes 255 for uint8.

At least one of the operands must have a concrete dtype, since loosely typed constants don’t have a bit width. For example, ct.wrapping_add(1, 2) is an error, but ct.wrapping_add(ct.uint8(150), 110) is ct.uint8(4).

Return type:

Tile

Examples

tx = ct.arange(4, dtype=ct.int8)
print(ct.wrapping_add(tx, 126))
import cuda.tile as ct
import torch

@ct.kernel
def kernel():
    tx = ct.arange(4, dtype=ct.int8)
    print(ct.wrapping_add(tx, 126))


torch.cuda.init()
ct.launch(torch.cuda.current_stream(), (1,), kernel, ())
torch.cuda.synchronize()

Output

[126, 127, -128, -127]