Merged
Add scalar limit check for int and float #5812
gaoxiang618Add on Aug 31
Add scalar limit check for int and float #5812
Merged
Merged fromgaoxiang618/pypto_0720masterintocann/pyptomaster
gaoxiang618Collaborators
Aug 31
Aug 31
- 增加对于pl和vf接口的scalar范围校验
- 修正vf接口的scalar类型推导


Pull Request has been successfully merged by CANN-robot.
(Thank you for gaoxiang618's contribution.)Aug 31 Created pull request, commit bb80d562
atomgit-bot
Aug 31 Comments:
Aug 31 Comments:
变更摘要
该 PR 为 int/float 标量在进入 IR 之前增加范围校验:新增统一的数值范围基础设施(pypto_pro/ir/_limits.py 与 pypto_pro/language/parser/diagnostics/_range.py),以 FinalRejectionError 拒绝超出 dtype 可表示范围或超出 ir.ConstInt 存储带 [INT64_MIN, UINT64_MAX] 的常量,并将 ConstInt 的无符号折叠存储(int64_t 兼作 uint64_t 位镜像)在打印与代码生成阶段按 dtype 有符号性正确还原;同时把硬件资源 ID 上限统一为共享常量并由各处复用同一套 check_in_range 检查。
主要改动
- 新增数值范围校验基础设施:新增
_limits.py(NumericLimits、limits_of、fits、fits_storage_int、to_storage_int、from_storage_int,含各浮点格式最大有限值与 BOOL/INDEX 特例)和diagnostics/_range.py(make_const_int、check_fits_dtype、check_in_range、check_ir_int、check_const_expr_fits_dtype、range_message),统一"<subject> must be in [lo, hi], got <value>"消息语法,并提供error=参数供非解析路径抛出普通ValueError。 - 字面量标量按 dtype 做 API 级范围校验:
_call_parser.py新增_VF_SCALAR_OPERAND_OPS与_check_vf_scalar_operands,对vf.adds/subs/muls/mins/maxs/axpy等操作的常量标量操作数按元素 dtype 校验(shift_left/right、bit_cast豁免);scalar_ops.py的pl.const按显式 dtype 校验;_utils.py、_expr_evaluator.py、_expression_parser.py中整数常量统一改走make_const_int(INDEX 占位符在值超过INT64_MAX时落定为UINT64并折叠存储)。 - 常量打印与代码生成支持往返和无符号折叠:
printer.h/cpp公开FormatFloatLiteral(整数值保留.0、超大值用科学计数法保证往返)与FormatIntLiteral(按 dtype 有符号性拼写),codegen_base.h/cpp新增FormatIntCLiteral(仅对折叠为负的 uint64 拼uLL后缀),io_text_dumper.cpp、cce_codegen.cpp、TryGenerateSimpleExprString等改用上述函数。 - 硬件资源上限统一为共享常量并复用范围检查:
system_ops.py将私有_MAX_EVENT_ID/_MAX_FLAG_EVENT_ID/_MAX_MUTEX_ID改为导出的含端点常量MAX_EVENT_ID=15、MAX_FLAG_EVENT_ID=7、MAX_MUTEX_ID=31,_buffer_parser.py(make_tile_groupmutex)、_cross_core_scanner.py、_analyzer.py、_call_parser.py(SIMTmax_threads≤ 2048)、_tiling.py(数组大小 ≤ 2048)统一改用check_in_range。 - CCE 后端标量强转逻辑重写:
backend_cce_vf_ops.cpp的CoerceScalarToInt由逐 dtype 分支改为通用实现——按src_dt位宽截断、无符号加u后缀、有符号做符号扩展,配合前端新增的标量范围校验避免静默回绕。


Incorrect?
atomgit-bot
Aug 31 Comments:
Aug 31 Comments:
Aug 31 Added label: cann-cla/yes
CANN-robot
Aug 31 Comments:
Aug 31 Comments:
121 messages are collapsed here。 See more
lidongsheng
Sep 3 Comments:
Sep 3 Comments:
/lgtm


Sep 3 Added label: lgtm
CANN-robot
Sep 3 Comments:
Sep 3 Comments:
The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


Sep 3 Resolved final issue
Sep 3 Merged pull request