| Files | Last commit | Last update |
|---|---|---|
fix(fresnel_sin): guard null GM base address and cap per-core split lengths Co-authored-by: wang-gang<wanggang414@h-partners.com> # message auto-generated for no-merge-commit merge: !6849 merge fix/fresnel-sin-ci-format into master fix(fresnel_sin): guard null GM base address and cap per-core split lengths Created-by: wang-gang Commit-by: wang-gang Merged-by: cann-robot Description: ## 描述 FresnelSin kernel performs an unchecked GM base address dereference in Init(): for oversized tensors (e.g. 2^32 fp32 elements) the GM allocation may fail and the framework hands over a null base address, so the first CopyIn reads address 0x0 (mSAN reports 2x illegal read of size 1 on GM). The host tiling also stores the per-core split lengths in uint32_t fields while the total element count is int64, which can silently truncate for element counts beyond the uint32 range. Changes: - op_kernel/arch35/fresnel_sin.h: add a null-pointer guard in Init() so the kernel bails out before any GM access, and guard Process() against zero-length work (avoids the loopCount division by zero when Init() returns early). - op_host/arch35/fresnel_sin_tiling.cpp: reject per-core split lengths beyond UINT32_MAX right at the narrowing point in FresnelSinTilingFunc(), so any length that the static_cast<uint32_t> of baseLength/tailLength would silently truncate fails fast in the host tiling with an explicit error, without rejecting large total element counts that the kernel itself supports. The FresnelSinTilingData layout is intentionally unchanged (no uint64 widening of baseLength/tailLength): the new host-side limit makes truncation unreachable, and keeping the layout avoids cross-component compatibility risk. ## 关联的Issue https://gitcode.com/wangyueting/changwei_gaoxiang/issues/18 ## 测试 - pre-commit checks (clang-format 18.1.8, OAT compliance, codespell) verified locally with the same hook versions as CI; the two touched files now pass clang-format --style=file --dry-run -Werror cleanly. - Local environment has no NPU device / CANN toolkit, so the mSAN reproduction (shape (1, 4294967296, 1, 1, 1) fp32) could not be run locally; verification relies on CI plus an mSAN rerun of the L1 upboundary cases. - Static code review: OP_CHECK_IF/OP_LOGE/UINT32_MAX usage follows existing conventions in this repo (e.g. split_v_tiling.cpp); the guard in Process() prevents a division-by-zero UB on the early-return path; normal-path behavior is unchanged. ## 文档更新 None ## 类型标签 <!-- [x] 表示选中 --> - [x] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-math!6849 | 10 days ago | |
[CANNBot]add FresnelSin operator Co-authored-by: handsomeRobot_SK<suke13@huawei.com> Co-authored-by: handsomeRobot_SK<2034073486@qq.com> # message auto-generated for no-merge-commit merge: !3644 merge master into master [CANNBot]add FresnelSin operator Created-by: handsomeRobot_SK Commit-by: handsomeRobot_SK Merged-by: cann-robot Description: # feat: add FresnelSin operator ## 概述 新增 FresnelSin 算子,计算 **Fresnel 正弦积分** \[ S(x) = \int_0^x \sin\left(\frac{\pi t^2}{2}\right) dt \] 对标 TensorFlow 的 tf.math.special.fresnel_sin 实现。 --- ## 支持规格 | 项目 | 说明 | |------------|-------------------------------| | 数据类型 | float16, float32, bfloat16 | | 目标芯片 | Ascend 950 (arch35) | | 接口类型 | GE IR(无 ACLNN) | --- ## 算法实现 基于 Cephes 库 fresnl.c 的分段逼近策略: - **小值分支**(\(x^2 < 2.5625\)): 有理逼近 \[ S(|x|) = |x|^3 \cdot \frac{P_S(x^*)}{Q_S(x^*)} \] 其中 \(x^* = x^2\),\(P_S\)、\(Q_S\) 为特定多项式系数。 - **渐近分支**(\(x^2 \ge 2.5625\)): \[ S(|x|) = 0.5 - \frac{f \cdot \cos(z) + g \cdot \sin(z)}{\pi |x|} \] 其中 \(z = \frac{\pi x^2}{2}\),\(f\)、\(g\) 由辅助函数计算。 - **特殊值处理**: - NaN → NaN - ±Inf → ±0.5 - **符号恢复**:利用奇函数性质 \(S(-x) = -S(x)\) 保证数值正确。 --- ## 新增文件 | 文件路径 | 说明 | |----------|------| | math/fresnel_sin/CMakeLists.txt | 构建配置 | | math/fresnel_sin/op_graph/fresnel_sin_proto.h | GE IR 算子注册 | | math/fresnel_sin/op_host/fresnel_sin_def.cpp | 算子定义(dtype/format/config) | | math/fresnel_sin/op_host/fresnel_sin_infershape.cpp | 形状推导(输出 = 输入) | | math/fresnel_sin/op_host/arch35/fresnel_sin_tiling_arch35.cpp | Tiling 策略(多核分块 + UB 规划) | | math/fresnel_sin/op_kernel/arch35/fresnel_sin.h | Kernel 核心实现(Cephes 系数 + Horner 求值) | | math/fresnel_sin/op_kernel/arch35/fresnel_sin_tiling_data.h | Tiling 数据结构 | | math/fresnel_sin/op_kernel/arch35/fresnel_sin_tiling_key.h | 模板参数声明 | | math/fresnel_sin/op_kernel/fresnel_sin_apt.cpp | Kernel 入口 | | math/fresnel_sin/examples/test_geir_fresnel_sin.cpp | GE IR 精度验证(10 个 L1 用例) | | math/fresnel_sin/examples/arch35/test_geir_fresnel_sin.cpp | arch35 精度验证 | --- ## 精度标准 | dtype | rtol | |------------|--------| | float32 | 1e-4 | | float16 | 1e-3 | | bfloat16 | 4e-3 | --- ## UB Buffer 规划 - 输入队列 qIn :1 × sizeof(T) - 输出队列 qOut :1 × sizeof(T) - 计算队列 calcQ :8 × sizeof(float) - 掩码队列 maskQ :3 × sizeof(uint8_t) See merge request: cann/ops-math!3644 | 4 months ago | |
feat(math): fresnel_cos/fresnel_sin 补充 tiling 校验并迁移 def 驱动 dtype 模式 Co-authored-by: handsomeRobot_SK<suke13@huawei.com> # message auto-generated for no-merge-commit merge: !4447 merge feature/fresnel_cos_v2 into master feat(math): fresnel_cos/fresnel_sin 补充 tiling 校验并迁移 def 驱动 dtype 模式 Created-by: handsomeRobot_SK Commit-by: handsomeRobot_SK Merged-by: cann-robot Description: 标题: feat(math): fresnel_cos/fresnel_sin 补充 tiling 校验并迁移 def 驱动 dtype 模式 描述: ## 变更内容 ### 1. Tiling 校验补充 参考 ops-nn PR#8161 / PR#8095 的校验规范,为 FresnelCos 和 FresnelSin 算子补充以下 tiling 阶段校验: | 校验项 | 宏 | 说明 | |--------|----|------| | 维度数 | OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON | 输入维度数不超过 8 | | dtype | OP_LOGE_WITH_INVALID_INPUT_DTYPE | 替换原有简单 OP_LOGE,使用标准错误日志宏 | | format | OP_LOGE | 校验输入 format 必须为 ND | ### 2. Def 驱动 dtype 模式迁移 - 移除 tiling_key.h 中的 ASCENDC_TPL_ARGS_DECL / ASCENDC_TPL_SEL 模板参数声明 - apt.cpp 中 kernel 函数移除 template <typename T>,改用 DTYPE_X 宏(由 def.cpp DataTypeList 自动注入) ### 3. UT 用例补充 每个算子新增 2 个 tiling UT 用例: - invalid_dim_num_exceeds_max:9 维输入,期望 GRAPH_FAILED - invalid_format_nchw:NCHW 格式输入,期望 GRAPH_FAILED ## 涉及文件 - math/fresnel_cos/op_host/arch35/fresnel_cos_tiling_arch35.cpp - math/fresnel_cos/op_kernel/arch35/fresnel_cos_tiling_key.h - math/fresnel_cos/op_kernel/fresnel_cos_apt.cpp - math/fresnel_cos/tests/ut/op_host/arch35/test_fresnel_cos_tiling_arch35.cpp - math/fresnel_sin/op_host/arch35/fresnel_sin_tiling_arch35.cpp - math/fresnel_sin/op_kernel/arch35/fresnel_sin_tiling_key.h - math/fresnel_sin/op_kernel/fresnel_sin_apt.cpp - math/fresnel_sin/tests/ut/op_host/arch35/test_fresnel_sin_tiling_arch35.cpp See merge request: cann/ops-math!4447 | 3 months ago |
| Files | Last commit | Last update |
|---|---|---|
| 10 days ago | ||
| 4 months ago | ||
| 3 months ago |