Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CINN]Fix compilation cache re-use same fn_ptr wrongly #64718

Merged
merged 2 commits into from
May 30, 2024

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented May 29, 2024

PR Category

CINN

PR Types

Bug fixes

Description

Pcard-67164

问题背景

在科学计算LDC模型上,关闭缓存,如下kernel有8个:fn_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_add_elementwise_add_yield_store_elementwise_mul_elementwise_add_elementwise_add_elementwise_add_elementwise_add_elementwise_add_

开启缓存,如下kernel会复用成1个:fn_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_mul_elementwise_add_elementwise_add_yield_store_elementwise_mul_elementwise_add_elementwise_add_elementwise_add_elementwise_add_elementwise_add__2

对应是如下两个子图Case,其实在计算%16时,依赖的上游算子顺序是有差别的,一个是L6+L7+L8,一个是L5+L7+L8.
image

这几个上游算子,其实从Op层面,他们的ValueInfo、OpInfo完全一样的(即Hash一样),但内在中间算子依赖的顺序不同,对于生成的函数,可能导致输入Argument Tensor解析&映射的顺序有差异,会导致下图中两个红框的CodeGen函数代码段有不同的var,若命中缓存,则引起计算错误。
image

解决方案

fusion_info.cc中的FusionOpInfo数据结构里inner_deps_除了要考虑依赖的上游算子hash,也要考虑依赖的上游算子index

Copy link

paddle-bot bot commented May 29, 2024

你的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.

@@ -20,7 +20,7 @@
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"

static constexpr float kAtolValue = 1e-5;
static constexpr float kAtolValue = 1e-8;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处 atol 和 rtol 的阈值与numpy.allclose的默认值对齐

@Aurelius84 Aurelius84 requested review from phlrain and cxxly May 30, 2024 05:59
Copy link
Contributor

@cxxly cxxly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aurelius84 Aurelius84 merged commit a93f26e into PaddlePaddle:develop May 30, 2024
32 checks passed
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.

None yet

3 participants