已合并
feat(jit): support pointer and struct tiling constants #5719
feat(jit): support pointer and struct tiling constants #5719
已合并
XuebinYang创建于 2 天前
XuebinYang成员
2 天前

描述

JIT 常量化编译此前要求所有 constant_infos 项提供 byte_size,并与 argsBytes 严格相等,无法表达按值传递的结构体 tiling。

新增 constant_infos[].arg_type,支持 pointer 和 struct,缺省为 struct。ACLNN manifest 生成器固定输出 arg_type: pointer 和按 kernel 确定的 byte_size,不提供类型配置。pointer 常量使用 manifest 的 byte_size;struct 常量只使用 argsBytes[parameter_index],禁止在 manifest 中提供 byte_size。pack validator 和运行时均拒绝 struct 携带 byte_size。

公用 ManifestConstant 类统一 exporter 与 runtime 的 constant 字段契约。ParseDefinition 解析并校验定义,BindArgument 绑定参数地址与大小,屏蔽 pointer/struct 差异;私有成员维护解析及绑定状态,失败保留原状态,重新解析成功后清除旧绑定。错误直接记录 plog。删除 ConstantSizeRule 和自由解析入口,模块兼容 C++11,不依赖 ACLRTC。

ACLRTC 计划构建按解析和绑定两个职责封装。CompilationManifestParser 选择本次 kernel 的 basic/SK 配置,复用公用常量解析,输出持有数据的 CompilationManifest;只保留 CompilationManifest、ManifestCommand 两个解析层接口结构体。KernelCompilationPlanBuilder 直接接收解析结果,绑定常量、路径、环境和命令选项,在全部检查成功后才读取常量字节,失败不修改调用者输出。删除旧 kernel_manifest_parser、ManifestText、重复的绑定中间结构和独立组装步骤,Builder 不再接触 JSON 或判断 pointer/struct。

能力不区分 ACLNN 或尖括号来源,不添加 ACLNN 标记;两种入口均可按参数语义使用 pointer/struct。

删除未产生行为差异的 Parsed/Bound 状态,仅保留 definitionParsed_。路径与环境展开明确命名为 ExpandPathAndEnvironmentReferences,有上限的整数读取命名为 ReadBoundedNonnegativeInteger,解析和执行命令的参数字段统一为 arguments。

Builder 先绑定编译和链接命令,最后由 BuildConstantSourcePatches 完成全部常量绑定、目标展开和 patch 生成,任一步校验失败都不读取常量内存。请求侧删除 KernelCompilationVariant,使用 enableSuperKernel 表达 SK 开关;ManifestObjectKind 仅描述单个 basic/sk 对象。调整现有保护内存 UT,使其覆盖绑定阶段的命令与链接失败。

命令先按顺序展开全部 options 引用,再将首项作为 executable,其余作为 arguments。支持首项引用同时包含可执行文件及多个选项,拒绝展开后的空命令;不递归展开 options 引用。

ParseSelectedObjects 按请求选择编译对象。启用 SK 但所选 kernel 只有 basic 时记录 INFO 日志并回退普通编译,不加入 SK 专用选项;basic 缺失或已存在的 sk 配置错误仍返回失败。复用现有 UT 比较回退与 basic 模式的编译、链接命令,不增加用例数量。

保留受保护内存、非零参数索引的 pointer/struct 混合用例及解析数据所有权检查。UT 按职责收敛:字段与参数绑定校验集中在 ManifestConstant,删除 Parser/Builder/exporter 的重复校验矩阵,公共测试仅在 exporter 目标运行一次。补充状态重置、失败保留原状态和重复解析/构建的必要回归。

两个 Python producer 镜像同步修改。旧 pointer manifest 必须补充 arg_type: pointer 或重新生成。

关联的Issue

暂无关联 Issue。

测试

  • 基于 CANN master 8668f3ffc 同步,无冲突。
  • Manifest 生成器单元测试:14/14 通过。
  • Exporter C++ 单元测试:80/80 通过。
  • ACLRTC C++ 单元测试:192/192 通过。
  • 公用 constant 测试仅在 exporter 中运行;本轮封装重构后 C++ 测试总执行数由 276 项减少至 272 项,保留整数边界、字段契约及失败输出不变等覆盖。
  • ACLRTC 非 UT Release 动态库和 C++11 exporter 生产构建通过。
  • 覆盖显式及缺省 struct、禁止 struct byte_size、pointer 必填 byte_size、两种大小来源、零长度和非法参数。
  • 未执行 NPU 二级冒烟及算子泛化。

文档更新

本 PR 不提交文档文件。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 XuebinYang 的贡献)
XXuebinYang成员
2 天前 创建了 pull request,commit 6d68a9f4
atomgit-bot
atomgit-bot
2 天前 评论:

变更摘要

本 PR 为 JIT 常量化编译引入按值传递的结构体 tiling 支持:此前所有 constant_infos 项都必须提供 byte_size 并与 argsBytes 严格相等,无法表达按值传递的结构体。改动为 constant_infos[] 新增 arg_type 字段(支持 pointerstruct,缺省为 struct),并同步更新了 manifest 校验器、ACLRTC 运行时构建逻辑及两个 Python manifest 生成器,同时要求旧的 pointer manifest 补充 arg_type: pointer 或重新生成。

主要改动

  • 新增 arg_type 字段并定义缺省值: kernel_compilation_plan_builder.cppBuildConstantSourcePatches 通过 constantInfo.value("arg_type", STRUCT_ARGUMENT_TYPE) 读取类型,支持 pointer/struct 两种取值并拒绝其他值;resource_manifest_validator.cppValidateConstant 同样以 struct 作为缺省类型进行校验。
  • 按类型分支确定大小来源: pointer 常量使用 manifest 中的 byte_size(必填且非零);struct 常量改用 argsBytes[parameter_index] 提供的字节数,并禁止在 manifest 中携带 byte_size,同时运行时校验 structargsBytes 必须非零、argsAddr 必须提供。
  • validator 校验逻辑重构: resource_manifest_validator.cpp 移除了原先无条件要求的 byte_size 必填及"恰好五个字段"的检查,改为保留逐字段必填与类型检查、按 pointer/struct 分支校验大小字段,并依据允许的字段数量(4 + 是否含 arg_type + 是否含 byte_size)拒绝额外字段。
  • Python manifest 生成器同步输出 pointer: tools/build/asc_op_compile_base/adapter/static_compile_resource_generator.pytools/build/asc_op_compile_base/asc_op_compiler/static_compile_resource_generator.py 中的 ManifestPackageWriter 均在写出 constant_infos 项时固定补充 "arg_type": "pointer"
  • 测试覆盖与既有用例迁移: 更新 test_static_compile_resource_generator.pytest_kernel_compilation_plan_builder.cpptest_kernel_specialization_session.cpptest_resource_manifest_validator.cpp,新增对显式/缺省 struct、禁止 struct 携带 byte_sizepointer 必填 byte_size、两种大小来源及零长度非法参数的覆盖。
likedislike
不准确?
atomgit-bot
atomgit-bot
2 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
2 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
2 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/asc-devkit sjtulxh, YANXI_ZHAO (2/2) sjtulxh, YANXI_ZHAO (2/1)
tools/aclrtc YANXI_ZHAO, sjtulxh (2/2) YANXI_ZHAO (1/1)
tools/build sjtulxh, YANXI_ZHAO (2/2) sjtulxh (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
此处折叠了97条消息 查看更多
YANXI_ZHAO成员
1 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
1 天前 添加了label:lgtm
sjtulxh成员
1 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
1 天前 添加了label:approved
CANN-robotCANN-robot成员
1 天前 合入了pull request