Merged
test(fused_infer_attention_score): 新增arch38 tiling UT用例并打通UT框架 #17489
HuLinjieAdd on 2 days ago
test(fused_infer_attention_score): 新增arch38 tiling UT用例并打通UT框架 #17489
Merged
HuLinjieAdd on 2 days ago
Total: 6 files changed+303-5
@@ -0,0 +1,13 @@
1+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3+# CANN Open Software License Agreement Version 2.0 (the "License").
4+# Please refer to the License for details. You may not use this file except in compliance with the License.
5+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
6+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
7+# See LICENSE in the root of the software repository for the full text of the License.
8+# ======================================================================================================================
9+ 
10+ 
11+if(UT_TEST_ALL OR OP_HOST_UT)
12+ add_modules_ut_sources(UT_NAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
13+endif()
@@ -0,0 +1,178 @@
1+/**
2+ * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#include <gtest/gtest.h>
12+#include "../fused_infer_attention_score_param.h"
13+#include "../../../../op_host/fused_infer_attention_score_tiling_compile_info.h"
14+#include "tiling_case_executor.h"
15+ 
16+namespace FusedInferAttentionScoreUT {
17+ 
18+class FusedInferAttentionScoreArch38TilingTest : public testing::TestWithParam<FusedInferAttentionTilingUtParam> {
19+protected:
20+ static void SetUpTestCase() {}
21+ 
22+ static void TearDownTestCase() {}
23+};
24+ 
25+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FusedInferAttentionScoreArch38TilingTest);
26+ 
27+TEST_P(FusedInferAttentionScoreArch38TilingTest, param)
28+{
29+ auto param = GetParam();
30+ optiling::FusedInferAttentionScoreCompileInfo compileInfo = {};
31+ 
32+ // arch38 (mc62, NpuArch=5102) 硬件参数:
33+ // L0A/L0B 64KB、L0C 256KB、L1 1MB、UB 248KB、L2 32MB、BT 4KB、cube/vector 各 16 核。
34+ const std::string Arch38SocInfo = "{\n"
35+ " \"hardware_info\": {\n"
36+ " \"BT_SIZE\": 4096,\n"
37+ " \"load3d_constraints\": \"1\",\n"
38+ " \"Intrinsic_fix_pipe_l0c2out\": false,\n"
39+ " \"Intrinsic_data_move_l12ub\": true,\n"
40+ " \"Intrinsic_data_move_l0c2ub\": true,\n"
41+ " \"Intrinsic_data_move_out2l1_nd2nz\": false,\n"
42+ " \"UB_SIZE\": 253952,\n"
43+ " \"L2_SIZE\": 33554432,\n"
44+ " \"L1_SIZE\": 1048576,\n"
45+ " \"L0A_SIZE\": 65536,\n"
46+ " \"L0B_SIZE\": 65536,\n"
47+ " \"L0C_SIZE\": 262144,\n"
48+ " \"cube_core_cnt\": 16,\n"
49+ " \"vector_core_cnt\": 16,\n"
50+ " \"socVersion\": \"MC62\"\n"
51+ " }\n"
52+ "}";
53+ 
54+ const std::vector<gert::TilingContextPara::OpAttr> attrs = {
55+ {"num_heads", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.num_heads)},
56+ {"scale", Ops::Transformer::AnyValue::CreateFrom<float>(param.scale)},
57+ {"pre_tokens", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.pre_tokens)},
58+ {"next_tokens", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.next_tokens)},
59+ {"input_layout", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.input_layout)},
60+ {"num_key_value_heads", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.num_key_value_heads)},
61+ {"sparse_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.sparse_mode)},
62+ {"inner_precise", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.inner_precise)},
63+ {"block_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.block_size)},
64+ {"antiquant_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.antiquant_mode)},
65+ {"softmax_lse_flag", Ops::Transformer::AnyValue::CreateFrom<bool>(param.softmax_lse_flag)},
66+ {"key_antiquant_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.key_antiquant_mode)},
67+ {"value_antiquant_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.value_antiquant_mode)},
68+ {"query_quant_mode", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.query_quant_mode)},
69+ {"pse_type", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.pse_type)},
70+ {"out_dtype", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.out_dtype)},
71+ };
72+ 
73+ if (!param.isTensorList) {
74+ gert::TilingContextPara tilingContextPara("FusedInferAttentionScore",
75+ {param.query,
76+ param.key,
77+ param.value,
78+ param.pse_shift,
79+ param.atten_mask,
80+ param.actual_seq_lengths,
81+ param.actual_seq_lengths_kv,
82+ param.dequant_scale1,
83+ param.quant_scale1,
84+ param.dequant_scale2,
85+ param.quant_scale2,
86+ param.quant_offset2,
87+ param.antiquant_scale,
88+ param.antiquant_offset,
89+ param.block_table,
90+ param.query_padding_size,
91+ param.kv_padding_size,
92+ param.key_antiquant_scale,
93+ param.key_antiquant_offset,
94+ param.value_antiquant_scale,
95+ param.value_antiquant_offset,
96+ param.key_shared_prefix,
97+ param.value_shared_prefix,
98+ param.actual_shared_prefix_len,
99+ param.query_rope,
100+ param.key_rope,
101+ param.key_rope_antiquant_scale,
102+ param.dequant_scale_query,
103+ param.learnable_sink,
104+ param.q_start_idx,
105+ param.kv_start_idx},
106+ {param.attention_out, param.softmax_lse}, attrs, &compileInfo, "5102",
107+ 16, 253952, 16384, Arch38SocInfo);
108+ ExecuteTestCase(tilingContextPara, param.expectResult, param.expectTilingKey, param.expectTilingDataHash, {}, 0,
109+ true);
110+ return;
111+ }
112+ 
113+ const std::vector<gert::TilingContextPara::TensorDescription> allInputs = {param.query,
114+ param.key,
115+ param.value,
116+ param.pse_shift,
117+ param.atten_mask,
118+ param.actual_seq_lengths,
119+ param.actual_seq_lengths_kv,
120+ param.dequant_scale1,
121+ param.quant_scale1,
122+ param.dequant_scale2,
123+ param.quant_scale2,
124+ param.quant_offset2,
125+ param.antiquant_scale,
126+ param.antiquant_offset,
127+ param.block_table,
128+ param.query_padding_size,
129+ param.kv_padding_size,
130+ param.key_antiquant_scale,
131+ param.key_antiquant_offset,
132+ param.value_antiquant_scale,
133+ param.value_antiquant_offset,
134+ param.key_shared_prefix,
135+ param.value_shared_prefix,
136+ param.actual_shared_prefix_len,
137+ param.query_rope,
138+ param.key_rope,
139+ param.key_rope_antiquant_scale,
140+ param.dequant_scale_query,
141+ param.learnable_sink,
142+ param.q_start_idx,
143+ param.kv_start_idx};
144+ 
145+ std::vector<gert::TilingContextPara::TensorDescription> inputTensors;
146+ std::vector<uint32_t> inputInstanceNum;
147+ inputTensors.emplace_back(allInputs[0]);
148+ inputInstanceNum.emplace_back(1);
149+ for (const auto& t : param.keyList) {
150+ inputTensors.emplace_back(t);
151+ }
152+ inputInstanceNum.emplace_back(static_cast<uint32_t>(param.keyList.size()));
153+ for (const auto& t : param.valueList) {
154+ inputTensors.emplace_back(t);
155+ }
156+ inputInstanceNum.emplace_back(static_cast<uint32_t>(param.valueList.size()));
157+ for (size_t i = 3; i < allInputs.size(); ++i) {
158+ bool present = allInputs[i].shape_.GetStorageShape().GetDimNum() != 0;
159+ if (present) {
160+ inputTensors.emplace_back(allInputs[i]);
161+ }
162+ inputInstanceNum.emplace_back(present ? 1U : 0U);
163+ }
164+ std::vector<uint32_t> outputInstanceNum = {param.attention_out.shape_.GetStorageShape().GetDimNum() != 0 ? 1U : 0U,
165+ param.softmax_lse.shape_.GetStorageShape().GetDimNum() != 0 ? 1U : 0U};
166+ 
167+ gert::TilingContextPara tilingContextPara(
168+ "FusedInferAttentionScore", inputTensors, {param.attention_out, param.softmax_lse}, attrs, inputInstanceNum,
169+ outputInstanceNum, &compileInfo, "5102", 16, 253952, 16384, Arch38SocInfo);
170+ ExecuteTestCase(tilingContextPara, param.expectResult, param.expectTilingKey, param.expectTilingDataHash, {}, 0,
171+ true);
172+}
173+INSTANTIATE_TEST_SUITE_P(
174+ FusedInferAttentionScoreArch38, FusedInferAttentionScoreArch38TilingTest,
175+ testing::ValuesIn(GetCasesFromCsv<FusedInferAttentionTilingUtParam>(ReplaceFileExtension2Csv(__FILE__))),
176+ PrintCaseInfoString<FusedInferAttentionTilingUtParam>);
177+ 
178+} // namespace FusedInferAttentionScoreUT
@@ -2531,7 +2531,7 @@ function build_pr_ut_exclude_mc2()
2531 fi2531 fi
2532 CUSTOM_OPTION="${CUSTOM_OPTION} -DTESTS_UT_OPS_TEST_CI_PR=ON"2532 CUSTOM_OPTION="${CUSTOM_OPTION} -DTESTS_UT_OPS_TEST_CI_PR=ON"
2533 CUSTOM_OPTION="${CUSTOM_OPTION} -DTESTS_UT_OPS_TEST=${TEST_EXCLUDE_MC2}"2533 CUSTOM_OPTION="${CUSTOM_OPTION} -DTESTS_UT_OPS_TEST=${TEST_EXCLUDE_MC2}"
2534- process_soc_input "ascend310p,ascend910b,ascend950,ascend350"2534+ process_soc_input "ascend310p,ascend910b,ascend950,ascend350,mc62"
2535 set_compute_unit_option_ut2535 set_compute_unit_option_ut
2536 build_ut ${BUILD}2536 build_ut ${BUILD}
2537}2537}
@@ -444,7 +444,6 @@ attention:
444 - attention/fused_infer_attention_score/op_kernel444 - attention/fused_infer_attention_score/op_kernel
445 - attention/fused_infer_attention_score/tests445 - attention/fused_infer_attention_score/tests
446 - attention/fused_infer_attention_score/op_host/arch22446 - attention/fused_infer_attention_score/op_host/arch22
447- - attention/fused_infer_attention_score/op_host/arch38 # arch38 tiling 目前UT框架不支持(会被高级api拦截走不进去tiling,后续打通后开放)
448 test:447 test:
449 ut: True448 ut: True
450 examples: False449 examples: False
@@ -160,14 +160,17 @@
160 map<string, string> versions; \160 map<string, string> versions; \
161 string version = tilingContextPara.socVersion_; \161 string version = tilingContextPara.socVersion_; \
162 if (isNpuArchString(version)) { \162 if (isNpuArchString(version)) { \
163- map<string, string> archToSoc = { \163+ map<string, string> archToSoc = {{"3510", "Ascend950"}, \
164- {"3510", "Ascend950"}, {"9201", "Ascend960DT"}, {"3003", "KirinX90"}, {"3113", "Kirin9030"}}; \164+ {"9201", "Ascend960DT"}, \
165+ {"3003", "KirinX90"}, \
166+ {"3113", "Kirin9030"}, \
167+ {"5102", "MC62"}}; \
165 versions = {{"NpuArch", tilingContextPara.socVersion_}, \168 versions = {{"NpuArch", tilingContextPara.socVersion_}, \
166 {"Short_SoC_version", archToSoc[tilingContextPara.socVersion_]}}; \169 {"Short_SoC_version", archToSoc[tilingContextPara.socVersion_]}}; \
167 } else { \170 } else { \
168 map<string, string> socToArch = {{"Ascend310P", "2002"}, {"Ascend910B", "2201"}, {"Ascend910_93", "2201"}, \171 map<string, string> socToArch = {{"Ascend310P", "2002"}, {"Ascend910B", "2201"}, {"Ascend910_93", "2201"}, \
169 {"Ascend950", "3510"}, {"Ascend960DT", "9201"}, {"KirinX90", "3003"}, \172 {"Ascend950", "3510"}, {"Ascend960DT", "9201"}, {"KirinX90", "3003"}, \
170- {"Kirin9030", "3113"}}; \173+ {"Kirin9030", "3113"}, {"MC62", "5102"}}; \
171 versions = {{"NpuArch", socToArch[tilingContextPara.socVersion_]}, \174 versions = {{"NpuArch", socToArch[tilingContextPara.socVersion_]}, \
172 {"Short_SoC_version", tilingContextPara.socVersion_}}; \175 {"Short_SoC_version", tilingContextPara.socVersion_}}; \
173 } \176 } \