Merged
feat: AngleV2算子新增ascend960dt平台适配 #7018
miaojingjingAdd on 8 days ago
feat: AngleV2算子新增ascend960dt平台适配 #7018
Merged
Merged frommiaojingjing/ops-mathmasterintocann/ops-mathmaster
Total: 8 files changed+427-45
| @@ -94,6 +94,7 @@ public: | |||
| 94 | .DynamicRankSupportFlag(true) | 94 | .DynamicRankSupportFlag(true) |
| 95 | .DynamicShapeSupportFlag(true); | 95 | .DynamicShapeSupportFlag(true); |
| 96 | this->AICore().AddConfig("ascend950", aicore_a5_config); | 96 | this->AICore().AddConfig("ascend950", aicore_a5_config); |
| 97 | + this->AICore().AddConfig("ascend960dt", aicore_a5_config); | ||
| 97 | 98 | ||
| 98 | OpAICoreConfig config_kirin = GetKirinCoreConfig(); | 99 | OpAICoreConfig config_kirin = GetKirinCoreConfig(); |
| 99 | this->AICore().AddConfig("kirinx90", config_kirin); | 100 | this->AICore().AddConfig("kirinx90", config_kirin); |
| @@ -0,0 +1,295 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "AngleV2", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "AngleV2_5cfa8f3b14716c3317bcd193933a3613", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "complex64", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "float32", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + "bin_filename": "AngleV2_1946086cc5d1bc19a4d66b5bd48e62cd", | ||
| 35 | + "inputs": [ | ||
| 36 | + { | ||
| 37 | + "name": "x", | ||
| 38 | + "index": 0, | ||
| 39 | + "dtype": "float32", | ||
| 40 | + "format": "ND", | ||
| 41 | + "paramType": "required", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "format_match_mode": "FormatAgnostic" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "float32", | ||
| 53 | + "format": "ND", | ||
| 54 | + "paramType": "required", | ||
| 55 | + "shape": [ | ||
| 56 | + -2 | ||
| 57 | + ], | ||
| 58 | + "format_match_mode": "FormatAgnostic" | ||
| 59 | + } | ||
| 60 | + ] | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + "bin_filename": "AngleV2_bf16", | ||
| 64 | + "inputs": [ | ||
| 65 | + { | ||
| 66 | + "name": "x", | ||
| 67 | + "index": 0, | ||
| 68 | + "dtype": "bfloat16", | ||
| 69 | + "format": "ND", | ||
| 70 | + "paramType": "required", | ||
| 71 | + "shape": [ | ||
| 72 | + -2 | ||
| 73 | + ], | ||
| 74 | + "format_match_mode": "FormatAgnostic" | ||
| 75 | + } | ||
| 76 | + ], | ||
| 77 | + "outputs": [ | ||
| 78 | + { | ||
| 79 | + "name": "y", | ||
| 80 | + "index": 0, | ||
| 81 | + "dtype": "bfloat16", | ||
| 82 | + "format": "ND", | ||
| 83 | + "paramType": "required", | ||
| 84 | + "shape": [ | ||
| 85 | + -2 | ||
| 86 | + ], | ||
| 87 | + "format_match_mode": "FormatAgnostic" | ||
| 88 | + } | ||
| 89 | + ] | ||
| 90 | + }, | ||
| 91 | + { | ||
| 92 | + "bin_filename": "AngleV2_a8c107f79de7b47ce419f0ec015539f7", | ||
| 93 | + "inputs": [ | ||
| 94 | + { | ||
| 95 | + "name": "x", | ||
| 96 | + "index": 0, | ||
| 97 | + "dtype": "float16", | ||
| 98 | + "format": "ND", | ||
| 99 | + "paramType": "required", | ||
| 100 | + "shape": [ | ||
| 101 | + -2 | ||
| 102 | + ], | ||
| 103 | + "format_match_mode": "FormatAgnostic" | ||
| 104 | + } | ||
| 105 | + ], | ||
| 106 | + "outputs": [ | ||
| 107 | + { | ||
| 108 | + "name": "y", | ||
| 109 | + "index": 0, | ||
| 110 | + "dtype": "float16", | ||
| 111 | + "format": "ND", | ||
| 112 | + "paramType": "required", | ||
| 113 | + "shape": [ | ||
| 114 | + -2 | ||
| 115 | + ], | ||
| 116 | + "format_match_mode": "FormatAgnostic" | ||
| 117 | + } | ||
| 118 | + ] | ||
| 119 | + }, | ||
| 120 | + { | ||
| 121 | + "bin_filename": "AngleV2_bool", | ||
| 122 | + "inputs": [ | ||
| 123 | + { | ||
| 124 | + "name": "x", | ||
| 125 | + "index": 0, | ||
| 126 | + "dtype": "bool", | ||
| 127 | + "format": "ND", | ||
| 128 | + "paramType": "required", | ||
| 129 | + "shape": [ | ||
| 130 | + -2 | ||
| 131 | + ], | ||
| 132 | + "format_match_mode": "FormatAgnostic" | ||
| 133 | + } | ||
| 134 | + ], | ||
| 135 | + "outputs": [ | ||
| 136 | + { | ||
| 137 | + "name": "y", | ||
| 138 | + "index": 0, | ||
| 139 | + "dtype": "float32", | ||
| 140 | + "format": "ND", | ||
| 141 | + "paramType": "required", | ||
| 142 | + "shape": [ | ||
| 143 | + -2 | ||
| 144 | + ], | ||
| 145 | + "format_match_mode": "FormatAgnostic" | ||
| 146 | + } | ||
| 147 | + ] | ||
| 148 | + }, | ||
| 149 | + { | ||
| 150 | + "bin_filename": "AngleV2_uint8", | ||
| 151 | + "inputs": [ | ||
| 152 | + { | ||
| 153 | + "name": "x", | ||
| 154 | + "index": 0, | ||
| 155 | + "dtype": "uint8", | ||
| 156 | + "format": "ND", | ||
| 157 | + "paramType": "required", | ||
| 158 | + "shape": [ | ||
| 159 | + -2 | ||
| 160 | + ], | ||
| 161 | + "format_match_mode": "FormatAgnostic" | ||
| 162 | + } | ||
| 163 | + ], | ||
| 164 | + "outputs": [ | ||
| 165 | + { | ||
| 166 | + "name": "y", | ||
| 167 | + "index": 0, | ||
| 168 | + "dtype": "float32", | ||
| 169 | + "format": "ND", | ||
| 170 | + "paramType": "required", | ||
| 171 | + "shape": [ | ||
| 172 | + -2 | ||
| 173 | + ], | ||
| 174 | + "format_match_mode": "FormatAgnostic" | ||
| 175 | + } | ||
| 176 | + ] | ||
| 177 | + }, | ||
| 178 | + { | ||
| 179 | + "bin_filename": "AngleV2_int8", | ||
| 180 | + "inputs": [ | ||
| 181 | + { | ||
| 182 | + "name": "x", | ||
| 183 | + "index": 0, | ||
| 184 | + "dtype": "int8", | ||
| 185 | + "format": "ND", | ||
| 186 | + "paramType": "required", | ||
| 187 | + "shape": [ | ||
| 188 | + -2 | ||
| 189 | + ], | ||
| 190 | + "format_match_mode": "FormatAgnostic" | ||
| 191 | + } | ||
| 192 | + ], | ||
| 193 | + "outputs": [ | ||
| 194 | + { | ||
| 195 | + "name": "y", | ||
| 196 | + "index": 0, | ||
| 197 | + "dtype": "float32", | ||
| 198 | + "format": "ND", | ||
| 199 | + "paramType": "required", | ||
| 200 | + "shape": [ | ||
| 201 | + -2 | ||
| 202 | + ], | ||
| 203 | + "format_match_mode": "FormatAgnostic" | ||
| 204 | + } | ||
| 205 | + ] | ||
| 206 | + }, | ||
| 207 | + { | ||
| 208 | + "bin_filename": "AngleV2_int16", | ||
| 209 | + "inputs": [ | ||
| 210 | + { | ||
| 211 | + "name": "x", | ||
| 212 | + "index": 0, | ||
| 213 | + "dtype": "int16", | ||
| 214 | + "format": "ND", | ||
| 215 | + "paramType": "required", | ||
| 216 | + "shape": [ | ||
| 217 | + -2 | ||
| 218 | + ], | ||
| 219 | + "format_match_mode": "FormatAgnostic" | ||
| 220 | + } | ||
| 221 | + ], | ||
| 222 | + "outputs": [ | ||
| 223 | + { | ||
| 224 | + "name": "y", | ||
| 225 | + "index": 0, | ||
| 226 | + "dtype": "float32", | ||
| 227 | + "format": "ND", | ||
| 228 | + "paramType": "required", | ||
| 229 | + "shape": [ | ||
| 230 | + -2 | ||
| 231 | + ], | ||
| 232 | + "format_match_mode": "FormatAgnostic" | ||
| 233 | + } | ||
| 234 | + ] | ||
| 235 | + }, | ||
| 236 | + { | ||
| 237 | + "bin_filename": "AngleV2_int32", | ||
| 238 | + "inputs": [ | ||
| 239 | + { | ||
| 240 | + "name": "x", | ||
| 241 | + "index": 0, | ||
| 242 | + "dtype": "int32", | ||
| 243 | + "format": "ND", | ||
| 244 | + "paramType": "required", | ||
| 245 | + "shape": [ | ||
| 246 | + -2 | ||
| 247 | + ], | ||
| 248 | + "format_match_mode": "FormatAgnostic" | ||
| 249 | + } | ||
| 250 | + ], | ||
| 251 | + "outputs": [ | ||
| 252 | + { | ||
| 253 | + "name": "y", | ||
| 254 | + "index": 0, | ||
| 255 | + "dtype": "float32", | ||
| 256 | + "format": "ND", | ||
| 257 | + "paramType": "required", | ||
| 258 | + "shape": [ | ||
| 259 | + -2 | ||
| 260 | + ], | ||
| 261 | + "format_match_mode": "FormatAgnostic" | ||
| 262 | + } | ||
| 263 | + ] | ||
| 264 | + }, | ||
| 265 | + { | ||
| 266 | + "bin_filename": "AngleV2_int64", | ||
| 267 | + "inputs": [ | ||
| 268 | + { | ||
| 269 | + "name": "x", | ||
| 270 | + "index": 0, | ||
| 271 | + "dtype": "int64", | ||
| 272 | + "format": "ND", | ||
| 273 | + "paramType": "required", | ||
| 274 | + "shape": [ | ||
| 275 | + -2 | ||
| 276 | + ], | ||
| 277 | + "format_match_mode": "FormatAgnostic" | ||
| 278 | + } | ||
| 279 | + ], | ||
| 280 | + "outputs": [ | ||
| 281 | + { | ||
| 282 | + "name": "y", | ||
| 283 | + "index": 0, | ||
| 284 | + "dtype": "float32", | ||
| 285 | + "format": "ND", | ||
| 286 | + "paramType": "required", | ||
| 287 | + "shape": [ | ||
| 288 | + -2 | ||
| 289 | + ], | ||
| 290 | + "format_match_mode": "FormatAgnostic" | ||
| 291 | + } | ||
| 292 | + ] | ||
| 293 | + } | ||
| 294 | + ] | ||
| 295 | +} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | +; [某算子] | ||
| 3 | +; default=xx | ||
| 4 | +; ascendxx=xx | ||
| 5 | +; 其中,default为默认mode,ascendxx为可选mode,如果不同芯片有差异化要求时,需要配置; | ||
| 6 | +; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 7 | +; 2)如果仅有default配置:各个版本按default配置 | ||
| 8 | +; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 9 | +; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。 | ||
| 10 | +; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式 | ||
| 11 | +; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定 | ||
| 12 | +[AngleV2] | ||
| 13 | +default=0 | ||
| @@ -60,7 +60,8 @@ extern "C" __global__ __aicore__ void angle_v2(GM_ADDR x, GM_ADDR y, GM_ADDR wor | |||
| 60 | } else if (TILING_KEY_IS(KEY_DTYPE_INT64)) { | 60 | } else if (TILING_KEY_IS(KEY_DTYPE_INT64)) { |
| 61 | RUN_ANGLE_OP(AngleV2N::AngleV2Int<int64_t, float>); | 61 | RUN_ANGLE_OP(AngleV2N::AngleV2Int<int64_t, float>); |
| 62 | } | 62 | } |
| 63 | -#if (__NPU_ARCH__ == 3510) | 63 | +// regbase 架构(950/350:3510;960DT:9201)支持 bf16 原生比较 |
| 64 | +#if ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 9201)) | ||
| 64 | else if (TILING_KEY_IS(KEY_DTYPE_BF16)) { | 65 | else if (TILING_KEY_IS(KEY_DTYPE_BF16)) { |
| 65 | RUN_ANGLE_OP(AngleV2N::AngleV2<bfloat16_t>); | 66 | RUN_ANGLE_OP(AngleV2N::AngleV2<bfloat16_t>); |
| 66 | } | 67 | } |
| @@ -1,11 +1,10 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | 2 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. |
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 4 | -# This file is a part of the CANN Open Software. | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 9 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| @@ -24,4 +23,6 @@ if (UT_TEST_ALL OR OP_KERNEL_UT) | |||
| 24 | # param3:自定义编译选项,一般填写测试的一种典型数据类型组合,不需要则传入空字符串,例如:"-DDTYPE_X=float",多个使用空格分隔,例如:"-DDTYPE_X=float -DDTYPE_Y=float" | 23 | # param3:自定义编译选项,一般填写测试的一种典型数据类型组合,不需要则传入空字符串,例如:"-DDTYPE_X=float",多个使用空格分隔,例如:"-DDTYPE_X=float -DDTYPE_Y=float" |
| 25 | # param4:该算子依赖的所有tiling源码文件 | 24 | # param4:该算子依赖的所有tiling源码文件 |
| 26 | AddOpTestCase(angle_v2 "ascend910b" "-DDTYPE_X=float" "${angle_v2_tiling_files}") | 25 | AddOpTestCase(angle_v2 "ascend910b" "-DDTYPE_X=float" "${angle_v2_tiling_files}") |
| 27 | -endif() | 26 | + AddOpTestCase(angle_v2 "ascend950" "-DDTYPE_X=float" "${angle_v2_tiling_files}") |
| 27 | + AddOpTestCase(angle_v2 "ascend960dt" "-DDTYPE_X=float" "${angle_v2_tiling_files}") | ||
| 28 | +endif() | ||
| @@ -1,13 +1,12 @@ | |||
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
| 3 | # ---------------------------------------------------------------------------- | 3 | # ---------------------------------------------------------------------------- |
| 4 | -# This program is free software, you can redistribute it and/or modify it. | 4 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. |
| 5 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 5 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 6 | -# This file is a part of the CANN Open Software. | 6 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 7 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 8 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 7 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 9 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 8 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 10 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 9 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | # See LICENSE in the root of the software repository for the full text of the License. | 10 | # See LICENSE in the root of the software repository for the full text of the License. |
| 12 | # ---------------------------------------------------------------------------- | 11 | # ---------------------------------------------------------------------------- |
| 13 | 12 | ||
| @@ -15,6 +14,7 @@ import sys | |||
| 15 | import numpy as np | 14 | import numpy as np |
| 16 | import torch | 15 | import torch |
| 17 | 16 | ||
| 17 | + | ||
| 18 | def gen_golden_data_simple(size, dtype): | 18 | def gen_golden_data_simple(size, dtype): |
| 19 | if dtype == "complex64": | 19 | if dtype == "complex64": |
| 20 | real = np.random.uniform(-100, 100, [int(size)]).astype(np.float32) | 20 | real = np.random.uniform(-100, 100, [int(size)]).astype(np.float32) |
| @@ -22,6 +22,13 @@ def gen_golden_data_simple(size, dtype): | |||
| 22 | input_x = real + imag * 1j | 22 | input_x = real + imag * 1j |
| 23 | inputX = torch.as_tensor(input_x).to(torch.complex64) | 23 | inputX = torch.as_tensor(input_x).to(torch.complex64) |
| 24 | dtype = np.float32 | 24 | dtype = np.float32 |
| 25 | + elif dtype == "bfloat16": | ||
| 26 | + input_x = np.random.uniform(-100, 100, [int(size)]).astype(np.float32) | ||
| 27 | + inputX = torch.as_tensor(input_x).to(torch.bfloat16) | ||
| 28 | + golden = torch.angle(inputX.float()).to(torch.bfloat16) | ||
| 29 | + inputX.view(torch.int16).numpy().tofile("./input_x.bin") | ||
| 30 | + golden.view(torch.int16).numpy().tofile("./golden.bin") | ||
| 31 | + return | ||
| 25 | else: | 32 | else: |
| 26 | input_x = np.random.uniform(-100, 100, [int(size)]).astype(dtype) | 33 | input_x = np.random.uniform(-100, 100, [int(size)]).astype(dtype) |
| 27 | inputX = torch.as_tensor(input_x) | 34 | inputX = torch.as_tensor(input_x) |
| @@ -35,4 +42,4 @@ def gen_golden_data_simple(size, dtype): | |||
| 35 | 42 | ||
| 36 | 43 | ||
| 37 | if __name__ == "__main__": | 44 | if __name__ == "__main__": |
| 38 | - gen_golden_data_simple(sys.argv[1], sys.argv[2]) | 45 | + gen_golden_data_simple(sys.argv[1], sys.argv[2]) |
| @@ -1,13 +1,12 @@ | |||
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
| 3 | # ---------------------------------------------------------------------------- | 3 | # ---------------------------------------------------------------------------- |
| 4 | -# This program is free software, you can redistribute it and/or modify it. | 4 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. |
| 5 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 5 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 6 | -# This file is a part of the CANN Open Software. | 6 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 7 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 8 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 7 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 9 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 8 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 10 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 9 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | # See LICENSE in the root of the software repository for the full text of the License. | 10 | # See LICENSE in the root of the software repository for the full text of the License. |
| 12 | # ---------------------------------------------------------------------------- | 11 | # ---------------------------------------------------------------------------- |
| 13 | 12 | ||
| @@ -28,29 +27,31 @@ def gen_tiling(totalLength, dtype_str): | |||
| 28 | "float32": torch.float32, | 27 | "float32": torch.float32, |
| 29 | "float": torch.float32, | 28 | "float": torch.float32, |
| 30 | "float16": torch.float16, | 29 | "float16": torch.float16, |
| 30 | + "bfloat16": torch.bfloat16, | ||
| 31 | "complex64": torch.complex64, | 31 | "complex64": torch.complex64, |
| 32 | "bool": torch.bool, | 32 | "bool": torch.bool, |
| 33 | "uint8": torch.uint8, | 33 | "uint8": torch.uint8, |
| 34 | "int8": torch.int8, | 34 | "int8": torch.int8, |
| 35 | "int16": torch.int16, | 35 | "int16": torch.int16, |
| 36 | "int32": torch.int32, | 36 | "int32": torch.int32, |
| 37 | - "int64": torch.int64 | 37 | + "int64": torch.int64, |
| 38 | } | 38 | } |
| 39 | bytesPerData = { | 39 | bytesPerData = { |
| 40 | "float32": 29, | 40 | "float32": 29, |
| 41 | "float": 29, | 41 | "float": 29, |
| 42 | "float16": 15, | 42 | "float16": 15, |
| 43 | + "bfloat16": 15, | ||
| 43 | "complex64": 66, | 44 | "complex64": 66, |
| 44 | "bool": 15, | 45 | "bool": 15, |
| 45 | "uint8": 15, | 46 | "uint8": 15, |
| 46 | "int8": 21, | 47 | "int8": 21, |
| 47 | "int16": 21, | 48 | "int16": 21, |
| 48 | "int32": 25, | 49 | "int32": 25, |
| 49 | - "int64": 33 | 50 | + "int64": 33, |
| 50 | } | 51 | } |
| 51 | outDtype = dtype_dict[dtype_str] | 52 | outDtype = dtype_dict[dtype_str] |
| 52 | 53 | ||
| 53 | - if outDtype == torch.float16: | 54 | + if outDtype in (torch.float16, torch.bfloat16): |
| 54 | ALIGN_NUM = blockSize / sizeB16 | 55 | ALIGN_NUM = blockSize / sizeB16 |
| 55 | elif outDtype == torch.int8: | 56 | elif outDtype == torch.int8: |
| 56 | ALIGN_NUM = blockSize / sizeB8 | 57 | ALIGN_NUM = blockSize / sizeB8 |
| @@ -62,11 +63,22 @@ def gen_tiling(totalLength, dtype_str): | |||
| 62 | totalLengthAligned = int(((totalLength + ALIGN_NUM - 1) / ALIGN_NUM)) * ALIGN_NUM | 63 | totalLengthAligned = int(((totalLength + ALIGN_NUM - 1) / ALIGN_NUM)) * ALIGN_NUM |
| 63 | formerNum = int(totalLengthAligned / ALIGN_NUM) % BLOCK_DIM | 64 | formerNum = int(totalLengthAligned / ALIGN_NUM) % BLOCK_DIM |
| 64 | tailNum = BLOCK_DIM - formerNum | 65 | tailNum = BLOCK_DIM - formerNum |
| 65 | - formerLength = int((int(totalLengthAligned / BLOCK_DIM) + ALIGN_NUM - 1) / ALIGN_NUM) * ALIGN_NUM | 66 | + formerLength = ( |
| 67 | + int((int(totalLengthAligned / BLOCK_DIM) + ALIGN_NUM - 1) / ALIGN_NUM) | ||
| 68 | + * ALIGN_NUM | ||
| 69 | + ) | ||
| 66 | tailLength = int(int(totalLengthAligned / BLOCK_DIM) / ALIGN_NUM) * ALIGN_NUM | 70 | tailLength = int(int(totalLengthAligned / BLOCK_DIM) / ALIGN_NUM) * ALIGN_NUM |
| 67 | 71 | ||
| 68 | - dataPerRepeat = 256 / sizeB16 if outDtype == torch.float16 else 256 / sizeB32 | 72 | + dataPerRepeat = ( |
| 69 | - tileLength = int(int((ubSizePlatForm - SELECT_MODE_GE_ZERO_TMP_UB) / bytesPerData[dtype_str]) / dataPerRepeat) * dataPerRepeat | 73 | + 256 / sizeB16 if outDtype in (torch.float16, torch.bfloat16) else 256 / sizeB32 |
| 74 | + ) | ||
| 75 | + tileLength = ( | ||
| 76 | + int( | ||
| 77 | + int((ubSizePlatForm - SELECT_MODE_GE_ZERO_TMP_UB) / bytesPerData[dtype_str]) | ||
| 78 | + / dataPerRepeat | ||
| 79 | + ) | ||
| 80 | + * dataPerRepeat | ||
| 81 | + ) | ||
| 70 | variables_dict = { | 82 | variables_dict = { |
| 71 | "totalLength": totalLength, | 83 | "totalLength": totalLength, |
| 72 | "formerNum": formerNum, | 84 | "formerNum": formerNum, |
| @@ -76,7 +88,7 @@ def gen_tiling(totalLength, dtype_str): | |||
| 76 | "alignNum": int(ALIGN_NUM), | 88 | "alignNum": int(ALIGN_NUM), |
| 77 | "totalLengthAligned": int(totalLengthAligned), | 89 | "totalLengthAligned": int(totalLengthAligned), |
| 78 | "tileLength": int(tileLength), | 90 | "tileLength": int(tileLength), |
| 79 | - "dataPerRepeat": int(dataPerRepeat) | 91 | + "dataPerRepeat": int(dataPerRepeat), |
| 80 | } | 92 | } |
| 81 | 93 | ||
| 82 | variables_array = [variables_dict[key] for key in variables_dict] | 94 | variables_array = [variables_dict[key] for key in variables_dict] |
| @@ -85,12 +97,14 @@ def gen_tiling(totalLength, dtype_str): | |||
| 85 | 97 | ||
| 86 | 98 | ||
| 87 | def main(): | 99 | def main(): |
| 88 | - params_list = gen_tiling(int(sys.argv[1]), (sys.argv[2])) # python gen_tiling.py argv1 argv2 | 100 | + params_list = gen_tiling( |
| 101 | + int(sys.argv[1]), (sys.argv[2]) | ||
| 102 | + ) # python gen_tiling.py argv1 argv2 | ||
| 89 | base_params = np.array(params_list, dtype=np.uint32) | 103 | base_params = np.array(params_list, dtype=np.uint32) |
| 90 | 104 | ||
| 91 | tiling_file = open("tiling.bin", "wb") | 105 | tiling_file = open("tiling.bin", "wb") |
| 92 | base_params.tofile(tiling_file) | 106 | base_params.tofile(tiling_file) |
| 93 | 107 | ||
| 94 | 108 | ||
| 95 | -if __name__ == '__main__': | 109 | +if __name__ == "__main__": |
| 96 | main() | 110 | main() |
| @@ -27,16 +27,13 @@ using namespace std; | |||
| 27 | 27 | ||
| 28 | extern "C" __global__ __aicore__ void angle_v2(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling); | 28 | extern "C" __global__ __aicore__ void angle_v2(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling); |
| 29 | class angle_v2_test : public testing::Test { | 29 | class angle_v2_test : public testing::Test { |
| 30 | - protected: | 30 | +protected: |
| 31 | - static void SetUpTestCase() { | 31 | + static void SetUpTestCase() { cout << "angle_v2_test SetUp\n" << endl; } |
| 32 | - cout << "angle_v2_test SetUp\n" << endl; | 32 | + static void TearDownTestCase() { cout << "angle_v2_test TearDown\n" << endl; } |
| 33 | - } | ||
| 34 | - static void TearDownTestCase() { | ||
| 35 | - cout << "angle_v2_test TearDown\n" << endl; | ||
| 36 | - } | ||
| 37 | }; | 33 | }; |
| 38 | 34 | ||
| 39 | -TEST_F(angle_v2_test, test_case_fp32) { | 35 | +TEST_F(angle_v2_test, test_case_fp32) |
| 36 | +{ | ||
| 40 | uint32_t totalLength = 8; | 37 | uint32_t totalLength = 8; |
| 41 | 38 | ||
| 42 | // inputs | 39 | // inputs |
| @@ -44,10 +41,10 @@ TEST_F(angle_v2_test, test_case_fp32) { | |||
| 44 | size_t y_size = totalLength * sizeof(float); | 41 | size_t y_size = totalLength * sizeof(float); |
| 45 | size_t tiling_data_size = sizeof(AngleV2TilingData); | 42 | size_t tiling_data_size = sizeof(AngleV2TilingData); |
| 46 | 43 | ||
| 47 | - uint8_t *x = (uint8_t*)AscendC::GmAlloc(x_size); | 44 | + uint8_t* x = (uint8_t*)AscendC::GmAlloc(x_size); |
| 48 | - uint8_t *y = (uint8_t*)AscendC::GmAlloc(y_size); | 45 | + uint8_t* y = (uint8_t*)AscendC::GmAlloc(y_size); |
| 49 | - uint8_t *workspace = (uint8_t *)AscendC::GmAlloc(1024 * 16 * 1024); | 46 | + uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(1024 * 16 * 1024); |
| 50 | - uint8_t *tiling = (uint8_t *)AscendC::GmAlloc(tiling_data_size); | 47 | + uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size); |
| 51 | uint32_t numBlocks = 1; | 48 | uint32_t numBlocks = 1; |
| 52 | system("cp -r ../../../../math/angle_v2/tests/ut/op_kernel/angle_v2_data ./"); | 49 | system("cp -r ../../../../math/angle_v2/tests/ut/op_kernel/angle_v2_data ./"); |
| 53 | system("chmod -R 755 ./angle_v2_data/"); | 50 | system("chmod -R 755 ./angle_v2_data/"); |
| @@ -55,7 +52,7 @@ TEST_F(angle_v2_test, test_case_fp32) { | |||
| 55 | system("cd ./angle_v2_data/ && python3 gen_data.py 8 float32"); | 52 | system("cd ./angle_v2_data/ && python3 gen_data.py 8 float32"); |
| 56 | system("cd ./angle_v2_data/ && python3 gen_tiling.py 8 float32"); | 53 | system("cd ./angle_v2_data/ && python3 gen_tiling.py 8 float32"); |
| 57 | 54 | ||
| 58 | - char * path_ = get_current_dir_name(); | 55 | + char* path_ = get_current_dir_name(); |
| 59 | string path(path_); | 56 | string path(path_); |
| 60 | ReadFile(path + "/angle_v2_data/input_x.bin", x_size, x, x_size); | 57 | ReadFile(path + "/angle_v2_data/input_x.bin", x_size, x, x_size); |
| 61 | ReadFile(path + "/angle_v2_data/tiling.bin", tiling_data_size, tiling, tiling_data_size); | 58 | ReadFile(path + "/angle_v2_data/tiling.bin", tiling_data_size, tiling, tiling_data_size); |
| @@ -72,8 +69,8 @@ TEST_F(angle_v2_test, test_case_fp32) { | |||
| 72 | tilingDatafromBin->dataPerRepeat = 64; | 69 | tilingDatafromBin->dataPerRepeat = 64; |
| 73 | 70 | ||
| 74 | auto angle_v2_kernel = [](GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) { | 71 | auto angle_v2_kernel = [](GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) { |
| 75 | - ::angle_v2(x, y, workspace, tiling); | 72 | + ::angle_v2(x, y, workspace, tiling); |
| 76 | - }; | 73 | + }; |
| 77 | 74 | ||
| 78 | ICPU_SET_TILING_KEY(2); | 75 | ICPU_SET_TILING_KEY(2); |
| 79 | AscendC::SetKernelMode(KernelMode::AIV_MODE); | 76 | AscendC::SetKernelMode(KernelMode::AIV_MODE); |
| @@ -85,3 +82,56 @@ TEST_F(angle_v2_test, test_case_fp32) { | |||
| 85 | AscendC::GmFree(tiling); | 82 | AscendC::GmFree(tiling); |
| 86 | free(path_); | 83 | free(path_); |
| 87 | } | 84 | } |
| 85 | + | ||
| 86 | +#if ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 9201)) | ||
| 87 | +TEST_F(angle_v2_test, test_case_bf16) | ||
| 88 | +{ | ||
| 89 | + uint32_t totalLength = 16; | ||
| 90 | + | ||
| 91 | + // inputs | ||
| 92 | + size_t x_size = totalLength * sizeof(uint16_t); | ||
| 93 | + size_t y_size = totalLength * sizeof(uint16_t); | ||
| 94 | + size_t tiling_data_size = sizeof(AngleV2TilingData); | ||
| 95 | + | ||
| 96 | + uint8_t* x = (uint8_t*)AscendC::GmAlloc(x_size); | ||
| 97 | + uint8_t* y = (uint8_t*)AscendC::GmAlloc(y_size); | ||
| 98 | + uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(1024 * 16 * 1024); | ||
| 99 | + uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size); | ||
| 100 | + uint32_t numBlocks = 1; | ||
| 101 | + system("cp -r ../../../../math/angle_v2/tests/ut/op_kernel/angle_v2_data ./"); | ||
| 102 | + system("chmod -R 755 ./angle_v2_data/"); | ||
| 103 | + system("cd ./angle_v2_data/ && rm -rf ./*bin"); | ||
| 104 | + system("cd ./angle_v2_data/ && python3 gen_data.py 16 bfloat16"); | ||
| 105 | + system("cd ./angle_v2_data/ && python3 gen_tiling.py 16 bfloat16"); | ||
| 106 | + | ||
| 107 | + char* path_ = get_current_dir_name(); | ||
| 108 | + string path(path_); | ||
| 109 | + ReadFile(path + "/angle_v2_data/input_x.bin", x_size, x, x_size); | ||
| 110 | + ReadFile(path + "/angle_v2_data/tiling.bin", tiling_data_size, tiling, tiling_data_size); | ||
| 111 | + | ||
| 112 | + AngleV2TilingData* tilingDatafromBin = reinterpret_cast<AngleV2TilingData*>(tiling); | ||
| 113 | + tilingDatafromBin->totalLength = 16; | ||
| 114 | + tilingDatafromBin->formerNum = 1; | ||
| 115 | + tilingDatafromBin->tailNum = 47; | ||
| 116 | + tilingDatafromBin->formerLength = 16; | ||
| 117 | + tilingDatafromBin->tailLength = 0; | ||
| 118 | + tilingDatafromBin->alignNum = 16; | ||
| 119 | + tilingDatafromBin->totalLengthAligned = 16; | ||
| 120 | + tilingDatafromBin->tileLength = 12160; | ||
| 121 | + tilingDatafromBin->dataPerRepeat = 128; | ||
| 122 | + | ||
| 123 | + auto angle_v2_kernel = [](GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) { | ||
| 124 | + ::angle_v2(x, y, workspace, tiling); | ||
| 125 | + }; | ||
| 126 | + | ||
| 127 | + ICPU_SET_TILING_KEY(10); | ||
| 128 | + AscendC::SetKernelMode(KernelMode::AIV_MODE); | ||
| 129 | + ICPU_RUN_KF(angle_v2_kernel, numBlocks, x, y, workspace, tiling); | ||
| 130 | + | ||
| 131 | + AscendC::GmFree(x); | ||
| 132 | + AscendC::GmFree(y); | ||
| 133 | + AscendC::GmFree(workspace); | ||
| 134 | + AscendC::GmFree(tiling); | ||
| 135 | + free(path_); | ||
| 136 | +} | ||
| 137 | +#endif | ||
🟡 Medium Priority
变更行:
this->AICore().AddConfig("ascend960dt", aicore_a5_config);(本算子首次声明支持 ascend960dt)。证据链:
op_host/config/下原本严格按 AddConfig 的每个 soc 一一对应存在目录:ascend910 / ascend910_93 / ascend910b / ascend950 / kirinx90 / kirin9030(各含angle_v2_binary.json与angle_v2_simplified_key.ini,共 12 个文件)。本次新增 ascend960dt 后,未同步新增op_host/config/ascend960dt/angle_v2_binary.json(及可选的angle_v2_simplified_key.ini),该目录成为唯一缺口。math/*/op_host/config/ascend960dt/**共 218 个文件,即所有已在 def 中声明 ascend960dt 的算子(abs、expm1、complex_abs、reduce_sum 等约 109 个)都同时提供了该 soc 的 binary 配置;本算子成为唯一"声明支持但没有 960DT binary 配置"的例外。*_binary.json,说明这些文件由算子编译/打包工具按op_host/config/<soc>/目录约定消费;因此新增 soc 而缺目录时,960DT 侧可能拿不到 kernel binary 与 simplified key 映射。失败模式:编译 960DT 版本时该算子的 kernel binary 配置缺失(或被回落处理),导致 960DT 上 AngleV2 无可用 kernel / binary 与 op info 不一致(运行时报找不到 kernel 或回落异常),使本次"960dt 适配"实际不可用。触发条件:以 ascend960dt 为目标编译/打包并下发该算子。
建议:补齐 op_host/config/ascend960dt/angle_v2_binary.json(必要时含 angle_v2_simplified_key.ini),与本算子 ascend950 等其他 soc 的配置目录结构一致;若确认可复用 ascend950 的配置,请加注释说明复用规则。