本需求涉及算子确定性与强一致性开关的运行时获取。
当前 aclnn 框架已支持运行时获取这两类开关:
InitL2Phase1Context
aclrtGetSysParamOpt(ACL_OPT_DETERMINISTIC, &determinConfig)
TilingParseCtxHolder::BuildTilingParseCtx
ACL_OPT_STRONG_CONSISTENCY
随着 ACL runtime 侧语义演进,ACL_OPT_DETERMINISTIC 的取值需要扩展为 4 档,且前向包含(即高值包含低值的所有语义):
ACL_OPT_DETERMINISTIC
语义变化:相当于把 ACL_OPT_STRONG_CONSISTENCY 的取值合并到 ACL_OPT_DETERMINISTIC 中,并新增 batch 一致性开关。在此背景下,aclnn 框架需要支持确定性计算与一致性开关的动态生效。
*项目客户对batch一致性提出需求: 在算法调测调试期间,需要支持算子级控制,用于精度调测时逐算子关闭、打开batch一致性,对比精度;且开关要支持动态配置。
按需求侧的 4 个动作组织,每条动作下方列出实现侧的对应改动:
1. 在 InitL2Phase1Context 中动态获取 ACL_OPT_DETERMINISTIC
determinConfig
deterministicLevel
src/nnopbase/composite_op/aclnn_engine/op_executor.cpp
GetDeterministicLevelFromRt()
2. 兼容性升级逻辑(兼容老 runtime)
== 1
aclrtGetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, &consistency)
consistency == 1
2
OP_LOGI
"Upgrade deterministic level from 1 to 2, because strong consistency is on."
3. 将新 level 值写入 cache key
src/nnopbase/common/utils/op_cache.cpp
AddOpConfigInfoToBuf
bool deterministic
int32_t deterministicLevel
include/nnopbase/opdev/op_config.h
OpConfigInfo
int32_t deterministicLevel_{0}
reserved[6]
4. 给 tilingCtx 的数据(两路输出)
Deterministic_ = deterministic >= 1
DeterministicLevel_ = deterministic
src/nnopbase/composite_op/aclnn_engine/tiling_parse_ctx_holder.{h,cpp}
GetDeterministicLevel()
opConfigInfo_.deterministicLevel_
DeterministicLevel_
mutable
BuildTilingParseCtx
static std::call_once
测试
tests/nnopbase/ut/composite_op/test_op_cache.cpp
test_op_executor.cpp
test_tilingctx_builder.cpp
tests/nnopbase/common/depends/acl/aclrt_stub.cpp
关联 PR:https://gitcode.com/cann/opbase/pull/631
Background(背景信息)
本需求涉及算子确定性与强一致性开关的运行时获取。
当前 aclnn 框架已支持运行时获取这两类开关:
InitL2Phase1Context中通过aclrtGetSysParamOpt(ACL_OPT_DETERMINISTIC, &determinConfig)获取确定性计算开关,取值为 0 / 1。TilingParseCtxHolder::BuildTilingParseCtx中以进程级方式获取一次ACL_OPT_STRONG_CONSISTENCY(强一致性开关,取值 0 / 1;具体逻辑与注释可参见该函数实现)。随着 ACL runtime 侧语义演进,
ACL_OPT_DETERMINISTIC的取值需要扩展为 4 档,且前向包含(即高值包含低值的所有语义):语义变化:相当于把
ACL_OPT_STRONG_CONSISTENCY的取值合并到ACL_OPT_DETERMINISTIC中,并新增 batch 一致性开关。在此背景下,aclnn 框架需要支持确定性计算与一致性开关的动态生效。Origin(信息来源)
*项目客户对batch一致性提出需求:
在算法调测调试期间,需要支持算子级控制,用于精度调测时逐算子关闭、打开batch一致性,对比精度;且开关要支持动态配置。
Benefit / Necessity(价值/作用)
ACL_OPT_STRONG_CONSISTENCY合并进ACL_OPT_DETERMINISTIC,下游只感知一个 level,不再需要在 aclnn 框架内单独维护一致性开关的进程级缓存。Design(设计方案)
按需求侧的 4 个动作组织,每条动作下方列出实现侧的对应改动:
1. 在
InitL2Phase1Context中动态获取ACL_OPT_DETERMINISTICaclrtGetSysParamOpt(ACL_OPT_DETERMINISTIC, &determinConfig),每个 aclnn 接口入口处都取一次,保证动态生效。determinConfig是否改名为deterministicLevel。实现侧确认采用deterministicLevel,更贴合"4 档 level"的语义。src/nnopbase/composite_op/aclnn_engine/op_executor.cpp中新增静态函数GetDeterministicLevelFromRt()封装读取逻辑,由InitL2Phase1Context调用。2. 兼容性升级逻辑(兼容老 runtime)
deterministicLevel后判断:若== 1,则再调用aclrtGetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, &consistency);若consistency == 1,则把deterministicLevel修改为2,否则保持原值。ACL_OPT_DETERMINISTIC不支持返回强一致性语义的老版本 runtime。OP_LOGI记录日志"Upgrade deterministic level from 1 to 2, because strong consistency is on."。3. 将新 level 值写入 cache key
src/nnopbase/common/utils/op_cache.cpp的AddOpConfigInfoToBuf中,把原 1 bytebool deterministic改为 4 byteint32_t deterministicLevel参与哈希,避免不同 level 命中同一份 tiling 缓存。include/nnopbase/opdev/op_config.h中的OpConfigInfo同步新增int32_t deterministicLevel_{0}(删除原reserved[6]占位,结构体大小保持兼容),拷贝构造与赋值运算带上新字段。4. 给 tilingCtx 的数据(两路输出)
Deterministic_ = deterministic >= 1DeterministicLevel_ = deterministicsrc/nnopbase/composite_op/aclnn_engine/tiling_parse_ctx_holder.{h,cpp}:GetDeterministicLevel()改为每次从 TLSopConfigInfo_.deterministicLevel_现场读取,DeterministicLevel_改为mutable。BuildTilingParseCtx中static std::call_once一次性获取ACL_OPT_STRONG_CONSISTENCY与原计算 level 的整段逻辑——上游InitL2Phase1Context已动态取值,此处不再需要重复缓存。测试
tests/nnopbase/ut/composite_op/test_op_cache.cpp、test_op_executor.cpp、test_tilingctx_builder.cpp配合上述 4 个动作更新用例。tests/nnopbase/common/depends/acl/aclrt_stub.cpp补齐ACL_OPT_STRONG_CONSISTENCY桩。关联 PR:https://gitcode.com/cann/opbase/pull/631