triton.language.sin#
- triton.language.sin(x, _semantic=None)#
Computes the element-wise sine of
x.- 参数:
x (Block) -- the input values
示例
import triton import triton.language as tl import torch def torch_sin(x0): res = torch.sin(x0) return res @triton.jit def triton_sin(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr, XBLOCK_SUB: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK for xoffset_sub in range(0, XBLOCK, XBLOCK_SUB): x_index = xoffset + xoffset_sub + tl.arange(0, XBLOCK_SUB) xmask = x_index < xnumel tmp0 = tl.load(in_ptr0 + x_index, xmask) tmp1 = tl.sin(tmp0) tl.store(out_ptr0 + x_index, tmp1, xmask) def test_sin(): param_list = ['float32', (2, 4096, 8), 2, 32768, 1024] dtype, shape, ncore, xblock, xblock_sub = param_list x0 = torch.randn(size=shape, dtype=eval('torch.' + dtype)).npu() torch_res = torch_sin(x0) triton_res = torch.empty_like(x0) triton_sin[ncore, 1, 1](x0, triton_res, x0.numel(), xblock, xblock_sub) torch.testing.assert_close(torch_res, triton_res, rtol=1e-04, atol=1e-04, equal_nan=True) if __name__ == '__main__': test_sin()
数据类型支持
uint8
int8
uint16
int16
uint32
int32
uint64
int64
fp16
fp32
fp64
bf16
fp8e(e4m3)
fp8e5(e5m2)
bool
Atlas A2 products/Atlas A3 products
×
×
×
×
×
×
×
×
×
√
×
×
×
×
×
Ascend 950PR&950DT products
×
×
×
×
×
×
×
×
×
√
×
×
×
×
×