已合并
test:add ut for triangular rightshift squared_diffence #1406
zhaowenrui创建于 2月28日
test:add ut for triangular rightshift squared_diffence #1406
已合并
zhaowenrui创建于 2月28日
9 个文件变更+1066-141
Mmath/right_shift/tests/ut/op_kernel_aicpu/test_right_shift.cpp+138-0
@@ -307,4 +307,142 @@ TEST_F(TEST_RIGHTSHIFT_UT, INPUT2_NEGATIVE_OR_GREATER)
307 307 
308 bool compare = CompareResult(output, output_exp, 6);308 bool compare = CompareResult(output, output_exp, 6);
309 EXPECT_EQ(compare, true);309 EXPECT_EQ(compare, true);
310}
311 
312TEST_F(TEST_RIGHTSHIFT_UT, DATA_TYPE_INT16_SUCC)
313{
314 vector<DataType> data_types = {DT_INT16, DT_INT16, DT_INT16};
315 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
316 const int16_t input1[6] = {100, 50, 25, 12, 8, 4};
317 const int16_t input2[6] = {2, 3, 1, 2, 1, 2};
318 int16_t output[6] = {0};
319 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
320 
321 CREATE_NODEDEF(shapes, data_types, datas);
322 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
323 
324 int16_t output_exp[6] = {25, 6, 12, 3, 4, 1};
325 bool compare = CompareResult(output, output_exp, 6);
326 EXPECT_EQ(compare, true);
327}
328 
329TEST_F(TEST_RIGHTSHIFT_UT, DATA_TYPE_INT64_SUCC)
330{
331 vector<DataType> data_types = {DT_INT64, DT_INT64, DT_INT64};
332 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
333 const int64_t input1[6] = {1000, 500, 250, 125, 62, 31};
334 const int64_t input2[6] = {3, 4, 2, 3, 1, 2};
335 int64_t output[6] = {0};
336 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
337 
338 CREATE_NODEDEF(shapes, data_types, datas);
339 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
340 
341 int64_t output_exp[6] = {125, 31, 62, 15, 31, 7};
342 bool compare = CompareResult(output, output_exp, 6);
343 EXPECT_EQ(compare, true);
344}
345 
346TEST_F(TEST_RIGHTSHIFT_UT, DATA_TYPE_UINT8_SUCC)
347{
348 vector<DataType> data_types = {DT_UINT8, DT_UINT8, DT_UINT8};
349 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
350 const uint8_t input1[6] = {200, 100, 50, 25, 12, 6};
351 const uint8_t input2[6] = {2, 3, 1, 2, 1, 1};
352 uint8_t output[6] = {0};
353 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
354 
355 CREATE_NODEDEF(shapes, data_types, datas);
356 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
357 
358 uint8_t output_exp[6] = {50, 12, 25, 6, 6, 3};
359 bool compare = CompareResult(output, output_exp, 6);
360 EXPECT_EQ(compare, true);
361}
362 
363TEST_F(TEST_RIGHTSHIFT_UT, LARGE_DATA_NOBCAST_PARALLEL_SUCC)
364{
365 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
366 vector<vector<int64_t>> shapes = {{64, 32}, {64, 32}, {64, 32}};
367 
368 constexpr uint64_t input1_size = 64 * 32;
369 int32_t input1[input1_size];
370 for (int64_t i = 0; i < input1_size; ++i) {
371 input1[i] = static_cast<int32_t>((i + 100) % 1000);
372 }
373 
374 constexpr uint64_t input2_size = 64 * 32;
375 int32_t input2[input2_size];
376 for (int64_t i = 0; i < input2_size; ++i) {
377 input2[i] = static_cast<int32_t>((i + 1) % 4);
378 }
379 
380 constexpr uint64_t output_size = 64 * 32;
381 int32_t output[output_size] = {0};
382 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
383 
384 CREATE_NODEDEF(shapes, data_types, datas);
385 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
386 
387 int32_t output_exp[output_size];
388 int32_t* in1_clamped = new int32_t[input2_size];
389 for (int64_t i = 0; i < input2_size; i++) {
390 in1_clamped[i] = input2[i];
391 if (in1_clamped[i] < 0) {
392 in1_clamped[i] = 0;
393 } else if (in1_clamped[i] > static_cast<int32_t>(sizeof(int32_t) * CHAR_BIT) - 1) {
394 in1_clamped[i] = static_cast<int32_t>(sizeof(int32_t) * CHAR_BIT) - 1;
395 }
396 }
397 for (int64_t i = 0; i < output_size; ++i) {
398 output_exp[i] = input1[i] >> in1_clamped[i];
399 }
400 delete[] in1_clamped;
401 
402 bool compare = CompareResult(output, output_exp, output_size);
403 EXPECT_EQ(compare, true);
404}
405 
406TEST_F(TEST_RIGHTSHIFT_UT, LARGE_DATA_BCAST_PARALLEL_SUCC)
407{
408 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
409 vector<vector<int64_t>> shapes = {{64, 32}, {32}, {64, 32}};
410 
411 constexpr uint64_t input1_size = 64 * 32;
412 int32_t input1[input1_size];
413 for (int64_t i = 0; i < input1_size; ++i) {
414 input1[i] = static_cast<int32_t>((i + 100) % 1000);
415 }
416 
417 constexpr uint64_t input2_size = 32;
418 int32_t input2[input2_size];
419 for (int64_t i = 0; i < input2_size; ++i) {
420 input2[i] = static_cast<int32_t>((i + 1) % 4);
421 }
422 
423 constexpr uint64_t output_size = 64 * 32;
424 int32_t output[output_size] = {0};
425 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
426 
427 CREATE_NODEDEF(shapes, data_types, datas);
428 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
429 
430 int32_t output_exp[output_size];
431 int32_t* in1_clamped = new int32_t[input2_size];
432 for (int64_t i = 0; i < input2_size; i++) {
433 in1_clamped[i] = input2[i];
434 if (in1_clamped[i] < 0) {
435 in1_clamped[i] = 0;
436 } else if (in1_clamped[i] > static_cast<int32_t>(sizeof(int32_t) * CHAR_BIT) - 1) {
437 in1_clamped[i] = static_cast<int32_t>(sizeof(int32_t) * CHAR_BIT) - 1;
438 }
439 }
440 for (int64_t i = 0; i < output_size; ++i) {
441 int64_t idx = i % input2_size;
442 output_exp[i] = input1[i] >> in1_clamped[idx];
443 }
444 delete[] in1_clamped;
445 
446 bool compare = CompareResult(output, output_exp, output_size);
447 EXPECT_EQ(compare, true);
310}448}
Mmath/squared_difference/tests/ut/op_kernel_aicpu/test_squared_difference.cpp+304-109
@@ -1,109 +1,304 @@
1/**1/**
2 * Copyright (c) 2025 Huawei Technologies Co., Ltd.2 * 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 of3 * 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").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.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,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.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.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11#include "gtest/gtest.h"11#include "gtest/gtest.h"
12#ifndef private12#ifndef private
13#define private public13#define private public
14#define protected public14#define protected public
15#endif15#endif
16#include "utils/aicpu_test_utils.h"16#include "utils/aicpu_test_utils.h"
17#include "cpu_kernel_utils.h"17#include "cpu_kernel_utils.h"
18#include "node_def_builder.h"18#include "node_def_builder.h"
19#undef private19#undef private
20#undef protected20#undef protected
21#include "Eigen/Core"21#include "Eigen/Core"
22 22 
23using namespace std;23using namespace std;
24using namespace aicpu;24using namespace aicpu;
25 25 
26class TEST_SQUAREDDIFFERENCE_UT : public testing::Test {};26class TEST_SQUAREDDIFFERENCE_UT : public testing::Test {};
27 27 
28#define CREATE_NODEDEF(shapes, data_types, datas) \28#define CREATE_NODEDEF(shapes, data_types, datas) \
29 auto node_def = CpuKernelUtils::CpuKernelUtils::CreateNodeDef(); \29 auto node_def = CpuKernelUtils::CpuKernelUtils::CreateNodeDef(); \
30 NodeDefBuilder(node_def.get(), "SquaredDifference", "SquaredDifference") \30 NodeDefBuilder(node_def.get(), "SquaredDifference", "SquaredDifference") \
31 .Input({"x1", data_types[0], shapes[0], datas[0]}) \31 .Input({"x1", data_types[0], shapes[0], datas[0]}) \
32 .Input({"x2", data_types[1], shapes[1], datas[1]}) \32 .Input({"x2", data_types[1], shapes[1], datas[1]}) \
33 .Output({"y", data_types[2], shapes[2], datas[2]})33 .Output({"y", data_types[2], shapes[2], datas[2]})
34 34 
35TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_X_NUM_ONE_SUCC)35TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_X_NUM_ONE_SUCC)
36{36{
37 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};37 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
38 vector<vector<int64_t>> shapes = {{1}, {1, 3}, {1, 3}};38 vector<vector<int64_t>> shapes = {{1}, {1, 3}, {1, 3}};
39 39 
40 constexpr uint64_t input1_size = 1;40 constexpr uint64_t input1_size = 1;
41 int32_t input1[input1_size] = {2};41 int32_t input1[input1_size] = {2};
42 42 
43 constexpr uint64_t input2_size = 3;43 constexpr uint64_t input2_size = 3;
44 int32_t input2[input2_size] = {7, 0, 4};44 int32_t input2[input2_size] = {7, 0, 4};
45 45 
46 constexpr uint64_t output_size = 3;46 constexpr uint64_t output_size = 3;
47 int32_t output[output_size] = {0};47 int32_t output[output_size] = {0};
48 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};48 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
49 49 
50 CREATE_NODEDEF(shapes, data_types, datas);50 CREATE_NODEDEF(shapes, data_types, datas);
51 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);51 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
52 52 
53 int32_t output_exp[output_size] = {25, 4, 4};53 int32_t output_exp[output_size] = {25, 4, 4};
54 54 
55 bool compare = CompareResult(output, output_exp, output_size);55 bool compare = CompareResult(output, output_exp, output_size);
56 EXPECT_EQ(compare, true);56 EXPECT_EQ(compare, true);
57}57}
58 58 
59TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_Y_NUM_ONESUCC)59TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_Y_NUM_ONESUCC)
60{60{
61 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};61 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
62 vector<vector<int64_t>> shapes = {{1, 3}, {1}, {1, 3}};62 vector<vector<int64_t>> shapes = {{1, 3}, {1}, {1, 3}};
63 63 
64 constexpr uint64_t input1_size = 3;64 constexpr uint64_t input1_size = 3;
65 int32_t input1[input1_size] = {2, 7, 0};65 int32_t input1[input1_size] = {2, 7, 0};
66 66 
67 constexpr uint64_t input2_size = 1;67 constexpr uint64_t input2_size = 1;
68 int32_t input2[input2_size] = {4};68 int32_t input2[input2_size] = {4};
69 69 
70 constexpr uint64_t output_size = 3;70 constexpr uint64_t output_size = 3;
71 int32_t output[output_size] = {0};71 int32_t output[output_size] = {0};
72 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};72 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
73 73 
74 CREATE_NODEDEF(shapes, data_types, datas);74 CREATE_NODEDEF(shapes, data_types, datas);
75 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);75 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
76 76 
77 int32_t output_exp[output_size] = {4, 9, 16};77 int32_t output_exp[output_size] = {4, 9, 16};
78 bool compare = CompareResult(output, output_exp, output_size);78 bool compare = CompareResult(output, output_exp, output_size);
79 EXPECT_EQ(compare, true);79 EXPECT_EQ(compare, true);
80}80}
81 81 
82TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_SUCC)82TEST_F(TEST_SQUAREDDIFFERENCE_UT, BROADCAST_INPUT_SUCC)
83{83{
84 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};84 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
85 vector<vector<int64_t>> shapes = {{4, 16}, {1, 16}, {4, 16}};85 vector<vector<int64_t>> shapes = {{4, 16}, {1, 16}, {4, 16}};
86 86 
87 constexpr uint64_t input1_size = 4 * 16;87 constexpr uint64_t input1_size = 4 * 16;
88 int32_t input1[input1_size] = {2, 7, 0, 4, 2, 1, 3, 3, 3, 9, 1, 2, 0, 7, 0, 5, 3, 9, 4, 7, 8, 5,88 int32_t input1[input1_size] = {2, 7, 0, 4, 2, 1, 3, 3, 3, 9, 1, 2, 0, 7, 0, 5, 3, 9, 4, 7, 8, 5,
89 6, 6, 7, 7, 6, 4, 0, 1, 5, 7, 5, 3, 7, 0, 8, 9, 8, 9, 6, 3, 7, 6,89 6, 6, 7, 7, 6, 4, 0, 1, 5, 7, 5, 3, 7, 0, 8, 9, 8, 9, 6, 3, 7, 6,
90 9, 5, 9, 4, 4, 2, 7, 2, 1, 9, 6, 8, 8, 9, 6, 2, 7, 9, 1, 2};90 9, 5, 9, 4, 4, 2, 7, 2, 1, 9, 6, 8, 8, 9, 6, 2, 7, 9, 1, 2};
91 91 
92 constexpr uint64_t input2_size = 16;92 constexpr uint64_t input2_size = 16;
93 int32_t input2[input2_size] = {6, 3, 1, 2, 5, 6, 4, 8, 6, 6, 1, 8, 5, 7, 2, 3};93 int32_t input2[input2_size] = {6, 3, 1, 2, 5, 6, 4, 8, 6, 6, 1, 8, 5, 7, 2, 3};
94 94 
95 constexpr uint64_t output_size = 4 * 16;95 constexpr uint64_t output_size = 4 * 16;
96 int32_t output[output_size] = {0};96 int32_t output[output_size] = {0};
97 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};97 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
98 98 
99 CREATE_NODEDEF(shapes, data_types, datas);99 CREATE_NODEDEF(shapes, data_types, datas);
100 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);100 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
101 101 
102 int32_t output_exp[output_size] = {16, 16, 1, 4, 9, 25, 1, 25, 9, 9, 0, 36, 25, 0, 4, 4,102 int32_t output_exp[output_size] = {16, 16, 1, 4, 9, 25, 1, 25, 9, 9, 0, 36, 25, 0, 4, 4,
103 9, 36, 9, 25, 9, 1, 4, 4, 1, 1, 25, 16, 25, 36, 9, 16,103 9, 36, 9, 25, 9, 1, 4, 4, 1, 1, 25, 16, 25, 36, 9, 16,
104 1, 0, 36, 4, 9, 9, 16, 1, 0, 9, 36, 4, 16, 4, 49, 1,104 1, 0, 36, 4, 9, 9, 16, 1, 0, 9, 36, 4, 16, 4, 49, 1,
105 4, 1, 36, 0, 16, 9, 4, 0, 4, 9, 25, 36, 4, 4, 1, 1};105 4, 1, 36, 0, 16, 9, 4, 0, 4, 9, 25, 36, 4, 4, 1, 1};
106 106 
107 bool compare = CompareResult(output, output_exp, output_size);107 bool compare = CompareResult(output, output_exp, output_size);
108 EXPECT_EQ(compare, true);108 EXPECT_EQ(compare, true);
109}109}
110 
111TEST_F(TEST_SQUAREDDIFFERENCE_UT, FLOAT16_SUCC)
112{
113 vector<DataType> data_types = {DT_FLOAT16, DT_FLOAT16, DT_FLOAT16};
114 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
115 
116 constexpr uint64_t input1_size = 6;
117 Eigen::half input1[input1_size] = {Eigen::half(1.0f), Eigen::half(2.0f), Eigen::half(3.0f),
118 Eigen::half(4.0f), Eigen::half(5.0f), Eigen::half(6.0f)};
119 
120 constexpr uint64_t input2_size = 6;
121 Eigen::half input2[input2_size] = {Eigen::half(0.5f), Eigen::half(1.5f), Eigen::half(2.5f),
122 Eigen::half(3.5f), Eigen::half(4.5f), Eigen::half(5.5f)};
123 
124 constexpr uint64_t output_size = 6;
125 Eigen::half output[output_size] = {Eigen::half(0.0f)};
126 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
127 
128 CREATE_NODEDEF(shapes, data_types, datas);
129 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
130 
131 Eigen::half output_exp[output_size] = {Eigen::half(0.25f), Eigen::half(0.25f), Eigen::half(0.25f),
132 Eigen::half(0.25f), Eigen::half(0.25f), Eigen::half(0.25f)};
133 
134 bool compare = CompareResult(output, output_exp, output_size);
135 EXPECT_EQ(compare, true);
136}
137 
138TEST_F(TEST_SQUAREDDIFFERENCE_UT, FLOAT_SUCC)
139{
140 vector<DataType> data_types = {DT_FLOAT, DT_FLOAT, DT_FLOAT};
141 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
142 
143 constexpr uint64_t input1_size = 6;
144 float input1[input1_size] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
145 
146 constexpr uint64_t input2_size = 6;
147 float input2[input2_size] = {0.5f, 1.5f, 2.5f, 3.5f, 4.5f, 5.5f};
148 
149 constexpr uint64_t output_size = 6;
150 float output[output_size] = {0.0f};
151 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
152 
153 CREATE_NODEDEF(shapes, data_types, datas);
154 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
155 
156 float output_exp[output_size] = {0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f};
157 
158 bool compare = CompareResult(output, output_exp, output_size);
159 EXPECT_EQ(compare, true);
160}
161 
162TEST_F(TEST_SQUAREDDIFFERENCE_UT, DOUBLE_SUCC)
163{
164 vector<DataType> data_types = {DT_DOUBLE, DT_DOUBLE, DT_DOUBLE};
165 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
166 
167 constexpr uint64_t input1_size = 6;
168 double input1[input1_size] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
169 
170 constexpr uint64_t input2_size = 6;
171 double input2[input2_size] = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5};
172 
173 constexpr uint64_t output_size = 6;
174 double output[output_size] = {0.0};
175 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
176 
177 CREATE_NODEDEF(shapes, data_types, datas);
178 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
179 
180 double output_exp[output_size] = {0.25, 0.25, 0.25, 0.25, 0.25, 0.25};
181 
182 bool compare = CompareResult(output, output_exp, output_size);
183 EXPECT_EQ(compare, true);
184}
185 
186TEST_F(TEST_SQUAREDDIFFERENCE_UT, INT64_SUCC)
187{
188 vector<DataType> data_types = {DT_INT64, DT_INT64, DT_INT64};
189 vector<vector<int64_t>> shapes = {{2, 3}, {2, 3}, {2, 3}};
190 
191 constexpr uint64_t input1_size = 6;
192 int64_t input1[input1_size] = {10, 20, 30, 40, 50, 60};
193 
194 constexpr uint64_t input2_size = 6;
195 int64_t input2[input2_size] = {5, 15, 25, 35, 45, 55};
196 
197 constexpr uint64_t output_size = 6;
198 int64_t output[output_size] = {0};
199 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
200 
201 CREATE_NODEDEF(shapes, data_types, datas);
202 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
203 
204 int64_t output_exp[output_size] = {25, 25, 25, 25, 25, 25};
205 
206 bool compare = CompareResult(output, output_exp, output_size);
207 EXPECT_EQ(compare, true);
208}
209 
210TEST_F(TEST_SQUAREDDIFFERENCE_UT, COMPLEX64_SUCC)
211{
212 vector<DataType> data_types = {DT_COMPLEX64, DT_COMPLEX64, DT_COMPLEX64};
213 vector<vector<int64_t>> shapes = {{2, 2}, {2, 2}, {2, 2}};
214 
215 constexpr uint64_t input1_size = 4;
216 std::complex<float> input1[input1_size] = {
217 std::complex<float>(1.0f, 2.0f), std::complex<float>(3.0f, 4.0f),
218 std::complex<float>(5.0f, 6.0f), std::complex<float>(7.0f, 8.0f)
219 };
220 
221 constexpr uint64_t input2_size = 4;
222 std::complex<float> input2[input2_size] = {
223 std::complex<float>(0.5f, 1.0f), std::complex<float>(1.5f, 2.0f),
224 std::complex<float>(2.5f, 3.0f), std::complex<float>(3.5f, 4.0f)
225 };
226 
227 constexpr uint64_t output_size = 4;
228 std::complex<float> output[output_size] = {std::complex<float>(0.0f, 0.0f)};
229 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
230 
231 CREATE_NODEDEF(shapes, data_types, datas);
232 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
233 
234 std::complex<float> output_exp[output_size] = {
235 std::complex<float>(1.25f, 0.0f), std::complex<float>(6.25f, 0.0f),
236 std::complex<float>(15.25f, 0.0f), std::complex<float>(28.25f, 0.0f)
237 };
238 
239 bool compare = CompareResult(output, output_exp, output_size);
240 EXPECT_EQ(compare, true);
241}
242 
243TEST_F(TEST_SQUAREDDIFFERENCE_UT, COMPLEX128_SUCC)
244{
245 vector<DataType> data_types = {DT_COMPLEX128, DT_COMPLEX128, DT_COMPLEX128};
246 vector<vector<int64_t>> shapes = {{2, 2}, {2, 2}, {2, 2}};
247 
248 constexpr uint64_t input1_size = 4;
249 std::complex<double> input1[input1_size] = {
250 std::complex<double>(1.0, 2.0), std::complex<double>(3.0, 4.0),
251 std::complex<double>(5.0, 6.0), std::complex<double>(7.0, 8.0)
252 };
253 
254 constexpr uint64_t input2_size = 4;
255 std::complex<double> input2[input2_size] = {
256 std::complex<double>(0.5, 1.0), std::complex<double>(1.5, 2.0),
257 std::complex<double>(2.5, 3.0), std::complex<double>(3.5, 4.0)
258 };
259 
260 constexpr uint64_t output_size = 4;
261 std::complex<double> output[output_size] = {std::complex<double>(0.0, 0.0)};
262 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
263 
264 CREATE_NODEDEF(shapes, data_types, datas);
265 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
266 
267 std::complex<double> output_exp[output_size] = {
268 std::complex<double>(1.25, 0.0), std::complex<double>(6.25, 0.0),
269 std::complex<double>(15.25, 0.0), std::complex<double>(28.25, 0.0)
270 };
271 
272 bool compare = CompareResult(output, output_exp, output_size);
273 EXPECT_EQ(compare, true);
274}
275 
276TEST_F(TEST_SQUAREDDIFFERENCE_UT, LARGE_DATA_PARALLEL_SUCC)
277{
278 vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32};
279 vector<vector<int64_t>> shapes = {{64, 32}, {64, 32}, {64, 32}};
280 
281 constexpr uint64_t input1_size = 64 * 32;
282 int32_t input1[input1_size];
283 for (int64_t i = 0; i < input1_size; ++i) {
284 input1[i] = static_cast<int32_t>(i % 10);
285 }
286 
287 constexpr uint64_t input2_size = 64 * 32;
288 int32_t input2[input2_size];
289 for (int64_t i = 0; i < input2_size; ++i) {
290 input2[i] = static_cast<int32_t>((i + 5) % 10);
291 }
292 
293 constexpr uint64_t output_size = 64 * 32;
294 int32_t output[output_size] = {0};
295 vector<void*> datas = {(void*)input1, (void*)input2, (void*)output};
296 
297 CREATE_NODEDEF(shapes, data_types, datas);
298 RUN_KERNEL(node_def, HOST, KERNEL_STATUS_OK);
299 
300 for (int64_t i = 0; i < output_size; ++i) {
301 int32_t expected = (input1[i] - input2[i]) * (input1[i] - input2[i]);
302 EXPECT_EQ(output[i], expected);
303 }
304}
Mmath/triangular_solve/CMakeLists.txt+21-20
@@ -1,20 +1,21 @@
1# ----------------------------------------------------------------------------1 # ----------------------------------------------------------------------------
2# This program is free software, you can redistribute it and/or modify it.2 # This program is free software, you can redistribute it and/or modify it.
3# Copyright (c) 2025 Huawei Technologies Co., Ltd.3 # Copyright (c) 2025 Huawei Technologies Co., Ltd.
4# This file is a part of the CANN Open Software.4 # This file is a part of the CANN Open Software.
5# Licensed under 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.6 # 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, INCLUDING7 # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
8# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.8 # 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.9 # See LICENSE in the root of the software repository for the full text of the License.
10# ----------------------------------------------------------------------------10 # ----------------------------------------------------------------------------
11 11
12file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)12
13if(NOT ENABLE_TEST AND NOT BENCHMARK)13 file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
14 list(REMOVE_ITEM CURRENT_DIRS tests)14 if(NOT ENABLE_TEST AND NOT BENCHMARK)
15endif()15 list(REMOVE_ITEM CURRENT_DIRS tests)
16foreach(SUB_DIR ${CURRENT_DIRS})16 endif()
17 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")17 foreach(SUB_DIR ${CURRENT_DIRS})
18 add_subdirectory(${SUB_DIR})18 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
19 endif()19 add_subdirectory(${SUB_DIR})
20endforeach()20 endif()
21 endforeach()
Mmath/triangular_solve/op_host/CMakeLists.txt+13-12
@@ -1,12 +1,13 @@
1# ----------------------------------------------------------------------------1 # ----------------------------------------------------------------------------
2# This program is free software, you can redistribute it and/or modify it.2 # This program is free software, you can redistribute it and/or modify it.
3# Copyright (c) 2025 Huawei Technologies Co., Ltd.3 # Copyright (c) 2025 Huawei Technologies Co., Ltd.
4# This file is a part of the CANN Open Software.4 # This file is a part of the CANN Open Software.
5# Licensed under 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.6 # 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, INCLUDING7 # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
8# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.8 # 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.9 # See LICENSE in the root of the software repository for the full text of the License.
10# ----------------------------------------------------------------------------10 # ----------------------------------------------------------------------------
11 11
12add_modules_sources()12
13 add_modules_sources()
Amath/triangular_solve/tests/CMakeLists.txt+16-0
@@ -0,0 +1,16 @@
1# -----------------------------------------------------------------------------------------------------------
2# 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# 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 
11file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
12foreach(SUB_DIR ${CURRENT_DIRS})
13 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
14 add_subdirectory(${SUB_DIR})
15 endif()
16endforeach()
Amath/triangular_solve/tests/ut/CMakeLists.txt+16-0
@@ -0,0 +1,16 @@
1# -----------------------------------------------------------------------------------------------------------
2# 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# 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 "ASAS 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 
11file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
12foreach(SUB_DIR ${CURRENT_DIRS})
13 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
14 add_subdirectory(${SUB_DIR})
15 endif()
16endforeach()
Amath/triangular_solve/tests/ut/op_api/CMakeLists.txt+14-0
@@ -0,0 +1,14 @@
1# -----------------------------------------------------------------------------------------------------------
2# 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# 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 
11message(STATUS "=== Debug: target_sources add test_aclnn_triangular_solve")
12if(UT_TEST_ALL OR OP_API_UT)
13 add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
14endif()
Amath/triangular_solve/tests/ut/op_api/test_aclnn_l0_triangular_solve.cpp+179-0
@@ -0,0 +1,179 @@
1/**
2 * 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 * 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 <iostream>
13#include <vector>
14 
15#include "opdev/make_op_executor.h"
16#include "../../../op_host/op_api/triangular_solve.h"
17 
18const int64_t DATA_SIZE = 1024 * 1024;
19 
20class TriangularSolveTest: public ::testing::Test {
21 public:
22 TriangularSolveTest() : l0Executor(nullptr) {}
23 
24 aclTensor *CreateContiguousAclTensor(std::vector<int64_t> viewShape, aclDataType dtype) {
25 std::vector<int64_t> stride(viewShape.size(), 1);
26 for (int i = viewShape.size() - 2; i >= 0; i--) {
27 stride[i] = stride[i + 1] * viewShape[i];
28 }
29 return aclCreateTensor(viewShape.data(), viewShape.size(), dtype, stride.data(), 0,
30 ACL_FORMAT_ND, viewShape.data(), viewShape.size(), data);
31 }
32 
33 void Clear() {
34 }
35 
36 void SetUp() override {
37 auto l2Executor = &l0Executor;
38 auto uniqueExecutor = CREATE_EXECUTOR();
39 uniqueExecutor.ReleaseTo(l2Executor);
40 }
41 
42 void TearDown() override {
43 delete l0Executor;
44 }
45 
46 public:
47 aclOpExecutor* l0Executor;
48 int64_t data[DATA_SIZE] = {0};
49};
50 
51TEST_F(TriangularSolveTest, TriangularSolve_float_upper_false) {
52 auto self = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
53 auto A = CreateContiguousAclTensor({3, 3}, ACL_FLOAT);
54 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
55 bool upper = false;
56 bool transpose = false;
57 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
58 ASSERT_NE(result, nullptr);
59 
60 op::ShapeVector expectShape({3, 4});
61 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
62}
63 
64TEST_F(TriangularSolveTest, TriangularSolve_float_upper_true) {
65 auto self = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
66 auto A = CreateContiguousAclTensor({3, 3}, ACL_FLOAT);
67 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
68 bool upper = true;
69 bool transpose = false;
70 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
71 ASSERT_NE(result, nullptr);
72 
73 op::ShapeVector expectShape({3, 4});
74 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
75}
76 
77TEST_F(TriangularSolveTest, TriangularSolve_transpose_true) {
78 auto self = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
79 auto A = CreateContiguousAclTensor({3, 3}, ACL_FLOAT);
80 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_FLOAT);
81 bool upper = true;
82 bool transpose = true;
83 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
84 ASSERT_NE(result, nullptr);
85 
86 op::ShapeVector expectShape({3, 4});
87 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
88}
89 
90TEST_F(TriangularSolveTest, TriangularSolve_double) {
91 auto self = CreateContiguousAclTensor({3, 4}, ACL_DOUBLE);
92 auto A = CreateContiguousAclTensor({3, 3}, ACL_DOUBLE);
93 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_DOUBLE);
94 bool upper = true;
95 bool transpose = false;
96 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
97 ASSERT_NE(result, nullptr);
98 
99 op::ShapeVector expectShape({3, 4});
100 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
101}
102 
103TEST_F(TriangularSolveTest, TriangularSolve_complex64) {
104 auto self = CreateContiguousAclTensor({3, 4}, ACL_COMPLEX64);
105 auto A = CreateContiguousAclTensor({3, 3}, ACL_COMPLEX64);
106 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_COMPLEX64);
107 bool upper = true;
108 bool transpose = false;
109 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
110 ASSERT_NE(result, nullptr);
111 
112 op::ShapeVector expectShape({3, 4});
113 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
114}
115 
116TEST_F(TriangularSolveTest, TriangularSolve_complex128) {
117 auto self = CreateContiguousAclTensor({3, 4}, ACL_COMPLEX128);
118 auto A = CreateContiguousAclTensor({3, 3}, ACL_COMPLEX128);
119 auto xOut = CreateContiguousAclTensor({3, 4}, ACL_COMPLEX128);
120 bool upper = true;
121 bool transpose = false;
122 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
123 ASSERT_NE(result, nullptr);
124 
125 op::ShapeVector expectShape({3, 4});
126 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
127}
128 
129TEST_F(TriangularSolveTest, TriangularSolve_batch) {
130 auto self = CreateContiguousAclTensor({2, 3, 4}, ACL_FLOAT);
131 auto A = CreateContiguousAclTensor({2, 3, 3}, ACL_FLOAT);
132 auto xOut = CreateContiguousAclTensor({2, 3, 4}, ACL_FLOAT);
133 bool upper = true;
134 bool transpose = false;
135 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
136 ASSERT_NE(result, nullptr);
137 
138 op::ShapeVector expectShape({2, 3, 4});
139 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
140}
141 
142TEST_F(TriangularSolveTest, TriangularSolve_4d_batch) {
143 auto self = CreateContiguousAclTensor({1, 1, 3, 4}, ACL_FLOAT);
144 auto A = CreateContiguousAclTensor({1, 1, 3, 3}, ACL_FLOAT);
145 auto xOut = CreateContiguousAclTensor({1, 1, 3, 4}, ACL_FLOAT);
146 bool upper = true;
147 bool transpose = false;
148 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
149 ASSERT_NE(result, nullptr);
150 
151 op::ShapeVector expectShape({1, 1, 3, 4});
152 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
153}
154 
155TEST_F(TriangularSolveTest, TriangularSolve_single_col) {
156 auto self = CreateContiguousAclTensor({3, 1}, ACL_FLOAT);
157 auto A = CreateContiguousAclTensor({3, 3}, ACL_FLOAT);
158 auto xOut = CreateContiguousAclTensor({3, 1}, ACL_FLOAT);
159 bool upper = true;
160 bool transpose = false;
161 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
162 ASSERT_NE(result, nullptr);
163 
164 op::ShapeVector expectShape({3, 1});
165 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
166}
167 
168TEST_F(TriangularSolveTest, TriangularSolve_empty_batch) {
169 auto self = CreateContiguousAclTensor({0, 3, 4}, ACL_FLOAT);
170 auto A = CreateContiguousAclTensor({0, 3, 3}, ACL_FLOAT);
171 auto xOut = CreateContiguousAclTensor({0, 3, 4}, ACL_FLOAT);
172 bool upper = true;
173 bool transpose = false;
174 auto result = l0op::TriangularSolve(self, A, upper, transpose, xOut, l0Executor);
175 ASSERT_NE(result, nullptr);
176 
177 op::ShapeVector expectShape({0, 3, 4});
178 EXPECT_EQ(op::ToShapeVector(result->GetViewShape()), expectShape);
179}
Amath/triangular_solve/tests/ut/op_api/test_aclnn_l2_triangular_solve.cpp+365-0
@@ -0,0 +1,365 @@
1/**
2 * 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 * 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#include <array>
11#include <vector>
12#include "gtest/gtest.h"
13#include "../../../op_host/op_api/aclnn_triangular_solve.h"
14#include "op_api_ut_common/tensor_desc.h"
15#include "op_api_ut_common/scalar_desc.h"
16#include "op_api_ut_common/op_api_ut.h"
17using namespace std;
18 
19class l2_triangular_solve_test : public testing::Test {
20protected:
21 static void SetUpTestCase() { cout << "Triangular Solve Test Setup" << endl; }
22 static void TearDownTestCase() { cout << "Triangular Solve Test TearDown" << endl; }
23};
24 
25TEST_F(l2_triangular_solve_test, case_normal)
26{
27 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
28 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
29 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
30 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
31 bool upper = true;
32 bool transpose = false;
33 bool unitriangular = false;
34 
35 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
36 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
37 
38 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
39 OUTPUT(X_desc, M_desc));
40 uint64_t workspaceSize = 0;
41 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
42 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
43}
44 
45TEST_F(l2_triangular_solve_test, case_nullptr)
46 
47 
48{
49 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
50 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
51 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
52 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
53 bool upper = true;
54 bool transpose = false;
55 bool unitriangular = false;
56 
57 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
58 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
59 
60 auto ut1 = OP_API_UT(aclnnTriangularSolve, INPUT(nullptr, A_desc, upper, transpose, unitriangular),
61 OUTPUT(X_desc, M_desc));
62 uint64_t workspaceSize1 = 0;
63 aclnnStatus aclRet1 = ut1.TestGetWorkspaceSize(&workspaceSize1);
64 EXPECT_EQ(aclRet1, ACLNN_ERR_INNER_NULLPTR);
65 
66 auto ut2 = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, nullptr, upper, transpose, unitriangular),
67 OUTPUT(X_desc, M_desc));
68 uint64_t workspaceSize2 = 0;
69 aclnnStatus aclRet2 = ut2.TestGetWorkspaceSize(&workspaceSize2);
70 EXPECT_EQ(aclRet2, ACLNN_ERR_INNER_NULLPTR);
71 
72 auto ut3 = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
73 OUTPUT(nullptr, M_desc));
74 uint64_t workspaceSize3 = 0;
75 aclnnStatus aclRet3 = ut3.TestGetWorkspaceSize(&workspaceSize3);
76 EXPECT_EQ(aclRet3, ACLNN_ERR_INNER_NULLPTR);
77 
78 auto ut4 = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
79 OUTPUT(X_desc, nullptr));
80 uint64_t workspaceSize4 = 0;
81 aclnnStatus aclRet4 = ut4.TestGetWorkspaceSize(&workspaceSize4);
82 EXPECT_EQ(aclRet4, ACLNN_ERR_INNER_NULLPTR);
83}
84 
85TEST_F(l2_triangular_solve_test, case_dtype_valid)
86{
87 vector<aclDataType> ValidList = {
88 ACL_FLOAT,
89 ACL_DOUBLE,
90 ACL_COMPLEX64,
91 ACL_COMPLEX128,
92 ACL_FLOAT16};
93
94 int length = ValidList.size();
95 for (int i = 0; i < length; i++) {
96 auto A_desc = TensorDesc({1, 1, 3, 3}, ValidList[i], ACL_FORMAT_ND)
97 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
98 auto b_desc = TensorDesc({1, 1, 3, 4}, ValidList[i], ACL_FORMAT_ND)
99 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
100
101 bool upper = true;
102 bool transpose = false;
103 bool unitriangular = false;
104 
105 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
106 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
107 
108 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
109 OUTPUT(X_desc, M_desc));
110 // SAMPLE: only test GetWorkspaceSize
111 uint64_t workspaceSize = 0;
112 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
113 if (ValidList[i] != ACL_FLOAT16) {
114 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
115 } else {
116 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
117 }
118 }
119}
120 
121 
122TEST_F(l2_triangular_solve_test, case_dtype_diff)
123{
124 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
125 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
126 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_DOUBLE, ACL_FORMAT_ND)
127 .Value(vector<double>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
128 bool upper = true;
129 bool transpose = false;
130 bool unitriangular = false;
131 
132 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
133 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
134 
135 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
136 OUTPUT(X_desc, M_desc));
137 uint64_t workspaceSize = 0;
138 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
139 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
140}
141 
142TEST_F(l2_triangular_solve_test, case_dim_less_2)
143{
144 auto A_desc = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND)
145 .Value(vector<float>{1, 2, 3});
146 auto b_desc = TensorDesc({3}, ACL_FLOAT, ACL_FORMAT_ND)
147 .Value(vector<float>{1, 2, 3});
148 bool upper = true;
149 bool transpose = false;
150 bool unitriangular = false;
151 
152 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
153 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
154 
155 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
156 OUTPUT(X_desc, M_desc));
157 uint64_t workspaceSize = 0;
158 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
159 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
160}
161 
162TEST_F(l2_triangular_solve_test, case_dim_more_8)
163{
164 auto A_desc = TensorDesc({1, 1, 1, 1, 1, 1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
165 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
166 auto b_desc = TensorDesc({1, 1, 1, 1, 1, 1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
167 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
168 bool upper = true;
169 bool transpose = false;
170 bool unitriangular = false;
171 
172 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
173 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
174 
175 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
176 OUTPUT(X_desc, M_desc));
177 uint64_t workspaceSize = 0;
178 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
179 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
180}
181 
182TEST_F(l2_triangular_solve_test, case_a_square)
183{
184 auto A_desc = TensorDesc({1, 1, 3, 2}, ACL_FLOAT, ACL_FORMAT_ND)
185 .Value(vector<float>{1, 2, 3, 4, 5, 6});
186 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
187 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
188 bool upper = true;
189 bool transpose = false;
190 bool unitriangular = false;
191 
192 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
193 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
194 
195 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
196 OUTPUT(X_desc, M_desc));
197 uint64_t workspaceSize = 0;
198 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
199 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
200}
201 
202TEST_F(l2_triangular_solve_test, case_matrix_shape)
203{
204 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
205 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
206 auto b_desc = TensorDesc({1, 1, 2, 4}, ACL_FLOAT, ACL_FORMAT_ND)
207 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2});
208 bool upper = true;
209 bool transpose = false;
210 bool unitriangular = false;
211 
212 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
213 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
214 
215 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
216 OUTPUT(X_desc, M_desc));
217 uint64_t workspaceSize = 0;
218 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
219 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
220}
221 
222TEST_F(l2_triangular_solve_test, case_shape_boardcast_fail)
223{
224 auto A_desc = TensorDesc({1, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND)
225 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8});
226 auto b_desc = TensorDesc({1, 3, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND)
227 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
228 bool upper = true;
229 bool transpose = false;
230 bool unitriangular = false;
231 
232 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
233 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
234 
235 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
236 OUTPUT(X_desc, M_desc));
237 uint64_t workspaceSize = 0;
238 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
239 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
240}
241 
242TEST_F(l2_triangular_solve_test, case_shape_boardcast_succ)
243{
244 auto A_desc = TensorDesc({3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
245 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
246 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
247 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
248 bool upper = true;
249 bool transpose = false;
250 bool unitriangular = false;
251 
252 auto X_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001);
253 auto M_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001);
254 
255 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
256 OUTPUT(X_desc, M_desc));
257 uint64_t workspaceSize = 0;
258 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
259 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
260}
261 
262TEST_F(l2_triangular_solve_test, case_shape_boardcast_out_fail)
263{
264 auto A_desc = TensorDesc({3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
265 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
266 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
267 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
268 bool upper = true;
269 bool transpose = false;
270 bool unitriangular = false;
271 
272 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
273 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
274 
275 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
276 OUTPUT(X_desc, M_desc));
277 uint64_t workspaceSize = 0;
278 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
279 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
280}
281 
282TEST_F(l2_triangular_solve_test, case_empty)
283{
284 auto A_desc = TensorDesc({1, 0, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND);
285 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
286 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
287 bool upper = true;
288 bool transpose = false;
289 bool unitriangular = false;
290 
291 auto X_desc = TensorDesc({1, 0, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001);
292 auto M_desc = TensorDesc({1, 0, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001);
293 
294 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
295 OUTPUT(X_desc, M_desc));
296 uint64_t workspaceSize = 0;
297 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
298 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
299}
300 
301TEST_F(l2_triangular_solve_test, case_transpose_true)
302{
303 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
304 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
305 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
306 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
307 bool upper = true;
308 bool transpose = true;
309 bool unitriangular = false;
310 
311 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
312 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
313 
314 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
315 OUTPUT(X_desc, M_desc));
316 uint64_t workspaceSize = 0;
317 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
318 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
319}
320 
321TEST_F(l2_triangular_solve_test, case_unitriangular_true)
322{
323 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_FLOAT, ACL_FORMAT_ND)
324 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
325 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_FLOAT, ACL_FORMAT_ND)
326 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
327 bool upper = true;
328 bool transpose = false;
329 bool unitriangular = true;
330 
331 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
332 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
333 
334 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
335 OUTPUT(X_desc, M_desc));
336 uint64_t workspaceSize = 0;
337 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
338 EXPECT_EQ(aclRet, ACLNN_SUCCESS);
339}
340 
341TEST_F(l2_triangular_solve_test, case_unitriangular_faile)
342{
343 auto A_desc = TensorDesc({1, 1, 3, 3}, ACL_DOUBLE, ACL_FORMAT_ND)
344 .Value(vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
345 auto b_desc = TensorDesc({1, 1, 3, 4}, ACL_DOUBLE, ACL_FORMAT_ND)
346 .Value(vector<float>{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
347 bool upper = true;
348 bool transpose = false;
349 bool unitriangular = true;
350 
351 auto X_desc = TensorDesc(b_desc).Precision(0.0001, 0.0001);
352 auto M_desc = TensorDesc(A_desc).Precision(0.0001, 0.0001);
353 
354 auto ut = OP_API_UT(aclnnTriangularSolve, INPUT(b_desc, A_desc, upper, transpose, unitriangular),
355 OUTPUT(X_desc, M_desc));
356 uint64_t workspaceSize = 0;
357 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize);
358 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
359}
360 
361 
362 
363 
364 
365