已合并
refactor(fa): 删除op_kernel头文件的__has_include守卫, 统一使用attention/common路径 #11073
refactor(fa): 删除op_kernel头文件的__has_include守卫, 统一使用attention/common路径 #11073
已合并
jiang-lirui创建于 25 天前
jiang-lirui成员
25 天前

描述

在 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

这种方式维护不便,而且这是编译工程问题,不应该传递带算子层

关联的Issue

Issue #4407

测试

按README.md中的Quick Start操作,执行用例时加--graph_mode参数可使能在线编译,编译不报错表明正确

python3 test_flash_attn.py --case_files functional_redline_infer --case_id Decode_Unquant_BF16_BF16_L0_1_5_1_1_2048_BNSD_BSND_000004 --graph_mode --device_id 0 

已验证编译OK

文档更新

不涉及

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 jiang-lirui 的贡献)
Jjiang-lirui成员
25 天前 创建了 pull request,commit 171ed286
atomgit-bot
atomgit-bot
25 天前 评论:

变更摘要

本 PR 是一次纯重构改动(refactor(fa)),针对 attention/flash_attn/op_kernel 目录下的头文件,删除其中用于头文件路径兼容的 __has_include 条件编译守卫及其 #else 分支(旧的 ../../common/... 回退路径),统一改为只保留 ../../../common/op_kernel/... 这一条标准 include 路径(即 attention/common 路径),消除冗余的双路径维护逻辑。改动共涉及 8 个文件,全部为删除代码(净删除 57 行),无新增逻辑,不改变任何头文件的实际包含目标。

主要改动

  • 移除 matmul.h 的 __has_include 守卫:在 flash_attn_block_cube_dn.h 与 flash_attn_block_cube_nd.h 中删除了 #if __has_include("../../../common/op_kernel/matmul.h") 及其 #else 回退分支,统一直接包含 ../../../common/op_kernel/matmul.h。
  • 统一 arch35 相关公共头文件的包含路径:在 flash_attn_block_vec_dn.h 与 flash_attn_block_vec_nd.h 中删除 __has_include 守卫及整段 #else 分支(flash_attention_score_common_regbase_arch35.h、vf_mul_sel_softmaxflashv2_cast_nz.h 等旧路径包含),仅保留 ../../../common/op_kernel/arch35/... 路径。
  • 精简 vf_flash_decode_arch35.h 与 memory_copy_arch35.h 的条件包含:flash_attn_block_vec_flashdecode.h 删除了对 vf_flash_decode_arch35.h 的 __has_include 判断;memory_copy_arch35.h 删除了对 vector_common.h、fa_gm_tensor.h、attn_copy_gm_to_l1.h、copy_ub_to_gm.h 的条件包含及旧路径分支。
  • 统一入口文件与类型头文件的包含方式:flash_attn.cpp 与 flash_attn_type.h 中删除对 flash_attention_score_common_regbase_arch35.h 的 __has_include 守卫及 ../common/arch35/... 回退路径,统一使用 ../../../common/op_kernel/arch35/...。
likedislike
不准确?
CANN-robotCANN-robot成员
25 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
25 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
25 天前 评论:

CLA Signature Pass

jiang-lirui, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了54条消息 查看更多
CANN-robotCANN-robot成员
23 天前 添加了label:approved
赵志勇成员
23 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
23 天前 添加了label:lgtm
CANN-robotCANN-robot成员
23 天前 关闭了关联的issue
CANN-robotCANN-robot成员
23 天前 合入了pull request