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.

optimization_pass_test.cc 3.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright 2020 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 <memory>
  17. #include <string>
  18. #include "minddata/dataset/core/client.h"
  19. #include "common/common.h"
  20. #include "gtest/gtest.h"
  21. #include "minddata/dataset/engine/execution_tree.h"
  22. #include "minddata/dataset/engine/ir/datasetops/dataset_node.h"
  23. #include "minddata/dataset/engine/opt/post/auto_worker_pass.h"
  24. #include "minddata/dataset/engine/opt/pre/getter_pass.h"
  25. using namespace mindspore::dataset;
  26. using mindspore::LogStream;
  27. using mindspore::MsLogLevel::INFO;
  28. class MindDataTestOptimizationPass : public UT::DatasetOpTesting {};
  29. TEST_F(MindDataTestOptimizationPass, MindDataTestAutoWorkerPass) {
  30. MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestAutoWorkerPass.";
  31. std::shared_ptr<SchemaObj> schema = std::make_shared<SchemaObj>();
  32. ASSERT_TRUE(schema->add_column("label", "uint32", {}));
  33. std::shared_ptr<Dataset> map_leaf = ImageFolder("dir")->SetNumWorkers(0);
  34. std::shared_ptr<Dataset> nonmap_leaf = RandomData(44, schema)->SetNumWorkers(0);
  35. std::shared_ptr<Dataset> batch = Zip({map_leaf, nonmap_leaf})->Batch(1)->SetNumWorkers(0);
  36. std::shared_ptr<Dataset> map = batch->Map({})->SetNumWorkers(0);
  37. // {ImageFolder, RandomData} -> zip -> batch
  38. EXPECT_EQ(map_leaf->IRNode()->num_workers(), 0);
  39. EXPECT_EQ(nonmap_leaf->IRNode()->num_workers(), 0);
  40. EXPECT_EQ(batch->IRNode()->num_workers(), 0);
  41. EXPECT_EQ(map->IRNode()->num_workers(), 0);
  42. std::unique_ptr<IRPass> pass = std::make_unique<AutoWorkerPass>();
  43. bool m = false;
  44. ASSERT_OK(pass->Run(map->IRNode(), &m));
  45. // checking that after this pass, num_workers are set correctly (aka a positive number)
  46. // It is hard to test a exact value because num_threads are different for different machine
  47. // however, this will for sure succeed bc regardless of the total threads on cpu, this would always be >= 1
  48. EXPECT_NE(map_leaf->IRNode()->num_workers(), 0);
  49. EXPECT_NE(nonmap_leaf->IRNode()->num_workers(), 0);
  50. EXPECT_NE(batch->IRNode()->num_workers(), 0);
  51. EXPECT_NE(map->IRNode()->num_workers(), 0);
  52. MS_LOG(DEBUG) << map_leaf->IRNode()->Name() << ": num_worker=" << map_leaf->IRNode()->num_workers();
  53. MS_LOG(DEBUG) << nonmap_leaf->IRNode()->Name() << ": num_worker=" << nonmap_leaf->IRNode()->num_workers();
  54. MS_LOG(DEBUG) << batch->IRNode()->Name() << ": num_worker=" << batch->IRNode()->num_workers();
  55. MS_LOG(DEBUG) << map->IRNode()->Name() << ": num_worker=" << map->IRNode()->num_workers();
  56. }