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.

strategy_test.cc 2.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright 2019 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 <string>
  17. #include <list>
  18. #include <vector>
  19. #include "common/common_test.h"
  20. #include "frontend/parallel/strategy.h"
  21. namespace mindspore {
  22. namespace parallel {
  23. class TestStrategy : public UT::Common {
  24. public:
  25. TestStrategy() {}
  26. void SetUp() {}
  27. void TearDown() {}
  28. };
  29. TEST_F(TestStrategy, GetInputNumber) {
  30. int32_t number = 2;
  31. int32_t stage = 1;
  32. std::vector<int32_t> dimension1 = {2, 4};
  33. std::vector<int32_t> dimension2 = {2, 2};
  34. std::vector<std::vector<int32_t>> inputs = {dimension1, dimension2};
  35. Strategy strategy(stage, inputs);
  36. int32_t number_test = strategy.GetInputNumber();
  37. ASSERT_EQ(number, number_test);
  38. }
  39. TEST_F(TestStrategy, GetInputStage) {
  40. int32_t stage = 1;
  41. std::vector<int32_t> dimension1 = {2, 4};
  42. std::vector<int32_t> dimension2 = {2, 2};
  43. std::vector<std::vector<int32_t>> inputs = {dimension1, dimension2};
  44. Strategy strategy(stage, inputs);
  45. int32_t stage_test = strategy.GetInputStage();
  46. ASSERT_EQ(stage, stage_test);
  47. }
  48. TEST_F(TestStrategy, GetInputDim) {
  49. int32_t stage = 1;
  50. std::vector<int32_t> dimension1 = {2, 4};
  51. std::vector<int32_t> dimension2 = {2, 2};
  52. std::vector<std::vector<int32_t>> inputs = {dimension1, dimension2};
  53. Strategy strategy(stage, inputs);
  54. std::vector<std::vector<int32_t>> inputs_test = strategy.GetInputDim();
  55. ASSERT_EQ(inputs, inputs_test);
  56. }
  57. TEST_F(TestStrategy, IsEqual) {
  58. int32_t stage1 = 0, stage2 = 0, stage3 = 1, stage4 = 0;
  59. std::vector<int32_t> dimension1 = {8, 1};
  60. std::vector<int32_t> dimension2 = {1, 8};
  61. std::vector<std::vector<int32_t>> inputs1 = {dimension1};
  62. std::vector<std::vector<int32_t>> inputs2 = {dimension1};
  63. std::vector<std::vector<int32_t>> inputs3 = {dimension2};
  64. std::vector<std::vector<int32_t>> inputs4 = {dimension1, dimension2};
  65. StrategyPtr stra1 = std::make_shared<Strategy>(stage1, inputs1);
  66. StrategyPtr stra2 = std::make_shared<Strategy>(stage2, inputs2);
  67. StrategyPtr stra3 = std::make_shared<Strategy>(stage3, inputs3);
  68. StrategyPtr stra4 = std::make_shared<Strategy>(stage4, inputs4);
  69. ASSERT_EQ(stra1->IsEqual(stra2), true);
  70. ASSERT_EQ(stra1->IsEqual(stra3), false);
  71. ASSERT_EQ(stra1->IsEqual(stra4), false);
  72. }
  73. } // namespace parallel
  74. } // namespace mindspore