triton.language.load_tensor_descriptor#
- triton.language.load_tensor_descriptor(desc: tensor_descriptor_base, offsets: Sequence[constexpr | tensor], _semantic=None) tensor#
Load a block of data from a tensor descriptor.
示例
import torch import triton import triton.language as tl @triton.jit def copy_kernel(in_ptr, out_ptr, M, N, M_BLOCK: tl.constexpr, N_BLOCK: tl.constexpr): """ Copy a 2D tensor blockwise using the functional tl.load_tensor_descriptor / tl.store_tensor_descriptor interface. """ in_desc = tl.make_tensor_descriptor( in_ptr, shape=[M, N], strides=[N, 1], block_shape=[M_BLOCK, N_BLOCK], ) out_desc = tl.make_tensor_descriptor( out_ptr, shape=[M, N], strides=[N, 1], block_shape=[M_BLOCK, N_BLOCK], ) moffset = tl.program_id(0) * M_BLOCK noffset = tl.program_id(1) * N_BLOCK block = tl.load_tensor_descriptor(in_desc, [moffset, noffset]) tl.store_tensor_descriptor(out_desc, [moffset, noffset], block) def test_load_tensor_descriptor(): M, N = 64, 128 M_BLOCK, N_BLOCK = 16, 32 inp = torch.arange(M * N, dtype=torch.float32, device='npu').reshape(M, N) out = torch.empty(M, N, dtype=torch.float32, device='npu') grid = (M // M_BLOCK, N // N_BLOCK) copy_kernel[grid](inp, out, M, N, M_BLOCK, N_BLOCK) torch.testing.assert_close(out, inp) if __name__ == "__main__": test_load_tensor_descriptor()
数据类型支持
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
√
√
√
√
√
√
√
√
√
√
×
√
√
√
×
特殊说明
make_tensor_descriptor, load_tensor_descriptor and store_tensor_descriptor. Do not mix them with tl.load() or tl.store().