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.

virtual_dataset_test.cc 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright 2019-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 <string>
  17. #include <list>
  18. #include <vector>
  19. #include "common/common_test.h"
  20. #include "frontend/parallel/strategy.h"
  21. #include "frontend/parallel/ops_info/virtual_dataset_info.h"
  22. #include "frontend/parallel/device_manager.h"
  23. #include "frontend/parallel/step_parallel.h"
  24. namespace mindspore {
  25. namespace parallel {
  26. class VirtualDatasetInfo;
  27. using VirtualDatasetInfoPtr = std::shared_ptr<VirtualDatasetInfo>;
  28. VirtualDatasetInfoPtr virtual_dataset;
  29. class TestVirtualDatasetInfo : public UT::Common {
  30. public:
  31. TestVirtualDatasetInfo() {}
  32. void SetUp();
  33. void TearDown() {}
  34. };
  35. void TestVirtualDatasetInfo::SetUp() {
  36. RankList dev_list;
  37. for (int32_t i = 0; i < 130; i++) {
  38. dev_list.push_back(i);
  39. }
  40. RankList stage_map;
  41. stage_map.push_back(16);
  42. stage_map.push_back(114);
  43. int32_t local_dev = 0;
  44. // create a new g_device_manager
  45. g_device_manager = std::make_shared<DeviceManager>();
  46. g_device_manager->Init(dev_list, local_dev, stage_map, "hccl");
  47. mindspore::HashMap<std::string, ValuePtr> attr;
  48. Shapes inputs_shape = {{128, 32}, {1280, 320}, {12800, 3200}};
  49. Shapes outputs_shape = {{128, 32}, {1280, 320}, {12800, 3200}};
  50. virtual_dataset = std::make_shared<VirtualDatasetInfo>("virtual_dataset_info", inputs_shape, outputs_shape, attr);
  51. }
  52. TEST_F(TestVirtualDatasetInfo, InferDevMatrixShape1) {
  53. Strategys inputs = {{16, 1}, {16, 1}, {16, 1}};
  54. StrategyPtr strategy = NewStrategy(0, inputs);
  55. virtual_dataset->Init(strategy, nullptr);
  56. Shape dev_matrix_shape = virtual_dataset->dev_matrix_shape();
  57. Shape expect = {16, 1};
  58. ASSERT_EQ(dev_matrix_shape, expect);
  59. }
  60. TEST_F(TestVirtualDatasetInfo, GetForwardOp1) {
  61. Strategys inputs = {{8, 1}, {8, 1}, {8, 1}};
  62. StrategyPtr strategy = NewStrategy(0, inputs);
  63. virtual_dataset->Init(strategy, nullptr);
  64. OperatorVector forward_op = virtual_dataset->forward_op();
  65. size_t size = forward_op.size();
  66. ASSERT_EQ(size, 0);
  67. }
  68. TEST_F(TestVirtualDatasetInfo, GetMirrorOPs1) {
  69. Strategys inputs = {{8, 1}, {8, 1}, {8, 1}};
  70. StrategyPtr strategy = NewStrategy(0, inputs);
  71. virtual_dataset->Init(strategy, nullptr);
  72. MirrorOps mirror_ops = virtual_dataset->mirror_ops();
  73. size_t size = mirror_ops.size();
  74. // no broadcast
  75. ASSERT_EQ(size, 0);
  76. // ASSERT_EQ(size, 3);
  77. }
  78. } // namespace parallel
  79. } // namespace mindspore