cuda.tile.wrapping_sub#
- cuda.tile.wrapping_sub(x, y, /)#
Elementwise integer subtraction that wraps around on overflow.
The shape of x and y will be broadcasted. Unlike
sub(), 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_sub(1, 2)is an error, butct.wrapping_sub(ct.uint8(0), 1)isct.uint8(255).- Return type:
Examples
tx = ct.arange(4, dtype=ct.int8) print(ct.wrapping_sub(-127, tx))
import cuda.tile as ct import torch @ct.kernel def kernel(): tx = ct.arange(4, dtype=ct.int8) print(ct.wrapping_sub(-127, tx)) torch.cuda.init() ct.launch(torch.cuda.current_stream(), (1,), kernel, ()) torch.cuda.synchronize()
Output
[-127, -128, 127, 126]