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 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "dataset/util/circular_pool.h"
  18. #include "dataset/core/client.h"
  19. #include "dataset/engine/execution_tree.h"
  20. #include "dataset/engine/datasetops/shuffle_op.h"
  21. #include "dataset/engine/datasetops/source/storage_op.h"
  22. #include "common/common.h"
  23. #include "gtest/gtest.h"
  24. #include "dataset/util/de_error.h"
  25. #include "utils/log_adapter.h"
  26. using namespace mindspore::dataset;
  27. using mindspore::MsLogLevel::INFO;
  28. using mindspore::ExceptionType::NoExceptionType;
  29. using mindspore::LogStream;
  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 =
  42. std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false, 32);
  43. ASSERT_NE(leaf_op1, nullptr);
  44. my_tree->AssociateNode(leaf_op1);
  45. shuffle_size = 16;
  46. std::shared_ptr<ShuffleOp> leaf_op2 =
  47. std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false, 32);
  48. ASSERT_NE(leaf_op2, nullptr);
  49. my_tree->AssociateNode(leaf_op2);
  50. shuffle_size = 8;
  51. std::shared_ptr<ShuffleOp> parent_op =
  52. std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false, 32);
  53. ASSERT_NE(parent_op, nullptr);
  54. my_tree->AssociateNode(parent_op);
  55. // It's up to you if you want to use move semantic or not here.
  56. // By using move, we transfer ownership of the child to the parent.
  57. // If you do not use move,
  58. // we get a reference count bump to the pointer and you have
  59. // your own pointer to it, plus the parent has a copy of the pointer.
  60. parent_op->AddChild(std::move(leaf_op1));
  61. parent_op->AddChild(std::move(leaf_op2));
  62. shuffle_size = 4;
  63. std::shared_ptr<DatasetOp> root_op =
  64. std::make_shared<ShuffleOp>(shuffle_size, 0, connector_size, false, 32);
  65. my_tree->AssignRoot(root_op);
  66. root_op->AddChild(parent_op);
  67. ASSERT_NE(root_op, nullptr);
  68. // Testing Iterator
  69. MS_LOG(INFO) << "Testing Tree Iterator from root.";
  70. for (auto itr = my_tree->begin(); itr != my_tree->end(); ++itr) {
  71. itr->Print(std::cout, false);
  72. }
  73. MS_LOG(INFO) << "Finished testing Tree Iterator from root.";
  74. MS_LOG(INFO) << "Testing Tree Iterator from parentOp.";
  75. for (auto itr = my_tree->begin(parent_op); itr != my_tree->end(); ++itr) {
  76. itr->Print(std::cout, false);
  77. }
  78. MS_LOG(INFO) << "Finished testing Tree Iterator from parentOp.";
  79. // At this point, since move semantic was used,
  80. // I don't have any operator access myself now.
  81. // Ownership is fully transferred into the tree.
  82. // explicitly drive tree destruction rather than
  83. // wait for descoping (to examine in debugger
  84. // just to see it work)
  85. my_tree.reset();
  86. MS_LOG(INFO) << "Done.";
  87. }
  88. // Construct some tree nodes and play with them
  89. TEST_F(MindDataTestExecutionTree, TestExecutionTree2) {
  90. MS_LOG(INFO) << "Doing MindDataTestExecutionTree2.";
  91. Status rc;
  92. auto my_tree = std::make_shared<ExecutionTree>();
  93. std::string dataset_path = datasets_root_path_ + "/testDataset1";
  94. std::shared_ptr<StorageOp> my_storage_op;
  95. StorageOp::Builder()
  96. .SetDatasetFilesDir(dataset_path)
  97. .SetRowsPerBuffer(2)
  98. .SetWorkerConnectorSize(2)
  99. .SetNumWorkers(2)
  100. .Build(&my_storage_op);
  101. my_tree->AssociateNode(my_storage_op);
  102. my_tree->AssignRoot(my_storage_op);
  103. // prepare the tree
  104. my_tree->Prepare();
  105. // Launch the tree execution to kick off threads
  106. // and start running the pipeline
  107. MS_LOG(INFO) << "Launching my tree.";
  108. my_tree->Launch();
  109. // Simulate a parse of data from our pipeline.
  110. std::shared_ptr<DatasetOp> root_node = my_tree->root();
  111. // Start the loop of reading from our pipeline using iterator
  112. MS_LOG(INFO) << "Testing DatasetIterator in testTree2.";
  113. DatasetIterator di(my_tree);
  114. TensorRow buffer;
  115. rc = di.FetchNextTensorRow(&buffer);
  116. EXPECT_TRUE(rc.IsOk());
  117. while (!buffer.empty()) {
  118. rc = di.FetchNextTensorRow(&buffer);
  119. EXPECT_TRUE(rc.IsOk());
  120. }
  121. }
  122. // Construct some tree nodes and play with them
  123. TEST_F(MindDataTestExecutionTree, TestExecutionTree3) {
  124. MS_LOG(INFO) << "Doing MindDataTestExecutionTree3.";
  125. }