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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 (!defined ENABLE_GE)
  32. #if 0
  33. // fix conv2d ut
  34. TEST_F(TestOpAdapter, TestSpecilization_Conv2D) {
  35. BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
  36. auto input = std::make_shared<ge::Operator>();
  37. auto conv = std::make_shared<Conv2D>();
  38. ASSERT_EQ(adpt->setInput(conv, 1, input), 0);
  39. ASSERT_EQ(adpt->setInput(conv, 2, input), 0);
  40. ASSERT_EQ(adpt->setInput(conv, 3, input), NOT_FOUND);
  41. ASSERT_EQ(0, adpt->setAttr(conv, "group", 1));
  42. ASSERT_EQ(0, adpt->setAttr(conv, "mode", 1));
  43. delete adpt;
  44. }
  45. #endif
  46. TEST_F(TestOpAdapter, TestSpecilization_Const) {
  47. BaseOpAdapter *adpt = new OpAdapter<Const>();
  48. auto valuenode = std::make_shared<Const>();
  49. auto input = std::make_shared<Const>();
  50. ASSERT_EQ(adpt->setInput(valuenode, 1, input), NOT_FOUND);
  51. delete adpt;
  52. }
  53. #if 0
  54. // fix conv2d ut
  55. TEST_F(TestOpAdapter, TestSetAttr_Conv2d_Primitive) {
  56. BaseOpAdapter *adpt = new OpAdapter<Conv2D>();
  57. auto conv = std::make_shared<Conv2D>();
  58. ASSERT_EQ(adpt->setAttr(conv, "padding", 1), NOT_FOUND);
  59. ASSERT_EQ(adpt->setAttr(conv, "pad", 1), 0);
  60. ASSERT_EQ(adpt->setAttr(conv, "pad_mode", string("same")), 0);
  61. ASSERT_EQ(adpt->setAttr(conv, "nothing", "test"), NOT_FOUND);
  62. const mindspore::HashMap<std::string, ValuePtr> attrs = {
  63. {"padding", MakeValue(2)},
  64. {"padding_mode", MakeValue(string("normal"))},
  65. {"stride", MakeValue(8)}
  66. };
  67. auto prim = prim::kPrimConv2D;
  68. prim->SetAttrs({
  69. {"strides", MakeValue(3)},
  70. {"padding", MakeValue(1)},
  71. });
  72. ASSERT_EQ(prim->name(), prim::kPrimConv2D->name());
  73. Int64Imm strides(3);
  74. Int64Imm padding(1);
  75. ASSERT_EQ(*(prim->GetAttr("strides")), strides);
  76. ASSERT_EQ(*(prim->GetAttr("padding")), padding);
  77. ASSERT_EQ(adpt->setAttr(conv, prim), 0);
  78. delete adpt;
  79. }
  80. #endif
  81. #endif
  82. } // namespace transform
  83. } // namespace mindspore