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.

client_config_test.cc 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <chrono>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <functional>
  20. #include <iostream>
  21. #include <memory>
  22. #include <string>
  23. #include "minddata/dataset/core/client.h"
  24. #include "minddata/dataset/engine/datasetops/source/tf_reader_op.h"
  25. #include "minddata/dataset/engine/jagged_connector.h"
  26. #include "gtest/gtest.h"
  27. #include "minddata/dataset/core/global_context.h"
  28. #include "minddata/dataset/util/status.h"
  29. #include "minddata/dataset/core/client.h"
  30. #include "common/common.h"
  31. #include "gtest/gtest.h"
  32. #include "utils/log_adapter.h"
  33. #include <memory>
  34. #include <vector>
  35. #include <iostream>
  36. using namespace mindspore::dataset;
  37. using mindspore::LogStream;
  38. using mindspore::ExceptionType::NoExceptionType;
  39. using mindspore::MsLogLevel::INFO;
  40. class MindDataTestClientConfig : public UT::DatasetOpTesting {
  41. protected:
  42. };
  43. TEST_F(MindDataTestClientConfig, TestClientConfig1) {
  44. std::shared_ptr<ConfigManager> my_conf = GlobalContext::config_manager();
  45. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  46. ASSERT_EQ(my_conf->worker_connector_size(), kCfgWorkerConnectorSize);
  47. ASSERT_EQ(my_conf->op_connector_size(), kCfgOpConnectorSize);
  48. ASSERT_EQ(my_conf->seed(), kCfgDefaultSeed);
  49. my_conf->set_num_parallel_workers(2);
  50. my_conf->set_worker_connector_size(3);
  51. my_conf->set_op_connector_size(4);
  52. my_conf->set_seed(5);
  53. my_conf->set_enable_shared_mem(false);
  54. ASSERT_EQ(my_conf->num_parallel_workers(), 2);
  55. ASSERT_EQ(my_conf->worker_connector_size(), 3);
  56. ASSERT_EQ(my_conf->op_connector_size(), 4);
  57. ASSERT_EQ(my_conf->seed(), 5);
  58. ASSERT_EQ(my_conf->enable_shared_mem(), false);
  59. std::string file = datasets_root_path_ + "/declient.cfg";
  60. ASSERT_TRUE(my_conf->LoadFile(file));
  61. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  62. ASSERT_EQ(my_conf->worker_connector_size(), kCfgWorkerConnectorSize);
  63. ASSERT_EQ(my_conf->op_connector_size(), kCfgOpConnectorSize);
  64. ASSERT_EQ(my_conf->seed(), kCfgDefaultSeed);
  65. }
  66. TEST_F(MindDataTestClientConfig, TestClientConfig2) {
  67. std::shared_ptr<ConfigManager> my_conf = GlobalContext::config_manager();
  68. my_conf->set_num_parallel_workers(8);
  69. Status rc;
  70. // Start with an empty execution tree
  71. auto my_tree = std::make_shared<ExecutionTree>();
  72. // Test info:
  73. // Dataset from testDataset1 has 10 rows, 2 columns.
  74. std::string dataset_path;
  75. dataset_path = datasets_root_path_ + "/testDataset1/testDataset1.data";
  76. // get defaults for tf_reader
  77. std::shared_ptr<ConfigManager> config_manager = GlobalContext::config_manager();
  78. auto op_connector_size = config_manager->op_connector_size();
  79. std::vector<std::string> columns_to_load = {};
  80. std::vector<std::string> files = {dataset_path};
  81. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  82. std::shared_ptr<TFReaderOp> my_tfreader_op = std::make_shared<TFReaderOp>(
  83. 1, 2, 0, files, std::move(schema), op_connector_size, columns_to_load, false, 1, 0, false);
  84. rc = my_tfreader_op->Init();
  85. ASSERT_OK(rc);
  86. ASSERT_EQ(my_tfreader_op->num_workers(), 1);
  87. my_tree->AssociateNode(my_tfreader_op);
  88. // Set children/root layout.
  89. my_tree->AssignRoot(my_tfreader_op);
  90. my_tree->Prepare();
  91. my_tree->Launch();
  92. // Start the loop of reading tensors from our pipeline
  93. DatasetIterator di(my_tree);
  94. TensorRow tensor_list;
  95. rc = di.FetchNextTensorRow(&tensor_list);
  96. ASSERT_TRUE(rc.IsOk());
  97. int row_count = 0;
  98. while (!tensor_list.empty()) {
  99. rc = di.FetchNextTensorRow(&tensor_list);
  100. ASSERT_TRUE(rc.IsOk());
  101. row_count++;
  102. }
  103. ASSERT_EQ(row_count, 10); // Should be 10 rows fetched
  104. ASSERT_EQ(my_tfreader_op->num_workers(), 1);
  105. }