| Support Acos op with AscendC
Co-authored-by: zyf0712<zhangyufei63@huawei.com>
# message auto-generated for no-merge-commit merge:
!1033 merge master into master
Support Acos op with AscendC
Created-by: luomin2005
Commit-by: luomin2005;zyf0712
Merged-by: cann-robot
Description: ## 描述
使用AscendC实现acos算子
1.按照泰勒公式计算arcsin(x) = Cx + Cx^3 + Cx^5 + Cx^7 + Cx^9 + Cx^11 + Cx^13 + Cx^15 .....
其中C为泰勒系数,参考常量taylorCoefficients,参考精度要求泰勒系数计算到第8项
T taylorCoefficients[] = {1.0, 1.0 / 6, 3.0 / 40, 5.0 / 112,
35.0 / 1152, 63.0 / 2816, 231.0 / 13312, 143.0 / 10240};
2.将x取绝对值,并将正负号保存到xSignMask掩码中;
3.当x < Boudry = 0.70710678118654752440084436210485 时计算 arcsin(x), 当x >Boudry计算arcsin(x) = halfPi - 1/2 sqrt(1-x^2)
4.利用arcsin(-x) = -arcsin(x), 根据符号标记合并还原计算负值情况
3.arccos(x) = halfPi - arcsin(x)
## 关联的Issue
https://gitcode.com/cann/ops-math/issues/581
## 测试
[2026-01-30 15:09:13] Start to run examples,name:acos mode:eager
[2026-01-30 15:09:13] Start compile and run examples file: ../math/acos/examples/test_aclnn_acos.cpp
[2026-01-30 15:09:13] pkg_mode:cust vendor_name:custom
[2026-01-30 15:09:19] [Warning]: tiling struct [ReduceOpTilingDataV2] is conflict with one in file kl_div_v2.cc, line 41
[2026-01-30 15:09:19] [Warning]: tiling struct [RepeatInterleaveGradTilingData] is conflict with one in file repeat_interleave_grad_tiling.h, line 21
[2026-01-30 15:09:19] [Warning]: tiling struct [IndexFillTilingData] is conflict with one in file index_fill_tiling.h, line 21
[2026-01-30 15:09:19] [Warning]: tiling struct [MaskedSelectV3TilingData] is conflict with one in file masked_select_v3_tiling.h, line 27
[2026-01-30 15:09:19] [Warning]: tiling struct [MaskedSelectV3TilingData] is conflict with one in file masked_select_v3_tiling.h, line 27
[2026-01-30 15:09:19] [Warning]: tiling struct [ScatterPaKvCacheTilingData] is conflict with one in file scatter_pa_kv_cache_tiling.h, line 35
[2026-01-30 15:09:19] [Warning]: tiling struct [ScatterPaKvCacheTilingData] is conflict with one in file scatter_pa_kv_cache_tiling.h, line 35
[2026-01-30 15:09:19] [Warning]: tiling struct [TopKTopPSampleTilingData] is conflict with one in file top_k_top_p_sample_tiling.h, line 26
[2026-01-30 15:09:19] [Warning]: tiling struct [AvgPool3dGradTilingBlockParam] is conflict with one in file avg_pool_3d_grad_tiling.h, line 99
[2026-01-30 15:09:19] [Warning]: tiling struct [AvgPool3dGradTilingParam] is conflict with one in file avg_pool_3d_grad_tiling.h, line 125
[2026-01-30 15:09:19] [Warning]: tiling struct [FusedCrossEntropyLossWithMaxSumTilingData] is conflict with one in file fused_cross_entropy_loss_with_max_sum_tiling.h, line 27
[2026-01-30 15:09:19] [Warning]: tiling struct [TilingDataBackgroundReplace] is conflict with one in file background_replace_tiling.h, line 22
[2026-01-30 15:09:19] [Warning]: tiling struct [TilingDataBlendImages] is conflict with one in file blend_images_custom_tiling.h, line 24
[2026-01-30 15:09:19] 0 acos(-inf) = nan
[2026-01-30 15:09:19] 1 acos(-12.000000) = nan
[2026-01-30 15:09:19] 2 acos(-1.000001) = nan
[2026-01-30 15:09:19] 3 acos(-1.000010) = nan
[2026-01-30 15:09:19] 4 acos(-1.000100) = nan
[2026-01-30 15:09:19] 5 acos(-1.001000) = nan
[2026-01-30 15:09:19] 6 acos(-1.010000) = nan
[2026-01-30 15:09:19] 7 acos(-1.000000) = 3.141593
[2026-01-30 15:09:19] 8 acos(-0.999990) = 3.137117
[2026-01-30 15:09:19] 9 acos(-0.999900) = 3.127449
[2026-01-30 15:09:19] 10 acos(-0.999000) = 3.096868
[2026-01-30 15:09:19] 11 acos(-0.990000) = 3.000053
[2026-01-30 15:09:19] 12 acos(-0.900000) = 2.690566
[2026-01-30 15:09:19] 13 acos(-0.800000) = 2.498095
[2026-01-30 15:09:19] 14 acos(-0.710000) = 2.360346
[2026-01-30 15:09:19] 15 acos(-0.705000) = 2.353167
[2026-01-30 15:09:19] 16 acos(-0.700000) = 2.346148
[2026-01-30 15:09:19] 17 acos(-0.650000) = 2.278369
[2026-01-30 15:09:19] 18 acos(-0.600000) = 2.214295
[2026-01-30 15:09:19] 19 acos(-0.500000) = 2.094395
[2026-01-30 15:09:19] 20 acos(-0.400000) = 1.982313
[2026-01-30 15:09:19] 21 acos(-0.300000) = 1.875489
[2026-01-30 15:09:19] 22 acos(-0.200000) = 1.772154
[2026-01-30 15:09:19] 23 acos(-0.100000) = 1.670964
[2026-01-30 15:09:19] 24 acos(-0.010000) = 1.580796
[2026-01-30 15:09:19] 25 acos(-0.001000) = 1.571796
[2026-01-30 15:09:19] 26 acos(-0.000100) = 1.570896
[2026-01-30 15:09:19] 27 acos(-0.000010) = 1.570806
[2026-01-30 15:09:19] 28 acos(-0.000001) = 1.570797
[2026-01-30 15:09:19] 29 acos(-0.000000) = 1.570796
[2026-01-30 15:09:19] 30 acos(0.000000) = 1.570796
[2026-01-30 15:09:19] 31 acos(nan) = nan
[2026-01-30 15:09:19] 32 acos(0.000000) = 1.570796
[2026-01-30 15:09:19] 33 acos(0.000000) = 1.570796
[2026-01-30 15:09:19] 34 acos(0.000001) = 1.570795
[2026-01-30 15:09:19] 35 acos(0.000010) = 1.570786
[2026-01-30 15:09:19] 36 acos(0.000100) = 1.570696
[2026-01-30 15:09:19] 37 acos(0.010000) = 1.560796
[2026-01-30 15:09:19] 38 acos(0.100000) = 1.470629
[2026-01-30 15:09:19] 39 acos(0.200000) = 1.369438
[2026-01-30 15:09:19] 40 acos(0.200000) = 1.369438
[2026-01-30 15:09:19] 41 acos(0.300000) = 1.266104
[2026-01-30 15:09:19] 42 acos(0.400000) = 1.159280
[2026-01-30 15:09:19] 43 acos(0.500000) = 1.047198
[2026-01-30 15:09:19] 44 acos(0.500000) = 1.047198
[2026-01-30 15:09:19] 45 acos(0.600000) = 0.927298
[2026-01-30 15:09:19] 46 acos(0.650000) = 0.863224
[2026-01-30 15:09:19] 47 acos(0.700000) = 0.795445
[2026-01-30 15:09:19] 48 acos(0.705000) = 0.788426
[2026-01-30 15:09:19] 49 acos(0.710000) = 0.781247
[2026-01-30 15:09:19] 50 acos(0.800000) = 0.643498
[2026-01-30 15:09:19] 51 acos(0.900000) = 0.451027
[2026-01-30 15:09:19] 52 acos(0.990000) = 0.141539
[2026-01-30 15:09:19] 53 acos(0.999000) = 0.044725
[2026-01-30 15:09:19] 54 acos(0.999900) = 0.014144
[2026-01-30 15:09:19] 55 acos(0.999990) = 0.004475
[2026-01-30 15:09:19] 56 acos(1.000000) = 0.000000
[2026-01-30 15:09:19] 57 acos(1.010000) = nan
[2026-01-30 15:09:19] 58 acos(1.001000) = nan
[2026-01-30 15:09:19] 59 acos(1.000100) = nan
[2026-01-30 15:09:19] 60 acos(1.000010) = nan
[2026-01-30 15:09:19] 61 acos(1.000001) = nan
[2026-01-30 15:09:19] 62 acos(12.000000) = nan
[2026-01-30 15:09:19] 63 acos(inf) = nan
[2026-01-30 15:09:19] run test_aclnn_acos, execute samples success
Kernel UT测试结果如下:测试数据形状(32, 8, 7, 7) tmp_input = np.random.choice([1.0, 0.8, 0.7, 0.5, -1, 0.1, 0.0, np.nan, np.inf], size=size)随机选择,精度误差绝对误差和相对误差10的负4次方
diff_res = np.isclose(tmp_out, tmp_gold, rtol=1e-4, atol=1e-4, equal_nan=True)
[2026-01-30 15:13:38] Run fast op utest
[2026-01-30 15:13:38] [==========] Running 1 test from 1 test suite.
[2026-01-30 15:13:38] [----------] Global test environment set-up.
[2026-01-30 15:13:38] Global Environment SetpUp.
[2026-01-30 15:13:38] [----------] 1 test from AcosTest
[2026-01-30 15:13:38] AcosTest SetUp
[2026-01-30 15:13:38]
[2026-01-30 15:13:38] [ RUN ] AcosTest.test_case_0
[2026-01-30 15:13:38] /home/l00614971/op-math/build/tests/ut/op_kernel/acos_data/gen_data.py:36: RuntimeWarning: invalid value encountered in arccos
[2026-01-30 15:13:38] tmp_golden = np.arccos(tmp_input)
[2026-01-30 15:13:39] libgcov profiling error:/home/l00614971/op-math/build/math/acos/CMakeFiles/ophost_math_tiling_obj.dir/op_host/acos_tiling.cpp.gcda:overwriting an existing profile data with a different timestamp
[2026-01-30 15:13:39] libgcov profiling error:/home/l00614971/op-math/build/tests/ut/op_kernel/CMakeFiles/math_op_kernel_ut_ascend910B1.dir/test_op_kernel_main.cpp.gcda:overwriting an existing profile data with a different timestamp
[2026-01-30 15:13:39] libgcov profiling error:/home/l00614971/op-math/build/math/acos/tests/ut/op_kernel/CMakeFiles/acos_Ascend910B1_cases_obj.dir/test_acos.cpp.gcda:overwriting an existing profile data with a different timestamp
[2026-01-30 15:13:39] libgcov profiling error:/home/l00614971/op-math/build/tests/ut/op_kernel/CMakeFiles/math_op_kernel_ut_common_obj.dir/__/common/tiling_context_faker.cpp.gcda:overwriting an existing profile data with a different timestamp
[2026-01-30 15:13:39] libgcov profiling error:/home/l00614971/op-math/build/tests/ut/op_kernel/CMakeFiles/math_op_kernel_ut_common_obj.dir/__/common/tiling_case_executor.cpp.gcda:overwriting an existing profile data with a different timestamp
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [SUCCESS][CORE_0][pid 1618408] exit success!
[2026-01-30 15:13:46] [TmSim]: Run in serial mode.
[2026-01-30 15:13:46] [SUCCESS][CORE_1][pid 1618409] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_2][pid 1618410] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_3][pid 1618411] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_4][pid 1618412] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_5][pid 1618413] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_6][pid 1618414] exit success!
[2026-01-30 15:13:46] [SUCCESS][CORE_7][pid 1618415] exit success!
[2026-01-30 15:13:46] PASSED!
[2026-01-30 15:13:46] compare result: True
[2026-01-30 15:13:46] [ OK ] AcosTest.test_case_0 (7926 ms)
[2026-01-30 15:13:46] AcosTest TearDown
[2026-01-30 15:13:46]
[2026-01-30 15:13:46] [----------] 1 test from AcosTest (7926 ms total)
[2026-01-30 15:13:46]
[2026-01-30 15:13:46] [----------] Global test environment tear-down
[2026-01-30 15:13:46] Global Environment TearDown
[2026-01-30 15:13:46] [==========] 1 test from 1 test suite ran. (7960 ms total)
[2026-01-30 15:13:46] [ PASSED ] 1 test.
[2026-01-30 15:13:46] [100%] Built target math_op_kernel_ut_ascend910B1
[2026-01-30 15:13:46] [100%] Built target math_op_kernel_ut
(ws) [root@shlqh-cann-cluster8-141-61-33-172 op-math]#
## 文档更新
<!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。-->
## 类型标签
<!-- [x] 表示选中 -->
- [ ] Bug修复
- [x] 新特性
- [ ] 性能优化
- [ ] 文档更新
- [ ] 其他,请描述:
See merge request: cann/ops-math!1033 | 3 个月前 |