已关闭
[Requirement|需求建议]: CheckType和ToString支持其他C++标准容器,比如vector或者array #256
xubinglin创建于  7月9日关闭于  6 天前
xubinglin
7月9日 创建

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

Backgroud(背景信息)

背景
当前 OP_CHECK_DTYPE_NOT_SUPPORT 依赖两类 opbase 接口:

CheckType(tensor->GetDataType(), supportList)
op::ToString(supportList)

CheckType 和 dtype-list 版 op::ToString 目前只支持 std::initializer_list<DataType>。业务侧为了复用 dtype 列表,把它写成 .h 中的 static const std::initializer_list 常量。标准层面安全,但 initializer_list 是 view 类型,作为头文件长期常量表达不直观,也容易引发生命周期争议。

修复目标
希望业务侧固定 dtype 列表可以改成更明确的拥有型/编译期容器,例如:

inline constexpr std::array<op::DataType, 2> IN_TYPE_SUPPORT_LIST = {
    op::DataType::DT_INT4, op::DataType::DT_INT8
};

并且仍能直接使用现有宏:

OP_CHECK_DTYPE_NOT_SUPPORT(x, IN_TYPE_SUPPORT_LIST, return false);

对 opbase 的诉求
需要在 include/nnopbase/opdev/data_type_utils.h 层统一扩展,而不是在业务仓新增 _FOR_VEC 宏。

  1. CheckType 支持标准容器:

    bool CheckType(DataType dtype, std::initializer_list<DataType> validTypes);
    
    template <size_t N>
    bool CheckType(DataType dtype, const std::array<DataType, N>& validTypes);
    
    bool CheckType(DataType dtype, const std::vector<DataType>& validTypes);
    
  2. op::ToString 支持同样的 dtype-list 类型:

    ge::AscendString ToString(std::initializer_list<DataType> dataTypes);
    
    template <size_t N>
    ge::AscendString ToString(const std::array<DataType, N>& dataTypes);
    
    ge::AscendString ToString(const std::vector<DataType>& dataTypes);
    
  3. 内部实现可以共用一个受限 helper:

    template <typename Range>
    // 限定元素类型为 DataType,避免污染 op::ToString 重载集
    
  4. 补充接口文档。当前 ToString(std::initializer_list<DataType>) 已声明和实现,但没有对外文档;如果宏事实依赖它,应明确记录 dtype-list 支持范围。

Origin(信息来源)

昇腾算子部门

Benefit / Necessity (价值/作用)

Design(设计方案)

likedislike
songkai111成员
7月10日 评论:

你好,已纳入Q3 roadmap

likedislike
Rren-botao成员
7 天前 关联了pull request:data_type_utils.h: CheckType/ToString 扩展支持 std::vector 与 std::array 重载
CANN-robotCANN-robot成员
6 天前 关闭了 issue
CANN-robotCANN-robot成员
6 天前 添加了label:resolved