Skip to content

Conversation

@baoqiwen
Copy link
Contributor

@baoqiwen baoqiwen commented Apr 7, 2025

PR Category

CINN

PR Types

Bug fixes

Description

Pcard-89071

向量化索引中包含 a % b,但是b % factor != 0的场景存在索引越界,例子:
image

该patch删除了tensor_is_continuous的代码:
paddle/cinn/ir/group_schedule/config/group_tile_util.cc的GetGroupVectorizeInfo保证,“存在非连续的变量,can_vectorize就为false”,不需要在后续代码中再次判断非连续了,故删除旧代码。

CheckTensorAddrLegalCastToVectorize的逻辑:
[a, b, c, d, e] + [a, 1, c, 1, e](shape为1的维度做broadcast)
这俩者相加,计算索引的代码会出现%e/(d*e)等(包括%(c*d*e),但只需要找到最小的除余或除号后面的数)。

if (e % factor == 0) {
  // 做向量化
} else {
  // 做向量化会出现地址越界,因此不做向量化
}

对于offset_is_zero:
1)CheckTensorAddrLegalCastToVectorize能处理最低维做广播的情况:
shape为[a, b, c, d] + [a, b, 1, 1]的场景,能通过判断flattened_value % vectorize_factor != 0,剔除这个情况。
2)CheckTensorAddrLegalCastToVectorize无法处理shape.size() = 1的情况
shape为[b]和[a, b, c, d]两个tensor发生计算关系,无法处理。所以保留了旧代码CheckTensorOffsetZero。

@paddle-bot
Copy link

paddle-bot bot commented Apr 7, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@baoqiwen baoqiwen force-pushed the bqw_vector branch 4 times, most recently from b9ae2a2 to b55f42a Compare April 8, 2025 09:41
@lshpku lshpku merged commit 018ffdd into PaddlePaddle:develop Apr 9, 2025
32 checks passed
YqGe585 pushed a commit to YqGe585/Paddle that referenced this pull request May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants