Merged
fix(xlogy): Tiling入口补输入dtype一致性校验与rank上界校验 #7110
fix(xlogy): Tiling入口补输入dtype一致性校验与rank上界校验 #7110
Merged
zhaoxinmengAdd on 9 days ago
Total: 2 files changed+183-0
@@ -33,6 +33,7 @@ namespace xlogy {
33// === 算子特定常量 — 新算子必须修改 ===33// === 算子特定常量 — 新算子必须修改 ===
34constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)34constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)
35constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)35constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)
36+constexpr int64_t kMaxRank = 8; // 模板支持的最大 rank(RANK_8D 模板)
36constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)37constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)
37 38 
38// 5.1 PadAndSqueeze39// 5.1 PadAndSqueeze
@@ -229,6 +230,17 @@ ge::graphStatus XlogyTiling::GetShapeInfo()
229 230 
230 auto inputDesc = ctx_->GetInputDesc(0);231 auto inputDesc = ctx_->GetInputDesc(0);
231 OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);232 OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);
233+ auto otherDesc = ctx_->GetInputDesc(1);
234+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, otherDesc);
235+ if (inputDesc->GetDataType() != otherDesc->GetDataType()) {
236+ OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(
237+ ctx_->GetNodeName(), "x1 and x2",
238+ (ge::TypeUtils::DataTypeToAscendString(inputDesc->GetDataType()).GetString() + std::string(" and ") +
239+ ge::TypeUtils::DataTypeToAscendString(otherDesc->GetDataType()).GetString())
240+ .c_str(),
241+ "x1 and x2 must have the same dtype");
242+ return ge::GRAPH_FAILED;
243+ }
232 ge::DataType dtype = inputDesc->GetDataType();244 ge::DataType dtype = inputDesc->GetDataType();
233 if (dtype == ge::DT_FLOAT) {245 if (dtype == ge::DT_FLOAT) {
234 dtype_size_ = 4;246 dtype_size_ = 4;
@@ -243,6 +255,11 @@ ge::graphStatus XlogyTiling::GetShapeInfo()
243 255 
244 PadAndSqueeze(raw_input_shapes_, raw_output_shapes_, max_bro_shape_, normal_input_shapes_, normal_output_shapes_);256 PadAndSqueeze(raw_input_shapes_, raw_output_shapes_, max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
245 rank_ = (int64_t)max_bro_shape_.size();257 rank_ = (int64_t)max_bro_shape_.size();
258+ if (rank_ > kMaxRank) {
259+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(ctx_->GetNodeName(), "x1/x2", std::to_string(rank_).c_str(),
260+ "input rank must be within [0, 8]");
261+ return ge::GRAPH_FAILED;
262+ }
246 263 
247 OP_LOGI(ctx_->GetNodeName(), "Xlogy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu", rank_, phys_nodes_,264 OP_LOGI(ctx_->GetNodeName(), "Xlogy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu", rank_, phys_nodes_,
248 compileInfo->ubSize, compileInfo->coreNum);265 compileInfo->ubSize, compileInfo->coreNum);
@@ -0,0 +1,166 @@
1+/**
2+ * Copyright (c) 2026 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+ * 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+/*!
12+ * \file test_xlogy_tiling_arch35.cpp
13+ * \brief Xlogy tiling ut:覆盖输入dtype一致性校验与rank上界校验,以及正常shape的tiling执行
14+ */
15+ 
16+#include "../../../../op_host/arch35/xlogy_tiling_arch35.h"
17+#include <iostream>
18+#include <gtest/gtest.h>
19+#include "tiling_context_faker.h"
20+#include "tiling_case_executor.h"
21+ 
22+using namespace std;
23+ 
24+class XlogyTilingTest : public testing::Test {
25+protected:
26+ static void SetUpTestCase() { std::cout << "XlogyTilingTest SetUp" << std::endl; }
27+ 
28+ static void TearDownTestCase() { std::cout << "XlogyTilingTest TearDown" << std::endl; }
29+};
30+ 
31+// 正常用例:fp16 同dtype、4维,tiling执行成功
32+TEST_F(XlogyTilingTest, test_tiling_fp16_success)
33+{
34+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
35+ gert::TilingContextPara tilingContextPara("Xlogy",
36+ {
37+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
38+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
39+ },
40+ {
41+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
42+ },
43+ {}, &compileInfo);
44+ TilingInfo tilingInfo;
45+ auto ret = ExecuteTiling(tilingContextPara, tilingInfo);
46+ EXPECT_TRUE(ret);
47+}
48+ 
49+// 正常用例:fp32 广播shape(x1为{4,2},x2为{2}),tiling执行成功
50+TEST_F(XlogyTilingTest, test_tiling_fp32_broadcast_success)
51+{
52+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
53+ gert::TilingContextPara tilingContextPara("Xlogy",
54+ {
55+ {{{4, 2}, {4, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
56+ {{{2}, {2}}, ge::DT_FLOAT, ge::FORMAT_ND},
57+ },
58+ {
59+ {{{4, 2}, {4, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
60+ },
61+ {}, &compileInfo);
62+ TilingInfo tilingInfo;
63+ auto ret = ExecuteTiling(tilingContextPara, tilingInfo);
64+ EXPECT_TRUE(ret);
65+}
66+ 
67+// 正常用例:bf16 8维,tiling执行成功
68+TEST_F(XlogyTilingTest, test_tiling_bf16_rank8_success)
69+{
70+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
71+ gert::TilingContextPara tilingContextPara(
72+ "Xlogy",
73+ {
74+ {{{2, 3, 4, 5, 6, 7, 8, 2}, {2, 3, 4, 5, 6, 7, 8, 2}}, ge::DT_BF16, ge::FORMAT_ND},
75+ {{{2, 3, 4, 5, 6, 7, 8, 1}, {2, 3, 4, 5, 6, 7, 8, 1}}, ge::DT_BF16, ge::FORMAT_ND},
76+ },
77+ {
78+ {{{2, 3, 4, 5, 6, 7, 8, 2}, {2, 3, 4, 5, 6, 7, 8, 2}}, ge::DT_BF16, ge::FORMAT_ND},
79+ },
80+ {}, &compileInfo);
81+ TilingInfo tilingInfo;
82+ auto ret = ExecuteTiling(tilingContextPara, tilingInfo);
83+ EXPECT_TRUE(ret);
84+}
85+ 
86+// 输入dtype不一致:x1为FP16、x2为FP32,tiling失败
87+TEST_F(XlogyTilingTest, test_tiling_dtype_mismatch_failed)
88+{
89+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
90+ gert::TilingContextPara tilingContextPara("Xlogy",
91+ {
92+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
93+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND},
94+ },
95+ {
96+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
97+ },
98+ {}, &compileInfo);
99+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
100+}
101+ 
102+// 输入dtype不一致:x1为BF16、x2为FP16,tiling失败
103+TEST_F(XlogyTilingTest, test_tiling_dtype_mismatch_bf16_failed)
104+{
105+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
106+ gert::TilingContextPara tilingContextPara("Xlogy",
107+ {
108+ {{{8, 4}, {8, 4}}, ge::DT_BF16, ge::FORMAT_ND},
109+ {{{8, 4}, {8, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND},
110+ },
111+ {
112+ {{{8, 4}, {8, 4}}, ge::DT_BF16, ge::FORMAT_ND},
113+ },
114+ {}, &compileInfo);
115+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
116+}
117+ 
118+// rank越界:归一化后仍为9维(各维均非1,不会被PadAndSqueeze压缩),超过最大rank 8,tiling失败
119+TEST_F(XlogyTilingTest, test_tiling_rank_exceed_failed)
120+{
121+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
122+ gert::TilingContextPara tilingContextPara(
123+ "Xlogy",
124+ {
125+ {{{2, 3, 4, 5, 6, 7, 8, 2, 2}, {2, 3, 4, 5, 6, 7, 8, 2, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
126+ {{{2, 3, 4, 5, 6, 7, 8, 2, 2}, {2, 3, 4, 5, 6, 7, 8, 2, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
127+ },
128+ {
129+ {{{2, 3, 4, 5, 6, 7, 8, 2, 2}, {2, 3, 4, 5, 6, 7, 8, 2, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
130+ },
131+ {}, &compileInfo);
132+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
133+}
134+ 
135+// rank越界:广播归一化后rank超过8(x1为9维、x2为低维广播),tiling失败
136+TEST_F(XlogyTilingTest, test_tiling_rank_exceed_broadcast_failed)
137+{
138+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
139+ gert::TilingContextPara tilingContextPara(
140+ "Xlogy",
141+ {
142+ {{{2, 3, 4, 5, 6, 7, 8, 2, 2}, {2, 3, 4, 5, 6, 7, 8, 2, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
143+ {{{2}, {2}}, ge::DT_FLOAT, ge::FORMAT_ND},
144+ },
145+ {
146+ {{{2, 3, 4, 5, 6, 7, 8, 2, 2}, {2, 3, 4, 5, 6, 7, 8, 2, 2}}, ge::DT_FLOAT, ge::FORMAT_ND},
147+ },
148+ {}, &compileInfo);
149+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
150+}
151+ 
152+// 不支持dtype:x1/x2为INT32,tiling失败
153+TEST_F(XlogyTilingTest, test_tiling_unsupported_dtype_failed)
154+{
155+ optiling::XlogyCompileInfo compileInfo = {64, 262144};
156+ gert::TilingContextPara tilingContextPara("Xlogy",
157+ {
158+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND},
159+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND},
160+ },
161+ {
162+ {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND},
163+ },
164+ {}, &compileInfo);
165+ ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED);
166+}