[CINN]Fix compilation cache re-use same fn_ptr wrongly #64718
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
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.

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

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