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.

profiler_test.cc 5.5 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * Copyright 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 "common/common.h"
  17. #include "minddata/dataset/engine/perf/profiling.h"
  18. #include "minddata/dataset/include/dataset/datasets.h"
  19. using namespace mindspore::dataset;
  20. using mindspore::LogStream;
  21. using mindspore::MsLogLevel::INFO;
  22. namespace mindspore {
  23. namespace dataset {
  24. namespace test {
  25. class MindDataTestProfiler : public UT::DatasetOpTesting {
  26. protected:
  27. MindDataTestProfiler() {}
  28. Status DeleteFiles(int file_id = 0) {
  29. std::shared_ptr<ProfilingManager> profiler_manager = GlobalContext::profiling_manager();
  30. std::string pipeline_file = "./pipeline_profiling_" + std::to_string(file_id) + ".json";
  31. std::string cpu_util_file = "./minddata_cpu_utilization_" + std::to_string(file_id) + ".json";
  32. std::string dataset_iterator_file = "./dataset_iterator_profiling_" + std::to_string(file_id) + ".txt";
  33. if (remove(pipeline_file.c_str()) == 0 && remove(cpu_util_file.c_str()) == 0 &&
  34. remove(dataset_iterator_file.c_str()) == 0) {
  35. return Status::OK();
  36. } else {
  37. RETURN_STATUS_UNEXPECTED("Error deleting profiler files");
  38. }
  39. }
  40. };
  41. /// Feature: MindData Profiling Support
  42. /// Description: Test MindData Profiling with profiling enabled for pipeline with ImageFolder
  43. /// Expectation: Profiling files are created.
  44. TEST_F(MindDataTestProfiler, TestProfilerManager1) {
  45. MS_LOG(INFO) << "Doing MindDataTestPipeline-TestProfilerManager1.";
  46. // Enable profiler and check
  47. common::SetEnv("RANK_ID", "1");
  48. std::shared_ptr<ProfilingManager> profiler_manager = GlobalContext::profiling_manager();
  49. EXPECT_OK(profiler_manager->Init());
  50. EXPECT_OK(profiler_manager->Start());
  51. EXPECT_TRUE(profiler_manager->IsProfilingEnable());
  52. std::string folder_path = datasets_root_path_ + "/testPK/data/";
  53. std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<SequentialSampler>(0, 2));
  54. EXPECT_NE(ds, nullptr);
  55. ds = ds->Repeat(2);
  56. EXPECT_NE(ds, nullptr);
  57. ds = ds->Shuffle(4);
  58. EXPECT_NE(ds, nullptr);
  59. // Create objects for the tensor ops
  60. std::shared_ptr<TensorTransform> one_hot = std::make_shared<transforms::OneHot>(10);
  61. EXPECT_NE(one_hot, nullptr);
  62. // Create a Map operation, this will automatically add a project after map
  63. ds = ds->Map({one_hot}, {"label"}, {"label"}, {"label"});
  64. EXPECT_NE(ds, nullptr);
  65. ds = ds->Take(4);
  66. EXPECT_NE(ds, nullptr);
  67. ds = ds->Batch(2, true);
  68. EXPECT_NE(ds, nullptr);
  69. // No columns are specified, use all columns
  70. std::shared_ptr<Iterator> iter = ds->CreateIterator();
  71. EXPECT_NE(iter, nullptr);
  72. // Iterate the dataset and get each row
  73. std::vector<mindspore::MSTensor> row;
  74. ASSERT_OK(iter->GetNextRow(&row));
  75. uint64_t i = 0;
  76. while (row.size() != 0) {
  77. ASSERT_OK(iter->GetNextRow(&row));
  78. i++;
  79. }
  80. EXPECT_EQ(i, 2);
  81. // Manually terminate the pipeline
  82. iter->Stop();
  83. // Stop MindData Profiling and save output files to current working directory
  84. EXPECT_OK(profiler_manager->Stop());
  85. EXPECT_FALSE(profiler_manager->IsProfilingEnable());
  86. EXPECT_OK(profiler_manager->Save("."));
  87. // File_id is expected to equal RANK_ID
  88. EXPECT_OK(DeleteFiles(1));
  89. }
  90. /// Feature: MindData Profiling Support
  91. /// Description: Test MindData Profiling with profiling enabled for pipeline with Mnist
  92. /// Expectation: Profiling files are created.
  93. TEST_F(MindDataTestProfiler, TestProfilerManager2) {
  94. MS_LOG(INFO) << "Doing MindDataTestPipeline-TestProfilerManager2.";
  95. // Enable profiler and check
  96. common::SetEnv("RANK_ID", "2");
  97. std::shared_ptr<ProfilingManager> profiler_manager = GlobalContext::profiling_manager();
  98. EXPECT_OK(profiler_manager->Init());
  99. EXPECT_OK(profiler_manager->Start());
  100. EXPECT_TRUE(profiler_manager->IsProfilingEnable());
  101. // Create a Mnist Dataset
  102. std::string folder_path = datasets_root_path_ + "/testMnistData/";
  103. std::shared_ptr<Dataset> ds = Mnist(folder_path, "all", std::make_shared<SequentialSampler>(0, 3));
  104. EXPECT_NE(ds, nullptr);
  105. ds = ds->Skip(1);
  106. EXPECT_NE(ds, nullptr);
  107. ds = ds->Repeat(2);
  108. EXPECT_NE(ds, nullptr);
  109. ds = ds->Batch(2, false);
  110. EXPECT_NE(ds, nullptr);
  111. // No columns are specified, use all columns
  112. std::shared_ptr<Iterator> iter = ds->CreateIterator();
  113. EXPECT_NE(iter, nullptr);
  114. // Iterate the dataset and get each row
  115. std::vector<mindspore::MSTensor> row;
  116. ASSERT_OK(iter->GetNextRow(&row));
  117. uint64_t i = 0;
  118. while (row.size() != 0) {
  119. ASSERT_OK(iter->GetNextRow(&row));
  120. i++;
  121. }
  122. EXPECT_EQ(i, 2);
  123. // Manually terminate the pipeline
  124. iter->Stop();
  125. // Stop MindData Profiling and save output files to current working directory
  126. EXPECT_OK(profiler_manager->Stop());
  127. EXPECT_FALSE(profiler_manager->IsProfilingEnable());
  128. EXPECT_OK(profiler_manager->Save("."));
  129. // File_id is expected to equal RANK_ID
  130. EXPECT_OK(DeleteFiles(2));
  131. }
  132. } // namespace test
  133. } // namespace dataset
  134. } // namespace mindspore