已关闭
[Bug-Report|缺陷反馈]: [AI 识别] tests/ut/common/tiling_context_faker.cpp 缺少 #include <algorithm> 头文件 #2696
StoneChan_创建于  5月14日关闭于  5月15日
StoneChan_
StoneChan_成员
5月14日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述

项目测试代码存在编译错误,tests/ut/common/tiling_context_faker.cpp 文件使用了 std::find 函数但缺少 #include <algorithm> 头文件,导致无法编译运行完整的单元测试套件。

具体问题

  • 文件位置:tests/ut/common/tiling_context_faker.cpp
  • 错误位置:第301行
  • 错误代码:使用 std::find 但未包含 <algorithm> 头文件

Environment / 环境信息

软件环境:

  • CANN 版本: 9.0.0
  • 操作系统: Debian GNU/Linux 13 (trixie)
  • GCC 版本: 14.2.0
  • CMake 版本: 3.31.6
  • Python 版本: 3.11.15

硬件环境:

  • NPU 型号: Ascend910
  • 服务器型号: A2/A3 服务器

问题环境:

  • 仓库: ops-nn
  • 问题类型: ut_compile_error
  • 问题文件数: 1
  • 问题性质: BUG(编译错误)
  • 影响范围: 单元测试编译失败

Steps to reproduce the issue / 重现步骤

  1. 进入项目目录:cd /mnt/workspace/gitCode/CANN/ops-nn
  2. 检查源代码文件:cat tests/ut/common/tiling_context_faker.cpp | grep -n "std::find"
  3. 发现第301行使用了 std::find
    bool inputPacked = std::find(inputInstanceNum_.begin(), inputInstanceNum_.end(), 0) != inputInstanceNum_.end();
    
  4. 检查头文件包含:cat tests/ut/common/tiling_context_faker.cpp | head -20
  5. 发现仅包含 tiling_context_faker.h,缺少 <algorithm> 头文件
  6. 创建最小化测试验证:
    #include <vector>
    int main() {
        std::vector<int> vec = {1, 2, 3, 0, 4};
        bool found = std::find(vec.begin(), vec.end(), 0) != vec.end();
        return found ? 0 : 1;
    }
    
  7. 编译测试:g++ test.cpp -o test
  8. 编译错误:error: 'find' is not a member of 'std'

Describe the expected behavior / 预期结果

修复建议:在 tests/ut/common/tiling_context_faker.cpp 文件开头添加缺失的头文件:

#include "tiling_context_faker.h"
#include <algorithm>  // 提供 std::find 的定义

预期结果:

  • 单元测试代码能够正常编译
  • 完整的单元测试套件能够运行
  • CI/CD 流程中的自动化测试能够正常执行

问题文件列表

序号 文件路径 问题类型 错误位置
1 tests/ut/common/tiling_context_faker.cpp 缺少头文件 第301行

编译错误信息

/tmp/test_find.cpp: In function 'int main()':
/tmp/test_find.cpp:6:23: error: 'find' is not a member of 'std'
    6 |     bool found = std::find(vec.begin(), vec.end(), 0) != vec.end();
      |                       ^~~~

问题代码片段

// 文件: tests/ut/common/tiling_context_faker.cpp
// 第301行

bool inputPacked = std::find(inputInstanceNum_.begin(), inputInstanceNum_.end(), 0) != inputInstanceNum_.end();

当前头文件包含

// 文件开头仅有:
#include "tiling_context_faker.h"

修复后头文件包含

#include "tiling_context_faker.h"
#include <algorithm>  // 提供 std::find 的定义

Special notes for this issue / 备注

影响范围

  1. 无法编译单元测试代码
  2. 影响开发者的测试和验证工作
  3. 可能影响 CI/CD 流程中的自动化测试
  4. 阻塞完整的单元测试套件执行

技术说明
std::find 是 C++ 标准库 <algorithm> 头文件中定义的算法函数,用于在容器中查找指定元素。使用该函数时必须包含相应的头文件,否则会导致编译失败。

验证结果

  • ✅ 问题确认:已通过最小化测试验证编译错误存在
  • ✅ 修复验证:添加 #include <algorithm> 后编译成功

提交地址: https://gitcode.com/cann/ops-nn/issues/new
Issue 文件: issue.md

likedislike
StoneChan_StoneChan_成员
5月14日 添加了label:bug-report
StoneChan_StoneChan_成员
5月14日 修改了issue 的描述
oscillatedoscillated成员
5月14日 关联了pull request:修复 gcc14 时仓内find函数编译报错的问题
CANN-robotCANN-robot成员
5月15日 关闭了 issue
CANN-robotCANN-robot成员
5月15日 添加了label:resolved