您好,感谢反馈!
问题分析
核对 cann/ops-math@b19eaee4f58e5e1e3cb3b2ecbfed2d02c11c820a 的 SearchSorted AICPU 实现,您指出的空范围解引用路径确实存在:Compute 先调用 GetInputAndCheck;当 sorter 存在且它与 sortedSequence 的元素数同为零时,元素数相等的检查会放行。随后代码对空范围调用 std::max_element、std::min_element 并立即解引用返回迭代器,没有先检查元素数是否为零。空范围的返回值是结束迭代器,不能解引用;数据缓冲为空时还会涉及空指针操作。后面的 CalSearchSorted 空序列分支在校验之后,因此保护不到这里。
接口资料要求 sorter 与序列形状一致,并未用该条件排除 {2,0}。不过,影响范围需按入口区分:当前 ACLNN 实现在参数检查后遇到空序列、空 self 或空 out,会构造 ZerosLike 和输出拷贝任务,并在调用 l0op::SearchSorted 前返回。因此,这份源码中正常经过该空输入分支的 ACLNN 调用会绕开上述 AICPU 校验,不能直接推断所有空张量 ACLNN 调用都会崩溃;这里确认的是进入该 AICPU kernel 时的校验缺口。
处理方向
一个可行的修正是在 sorter 类型与形状/元素数检查之后,仅在 sorter 非空时读取数据并计算索引的最小值、最大值;非空 sorter 还应核对数据指针有效,再检查索引范围。对空 sorter 跳过极值读取时,仍需保留其他输入、输出和形状校验,避免把整个校验函数提前成功返回。验证应覆盖您给出的 {2,0}、其他零元素形状、正常 sorter 和越界索引,并分别核对 AICPU 直接入口与 ACLNN 空输入路径。我们会继续跟踪这一边界校验问题。


SearchSortedKernel::Compute at line 219 calls GetInputAndCheck before any empty-tensor shortcut. When sorter is supplied and both sorted_sequence and sorter have zero elements, the size check at line 119 passes because both counts are zero. The sorter data pointer is fetched at line 126, then lines 127-128 call std::max_element and std::min_element over the empty range and immediately dereference the returned end iterator. For an empty tensor buffer obtained through GetData() this reads outside the valid allocation, and for a null buffer it is a null read. The empty-sequence return in CalSearchSorted at lines 165-169 executes after validation, so it cannot protect this path. The documented contract only requires sorter shape to equal sorted_sequence, which includes an empty shape such as {2,0}.