已合并
feat(op): Add custom op support for __builtin_index_select #1113
candyhong创建于 1月16日
feat(op): Add custom op support for __builtin_index_select #1113
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 candyhong 的贡献)ascend-robot
1月16日 评论:
1月16日 评论:
CANN-robot
1月16日 评论:
1月16日 评论:
ascend-robot
1月16日 评论:
1月16日 评论:
以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入
| Module List | Reviewers | Committers |
|---|---|---|
| repo-Ascend/triton-ascend | gymgit1, HaiLijuan, kang-ingu, chnjz233, saruagithub | zhucehw, ccdedreams, HaiLijuan, wangtao489, shijingchang |


1月16日 添加了label:ascend-cla/yes
此处折叠了45条消息 查看更多
1月16日 解决了最后一个问题
wangzhanpeng5
1月16日 评论:
1月16日 评论:
/lgtm


1月16日 添加了label:lgtm
ascend-robot
1月16日 评论:
1月16日 评论:
Review Guide
This Pull-Request Passes Review.
Committers who wrote a comment of /approve are: zhang-chunli01.
Reviewers who wrote a comment of /lgtm are: zhang-chunli01, wangzhanpeng5.


1月16日 合入了pull request
Background
This PR adds custom op support for
__builtin_index_select, whose semantics align withtorch.index_select.This change improves the expressiveness of index-related kernels and enables more general indexing patterns in Triton custom ops.
Interface Introduction
The operator gathers elements from a source tensor in Global Memory (GM) into an output tensor in Unified Buffer (UB) using indices provided in UB along a specified dimension.
Usage Example
@triton.jit def builtin_index_select_kernel(src_ptr, index_ptr, out_ptr): # Define 2x2 tile indices for output tensor r = tl.arange(0, 2)[:, None] # Row indices: shape [2, 1] c = tl.arange(0, 2)[None, :] # Column indices: shape [1, 2] # Load index tensor (shape [2]) from GM to UB idx = tl.load(index_ptr + tl.arange(0, 2)) # Initialize empty 2x2 output tile in UB (default value: 0) dst = tl.full((2, 2), 0, dtype=tl.float32) # Invoke __builtin_index_select custom op to gather elements out_tile = al.custom( "__builtin_index_select", src_ptr, # Pointer to source tensor in GM idx, # Index tensor (in UB) for gathering dim=0, # Dimension to gather along bound=4, # Upper bound for valid index values (out-of-bound check) end_offset=(2, 2),# End offsets of each dimension for the index tensor start_offset=(0, 0), # Start offsets of each dimension for the source tensor src_stride=(4, 1),# Stride of each dimension for the source tensor in GM out=dst # Output tensor (in UB) to store gathered elements ) # Store the gathered tile from UB to output tensor in GM tl.store(out_ptr + r * 2 + c, out_tile)Checklist
/testforlittests/unittestfor C++ tests/python/testfor end-to-end tests