已关闭
flash_attn.cpp 中条件编译路径存在头文件引用不一致风险 #4407
崇理战队创建于 27 天前关闭于 11 天前
weihao18
27 天前 评论:
27 天前 评论:
/assign @jiang-lirui


27 天前 将 jiang-lirui 设为负责人
jiang-lirui
27 天前 评论:
27 天前 评论:
感谢你的建议!需要解释的是:这并不是在include两份文件,else分支是为在线编译场景准备的,因打包路径问题,在该场景下源码路径发生了变化;但是我们已经意识到这种写法不太合适,将推动编译工程适配后,修改为实际所见路径。


14 天前 将 hblnb 设为负责人
14 天前 关联了pull request:修改cann包下算子kernel源码的路径,多加一级op_kernel
14 天前 删除了关联的pull request:修改cann包下算子kernel源码的路径,多加一级op_kernel
13 天前 关联了pull request:修改cann包下算子kernel源码的路径,多加一级op_kernel
huangbolin
13 天前 评论:
13 天前 评论:
已关联pr,目前基于该pr出的包里面的文件结构和代码仓一致,验证功能中


Jjiang-lirui
13 天前 关联了pull request:refactor(fa): 删除op_kernel头文件的__has_include守卫, 统一使用attention/common路径
13 天前 关联了pull request:refactor(fa): 删除op_kernel头文件的__has_include守卫, 统一使用attention/common路径
11 天前 关闭了 issue
11 天前 添加了label:resolved
问题描述
在
attention/flash_attn/op_kernel/flash_attn.cpp中,存在以下条件编译代码:#if __has_include("../../common/op_kernel/arch35/flash_attention_score_common_regbase.h") #include "../../common/op_kernel/arch35/flash_attention_score_common_regbase.h" #else #include "../common/arch35/flash_attention_score_common_regbase.h" #endif这种基于
__has_include的条件编译方式存在以下风险:../../common/和../common/的相对路径依赖于文件在目录结构中的精确位置,一旦目录结构调整(如算子目录重组),可能导致编译失败。#include "common/..."或#include "../common/..."。建议方案
target_include_directories管理头文件搜索路径,避免在源码中使用相对路径条件编译。flash_attention_score_common_regbase.h提取到公共 include 目录,统一引用路径。相关文件
attention/flash_attn/op_kernel/flash_attn.cppattention/common/arch35/flash_attention_score_common_regbase.h