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.

execution_tree_test.cc 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "minddata/dataset/util/circular_pool.h"
  18. #include "minddata/dataset/core/client.h"
  19. #include "minddata/dataset/engine/execution_tree.h"
  20. #include "minddata/dataset/engine/datasetops/shuffle_op.h"
  21. #include "minddata/dataset/engine/datasetops/source/tf_reader_op.h"
  22. #include "minddata/dataset/engine/jagged_connector.h"
  23. #include "common/common.h"
  24. #include "gtest/gtest.h"
  25. #include "utils/log_adapter.h"
  26. using namespace mindspore::dataset;
  27. using mindspore::LogStream;
  28. using mindspore::ExceptionType::NoExceptionType;
  29. using mindspore::MsLogLevel::INFO;
  30. class MindDataTestExecutionTree : public UT::DatasetOpTesting {
  31. public:
  32. };
  33. // Construct some tree nodes and play with them
  34. TEST_F(MindDataTestExecutionTree, TestExecutionTree1) {
  35. MS_LOG(INFO) << "Doing MindDataTestExecutionTree1.";
  36. // Start with an empty execution tree
  37. auto my_tree = std::make_shared<ExecutionTree>();
  38. ASSERT_NE(my_tree, nullptr);
  39. uint32_t shuffle_size = 32;
  40. uint32_t connector_size = 8;
  41. std::shared_ptr<ShuffleOp> leaf_op1 = std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false);
  42. ASSERT_NE(leaf_op1, nullptr);
  43. my_tree->AssociateNode(leaf_op1);
  44. shuffle_size = 16;
  45. std::shared_ptr<ShuffleOp> leaf_op2 = std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false);
  46. ASSERT_NE(leaf_op2, nullptr);
  47. my_tree->AssociateNode(leaf_op2);
  48. shuffle_size = 8;
  49. std::shared_ptr<ShuffleOp> parent_op = std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false);
  50. ASSERT_NE(parent_op, nullptr);
  51. my_tree->AssociateNode(parent_op);
  52. // It's up to you if you want to use move semantic or not here.
  53. // By using move, we transfer ownership of the child to the parent.
  54. // If you do not use move,
  55. // we get a reference count bump to the pointer and you have
  56. // your own pointer to it, plus the parent has a copy of the pointer.
  57. parent_op->AddChild(std::move(leaf_op1));
  58. parent_op->AddChild(std::move(leaf_op2));
  59. shuffle_size = 4;
  60. std::shared_ptr<DatasetOp> root_op = std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false);
  61. my_tree->AssignRoot(root_op);
  62. root_op->AddChild(parent_op);
  63. ASSERT_NE(root_op, nullptr);
  64. // At this point, since move semantic was used,
  65. // I don't have any operator access myself now.
  66. // Ownership is fully transferred into the tree.
  67. // explicitly drive tree destruction rather than
  68. // wait for descoping (to examine in debugger
  69. // just to see it work)
  70. my_tree.reset();
  71. MS_LOG(INFO) << "Done.";
  72. }
  73. // Construct some tree nodes and play with them
  74. TEST_F(MindDataTestExecutionTree, TestExecutionTree2) {
  75. MS_LOG(INFO) << "Doing MindDataTestExecutionTree2.";
  76. Status rc;
  77. auto my_tree = std::make_shared<ExecutionTree>();
  78. std::string dataset_path = datasets_root_path_ + "/testDataset1/testDataset1.data";
  79. std::shared_ptr<ConfigManager> config_manager = GlobalContext::config_manager();
  80. auto op_connector_size = config_manager->op_connector_size();
  81. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  82. std::vector<std::string> columns_to_load = {};
  83. std::vector<std::string> files = {dataset_path};
  84. std::shared_ptr<TFReaderOp> my_tfreader_op = std::make_shared<TFReaderOp>(
  85. 1, 2, 0, files, std::move(schema), op_connector_size, columns_to_load, false, 1, 0, false);
  86. rc = my_tfreader_op->Init();
  87. ASSERT_OK(rc);
  88. rc = my_tree->AssociateNode(my_tfreader_op);
  89. ASSERT_OK(rc);
  90. rc = my_tree->AssignRoot(my_tfreader_op);
  91. ASSERT_OK(rc);
  92. // prepare the tree
  93. rc = my_tree->Prepare();
  94. ASSERT_OK(rc);
  95. // Launch the tree execution to kick off threads
  96. // and start running the pipeline
  97. MS_LOG(INFO) << "Launching my tree.";
  98. rc = my_tree->Launch();
  99. ASSERT_OK(rc);
  100. }