1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <iostream>
17 #include <unordered_map>
18 #include <string>
19
20 #include "common/common_test.h"
21
22 #include "transform/graph_ir/op_adapter.h"
23 #include "transform/graph_ir/op_declare/array_ops_declare.h"
24 #include "frontend/operator/ops.h"
25
26 using std::cout;
27 using std::endl;
28 using std::string;
29 using std::unordered_map;
30
31 namespace mindspore {
32 namespace transform {
33 class TestOpAdapter : public UT::Common {
34 public:
TestOpAdapter()35 TestOpAdapter() {}
36 };
37
38 #if (!defined ENABLE_GE)
39 #if 0
40 // fix conv2d ut
41 TEST_F(TestOpAdapter, TestSpecilization_Conv2D) {
42 BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
43
44 auto input = std::make_shared<ge::Operator>();
45 auto conv = std::make_shared<Conv2D>();
46
47 ASSERT_EQ(adpt->setInput(conv, 1, input), 0);
48 ASSERT_EQ(adpt->setInput(conv, 2, input), 0);
49 ASSERT_EQ(adpt->setInput(conv, 3, input), NOT_FOUND);
50
51 ASSERT_EQ(0, adpt->setAttr(conv, "group", 1));
52 ASSERT_EQ(0, adpt->setAttr(conv, "mode", 1));
53
54 delete adpt;
55 }
56 #endif
TEST_F(TestOpAdapter,TestSpecilization_Const)57 TEST_F(TestOpAdapter, TestSpecilization_Const) {
58 BaseOpAdapter *adpt = new OpAdapter<Const>();
59 auto valuenode = std::make_shared<Const>();
60 auto input = std::make_shared<Const>();
61
62 ASSERT_EQ(adpt->setInput(valuenode, 1, input), NOT_FOUND);
63 delete adpt;
64 }
65 #if 0
66 // fix conv2d ut
67 TEST_F(TestOpAdapter, TestSetAttr_Conv2d_Primitive) {
68 BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
69 auto conv = std::make_shared<Conv2D>();
70
71 ASSERT_EQ(adpt->setAttr(conv, "padding", 1), NOT_FOUND);
72 ASSERT_EQ(adpt->setAttr(conv, "pad", 1), 0);
73 ASSERT_EQ(adpt->setAttr(conv, "pad_mode", string("same")), 0);
74 ASSERT_EQ(adpt->setAttr(conv, "nothing", "test"), NOT_FOUND);
75
76 const unordered_map<std::string, ValuePtr> attrs = {
77 {"padding", MakeValue(2)},
78 {"padding_mode", MakeValue(string("normal"))},
79 {"stride", MakeValue(8)}
80 };
81
82 auto prim = prim::kPrimConv2D;
83 prim->SetAttrs({
84 {"strides", MakeValue(3)},
85 {"padding", MakeValue(1)},
86 });
87 ASSERT_EQ(prim->name(), prim::kPrimConv2D->name());
88
89 Int64Imm strides(3);
90 Int64Imm padding(1);
91 ASSERT_EQ(*(prim->GetAttr("strides")), strides);
92 ASSERT_EQ(*(prim->GetAttr("padding")), padding);
93
94 ASSERT_EQ(adpt->setAttr(conv, prim), 0);
95
96 delete adpt;
97 }
98 #endif
99 #endif
100 } // namespace transform
101 } // namespace mindspore
102