You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

op_adapter_test.cc 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Copyright 2020-2021 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 <string>
  18. #include "common/common_test.h"
  19. #include "transform/graph_ir/op_adapter.h"
  20. #include "transform/graph_ir/op_declare/array_ops_declare.h"
  21. #include "frontend/operator/ops.h"
  22. using std::cout;
  23. using std::endl;
  24. using std::string;
  25. namespace mindspore {
  26. namespace transform {
  27. class TestOpAdapter : public UT::Common {
  28. public:
  29. TestOpAdapter() {}
  30. };
  31. #if 0
  32. // fix conv2d ut
  33. TEST_F(TestOpAdapter, TestSpecilization_Conv2D) {
  34. BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
  35. auto input = std::make_shared<ge::Operator>();
  36. auto conv = std::make_shared<Conv2D>();
  37. ASSERT_EQ(adpt->setInput(conv, 1, input), 0);
  38. ASSERT_EQ(adpt->setInput(conv, 2, input), 0);
  39. ASSERT_EQ(adpt->setInput(conv, 3, input), NOT_FOUND);
  40. ASSERT_EQ(0, adpt->setAttr(conv, "group", 1));
  41. ASSERT_EQ(0, adpt->setAttr(conv, "mode", 1));
  42. delete adpt;
  43. }
  44. #endif
  45. TEST_F(TestOpAdapter, TestSpecilization_Const) {
  46. BaseOpAdapter *adpt = new OpAdapter<Const>();
  47. auto valuenode = std::make_shared<Const>();
  48. auto input = std::make_shared<Const>();
  49. ASSERT_EQ(adpt->setInput(valuenode, 1, input), NOT_FOUND);
  50. delete adpt;
  51. }
  52. #if 0
  53. // fix conv2d ut
  54. TEST_F(TestOpAdapter, TestSetAttr_Conv2d_Primitive) {
  55. BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
  56. auto conv = std::make_shared<Conv2D>();
  57. ASSERT_EQ(adpt->setAttr(conv, "padding", 1), NOT_FOUND);
  58. ASSERT_EQ(adpt->setAttr(conv, "pad", 1), 0);
  59. ASSERT_EQ(adpt->setAttr(conv, "pad_mode", string("same")), 0);
  60. ASSERT_EQ(adpt->setAttr(conv, "nothing", "test"), NOT_FOUND);
  61. const mindspore::HashMap<std::string, ValuePtr> attrs = {
  62. {"padding", MakeValue(2)},
  63. {"padding_mode", MakeValue(string("normal"))},
  64. {"stride", MakeValue(8)}
  65. };
  66. auto prim = prim::kPrimConv2D;
  67. prim->SetAttrs({
  68. {"strides", MakeValue(3)},
  69. {"padding", MakeValue(1)},
  70. });
  71. ASSERT_EQ(prim->name(), prim::kPrimConv2D->name());
  72. Int64Imm strides(3);
  73. Int64Imm padding(1);
  74. ASSERT_EQ(*(prim->GetAttr("strides")), strides);
  75. ASSERT_EQ(*(prim->GetAttr("padding")), padding);
  76. ASSERT_EQ(adpt->setAttr(conv, prim), 0);
  77. delete adpt;
  78. }
  79. #endif
  80. } // namespace transform
  81. } // namespace mindspore