[PHI][CINN] Fix argsort kernel for big tensor #73118
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
PR Category
Operator Mechanism
PR Types
Bug fixes
Description
bug原因
a)thrust::sort_by_key函数不支持大tensor
思考过程
a)目前首先分段进行排序 在对排序后的tensor进行归并操作
b)由于thrust::merge也不支持对大tensor进行merge 所以手写核函数进行实现
代码逻辑改动
a)将原本的thrust::sort_by_key逻辑封装为一个persort函数
b) 手写核函数kernel_merge
c)设置每段大小为1 << 31 -1 当tensor大小小于等于1 << 31 -1时 保持原有逻辑运行
结果如下
由于per_number为2047483647后torch有问题 所以调小数值