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

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