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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "dataset/core/client.h"
  24. #include "gtest/gtest.h"
  25. #include "dataset/core/global_context.h"
  26. #include "dataset/util/status.h"
  27. #include "dataset/core/client.h"
  28. #include "common/common.h"
  29. #include "gtest/gtest.h"
  30. #include "utils/log_adapter.h"
  31. #include <memory>
  32. #include <vector>
  33. #include <iostream>
  34. using namespace mindspore::dataset;
  35. using mindspore::MsLogLevel::INFO;
  36. using mindspore::ExceptionType::NoExceptionType;
  37. using mindspore::LogStream;
  38. class MindDataTestClientConfig : public UT::DatasetOpTesting {
  39. protected:
  40. };
  41. TEST_F(MindDataTestClientConfig, TestClientConfig1) {
  42. std::shared_ptr<ConfigManager> my_conf = GlobalContext::config_manager();
  43. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  44. ASSERT_EQ(my_conf->rows_per_buffer(), kCfgRowsPerBuffer);
  45. ASSERT_EQ(my_conf->worker_connector_size(), kCfgWorkerConnectorSize);
  46. ASSERT_EQ(my_conf->op_connector_size(), kCfgOpConnectorSize);
  47. ASSERT_EQ(my_conf->seed(), kCfgDefaultSeed);
  48. my_conf->set_num_parallel_workers(2);
  49. my_conf->set_rows_per_buffer(1);
  50. my_conf->set_worker_connector_size(3);
  51. my_conf->set_op_connector_size(4);
  52. my_conf->set_seed(5);
  53. ASSERT_EQ(my_conf->num_parallel_workers(), 2);
  54. ASSERT_EQ(my_conf->rows_per_buffer(), 1);
  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. std::string file = datasets_root_path_ + "/declient.cfg";
  59. ASSERT_TRUE(my_conf->LoadFile(file));
  60. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  61. ASSERT_EQ(my_conf->rows_per_buffer(), kCfgRowsPerBuffer);
  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(16);
  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. // RowsPerBuffer buffer setting of 2 divides evenly into total rows.
  75. std::string dataset_path;
  76. dataset_path = datasets_root_path_ + "/testDataset1";
  77. std::shared_ptr<StorageOp> my_storage_op;
  78. StorageOp::Builder builder;
  79. builder.SetDatasetFilesDir(dataset_path);
  80. rc = builder.Build(&my_storage_op);
  81. ASSERT_TRUE(rc.IsOk());
  82. ASSERT_EQ(my_storage_op->num_workers(),16);
  83. my_tree->AssociateNode(my_storage_op);
  84. // Set children/root layout.
  85. my_tree->AssignRoot(my_storage_op);
  86. my_tree->Prepare();
  87. my_tree->Launch();
  88. // Start the loop of reading tensors from our pipeline
  89. DatasetIterator di(my_tree);
  90. TensorRow tensor_list;
  91. rc = di.FetchNextTensorRow(&tensor_list);
  92. ASSERT_TRUE(rc.IsOk());
  93. int row_count = 0;
  94. while (!tensor_list.empty()) {
  95. rc = di.FetchNextTensorRow(&tensor_list);
  96. ASSERT_TRUE(rc.IsOk());
  97. row_count++;
  98. }
  99. ASSERT_EQ(row_count, 10); // Should be 10 rows fetched
  100. ASSERT_EQ(my_storage_op->num_workers(),16);
  101. }