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.

cache_op_test.cc 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /**
  2. * Copyright 2020-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 <string>
  17. #include "minddata/dataset/core/client.h"
  18. #include "minddata/dataset/engine/cache/cache_client.h"
  19. #include "minddata/dataset/engine/execution_tree.h"
  20. #include "minddata/dataset/engine/datasetops/cache_op.h"
  21. #include "minddata/dataset/engine/datasetops/cache_lookup_op.h"
  22. #include "minddata/dataset/engine/datasetops/cache_merge_op.h"
  23. #include "minddata/dataset/engine/datasetops/source/image_folder_op.h"
  24. #include "common/common.h"
  25. #include "gtest/gtest.h"
  26. #include "utils/log_adapter.h"
  27. #include "minddata/dataset/engine/datasetops/source/random_data_op.h"
  28. #include "minddata/dataset/engine/data_schema.h"
  29. using namespace mindspore::dataset;
  30. using mindspore::LogStream;
  31. using mindspore::dataset::CacheClient;
  32. using mindspore::dataset::TaskGroup;
  33. using mindspore::ExceptionType::NoExceptionType;
  34. using mindspore::MsLogLevel::INFO;
  35. // Helper function to get the session id from SESSION_ID env variable
  36. Status GetSessionFromEnv(session_id_type *session_id) {
  37. RETURN_UNEXPECTED_IF_NULL(session_id);
  38. if (const char *session_env = std::getenv("SESSION_ID")) {
  39. std::string session_id_str(session_env);
  40. try {
  41. *session_id = std::stoul(session_id_str);
  42. } catch (const std::exception &e) {
  43. std::string err_msg = "Invalid numeric value for session id in env var: " + session_id_str;
  44. return Status(StatusCode::kMDSyntaxError, err_msg);
  45. }
  46. } else {
  47. RETURN_STATUS_UNEXPECTED("Test case requires a session id to be provided via SESSION_ID environment variable.");
  48. }
  49. return Status::OK();
  50. }
  51. class MindDataTestCacheOp : public UT::DatasetOpTesting {
  52. public:
  53. void SetUp() override {
  54. DatasetOpTesting::SetUp();
  55. GlobalInit();
  56. }
  57. };
  58. TEST_F(MindDataTestCacheOp, DISABLED_TestCacheServer) {
  59. Status rc;
  60. CacheClient::Builder builder;
  61. session_id_type env_session;
  62. rc = GetSessionFromEnv(&env_session);
  63. ASSERT_TRUE(rc.IsOk());
  64. // use arbitrary session of 1, size of 0, spilling// is true
  65. builder.SetSessionId(env_session).SetCacheMemSz(0).SetSpill(true);
  66. std::shared_ptr<CacheClient> myClient;
  67. rc = builder.Build(&myClient);
  68. ASSERT_TRUE(rc.IsOk());
  69. // cksum value of 1 for CreateCache here...normally you do not directly create a cache and the cksum arg is generated.
  70. rc = myClient->CreateCache(1, true);
  71. ASSERT_TRUE(rc.IsOk());
  72. std::cout << *myClient << std::endl;
  73. // Create a schema using the C api's
  74. int32_t rank = 0; // not used
  75. std::unique_ptr<DataSchema> testSchema = std::make_unique<DataSchema>();
  76. // 2 columns. First column is an "image" 640,480,3
  77. TensorShape c1Shape({640, 480, 3});
  78. ColDescriptor c1("image", DataType(DataType::DE_INT8), TensorImpl::kFlexible,
  79. rank, // not used
  80. &c1Shape);
  81. // Column 2 will just be a scalar label number
  82. TensorShape c2Shape({}); // empty shape is a 1-value scalar Tensor
  83. ColDescriptor c2("label", DataType(DataType::DE_UINT32), TensorImpl::kFlexible, rank, &c2Shape);
  84. testSchema->AddColumn(c1);
  85. testSchema->AddColumn(c2);
  86. std::unordered_map<std::string, int32_t> map;
  87. rc = testSchema->GetColumnNameMap(&map);
  88. ASSERT_TRUE(rc.IsOk());
  89. // Test the CacheSchema api
  90. rc = myClient->CacheSchema(map);
  91. ASSERT_TRUE(rc.IsOk());
  92. // Create a tensor, take a snapshot and restore it back, and compare.
  93. std::shared_ptr<Tensor> t;
  94. Tensor::CreateEmpty(TensorShape({2, 3}), DataType(DataType::DE_UINT64), &t);
  95. t->SetItemAt<uint64_t>({0, 0}, 1);
  96. t->SetItemAt<uint64_t>({0, 1}, 2);
  97. t->SetItemAt<uint64_t>({0, 2}, 3);
  98. t->SetItemAt<uint64_t>({1, 0}, 4);
  99. t->SetItemAt<uint64_t>({1, 1}, 5);
  100. t->SetItemAt<uint64_t>({1, 2}, 6);
  101. std::cout << *t << std::endl;
  102. TensorTable tbl;
  103. TensorRow row;
  104. row.push_back(t);
  105. int64_t row_id;
  106. rc = myClient->WriteRow(row, &row_id);
  107. ASSERT_TRUE(rc.IsOk());
  108. // Switch off build phase.
  109. rc = myClient->BuildPhaseDone();
  110. ASSERT_TRUE(rc.IsOk());
  111. // Now restore from cache.
  112. row.clear();
  113. rc = myClient->GetRows({row_id}, &tbl);
  114. row = tbl.front();
  115. ASSERT_TRUE(rc.IsOk());
  116. auto r = row.front();
  117. std::cout << *r << std::endl;
  118. // Compare
  119. bool cmp = (*t == *r);
  120. ASSERT_TRUE(cmp);
  121. // Get back the schema and verify
  122. std::unordered_map<std::string, int32_t> map_out;
  123. rc = myClient->FetchSchema(&map_out);
  124. ASSERT_TRUE(rc.IsOk());
  125. cmp = (map_out == map);
  126. ASSERT_TRUE(cmp);
  127. rc = myClient->DestroyCache();
  128. ASSERT_TRUE(rc.IsOk());
  129. }
  130. TEST_F(MindDataTestCacheOp, DISABLED_TestConcurrencyRequest) {
  131. // Clear the rc of the master thread if any
  132. (void)TaskManager::GetMasterThreadRc();
  133. TaskGroup vg;
  134. Status rc;
  135. session_id_type env_session;
  136. rc = GetSessionFromEnv(&env_session);
  137. ASSERT_TRUE(rc.IsOk());
  138. // use arbitrary session of 1, size 1, spilling is true
  139. CacheClient::Builder builder;
  140. // use arbitrary session of 1, size of 0, spilling// is true
  141. builder.SetSessionId(env_session).SetCacheMemSz(1).SetSpill(true);
  142. std::shared_ptr<CacheClient> myClient;
  143. rc = builder.Build(&myClient);
  144. ASSERT_TRUE(rc.IsOk());
  145. // cksum value of 1 for CreateCache here...normally you do not directly create a cache and the cksum arg is generated.
  146. rc = myClient->CreateCache(1, true);
  147. ASSERT_TRUE(rc.IsOk());
  148. std::cout << *myClient << std::endl;
  149. std::shared_ptr<Tensor> t;
  150. Tensor::CreateEmpty(TensorShape({2, 3}), DataType(DataType::DE_UINT64), &t);
  151. t->SetItemAt<uint64_t>({0, 0}, 1);
  152. t->SetItemAt<uint64_t>({0, 1}, 2);
  153. t->SetItemAt<uint64_t>({0, 2}, 3);
  154. t->SetItemAt<uint64_t>({1, 0}, 4);
  155. t->SetItemAt<uint64_t>({1, 1}, 5);
  156. t->SetItemAt<uint64_t>({1, 2}, 6);
  157. TensorTable tbl;
  158. TensorRow row;
  159. row.push_back(t);
  160. // Cache tensor row t 5000 times using 10 threads.
  161. for (auto k = 0; k < 10; ++k) {
  162. Status vg_rc = vg.CreateAsyncTask("Test agent", [&myClient, &row]() -> Status {
  163. TaskManager::FindMe()->Post();
  164. for (auto i = 0; i < 500; i++) {
  165. RETURN_IF_NOT_OK(myClient->WriteRow(row));
  166. }
  167. return Status::OK();
  168. });
  169. ASSERT_TRUE(vg_rc.IsOk());
  170. }
  171. ASSERT_TRUE(vg.join_all().IsOk());
  172. ASSERT_TRUE(vg.GetTaskErrorIfAny().IsOk());
  173. rc = myClient->BuildPhaseDone();
  174. ASSERT_TRUE(rc.IsOk());
  175. // Get statistics from the server.
  176. CacheServiceStat stat{};
  177. rc = myClient->GetStat(&stat);
  178. ASSERT_TRUE(rc.IsOk());
  179. std::cout << stat.min_row_id << ":" << stat.max_row_id << ":" << stat.num_mem_cached << ":" << stat.num_disk_cached
  180. << "\n";
  181. // Expect there are 5000 rows there.
  182. EXPECT_EQ(5000, stat.max_row_id - stat.min_row_id + 1);
  183. // Get them all back using row id and compare with tensor t.
  184. for (auto i = stat.min_row_id; i <= stat.max_row_id; ++i) {
  185. tbl.clear();
  186. row.clear();
  187. rc = myClient->GetRows({i}, &tbl);
  188. ASSERT_TRUE(rc.IsOk());
  189. row = tbl.front();
  190. auto r = row.front();
  191. bool cmp = (*t == *r);
  192. ASSERT_TRUE(cmp);
  193. }
  194. rc = myClient->DestroyCache();
  195. ASSERT_TRUE(rc.IsOk());
  196. }
  197. // Simple test with a repeated cache op over random data producer
  198. //
  199. // RepeatOp
  200. // |
  201. // CacheOp
  202. // |
  203. // RandomDataOp
  204. //
  205. TEST_F(MindDataTestCacheOp, DISABLED_TestRandomDataCache1) {
  206. // Clear the rc of the master thread if any
  207. (void)TaskManager::GetMasterThreadRc();
  208. Status rc;
  209. int32_t rank = 0; // not used
  210. session_id_type env_session;
  211. rc = GetSessionFromEnv(&env_session);
  212. ASSERT_TRUE(rc.IsOk());
  213. MS_LOG(INFO) << "UT test TestRandomDataCache1";
  214. // Start with an empty execution tree
  215. auto myTree = std::make_shared<ExecutionTree>();
  216. // Create a schema using the C api's
  217. std::unique_ptr<DataSchema> testSchema = std::make_unique<DataSchema>();
  218. // 2 columns. First column is an "image" 640,480,3
  219. TensorShape c1Shape({640, 480, 3});
  220. ColDescriptor c1("image", DataType(DataType::DE_INT8), TensorImpl::kFlexible,
  221. rank, // not used
  222. &c1Shape);
  223. // Column 2 will just be a scalar label number
  224. TensorShape c2Shape({}); // empty shape is a 1-value scalar Tensor
  225. ColDescriptor c2("label", DataType(DataType::DE_UINT32), TensorImpl::kFlexible, rank, &c2Shape);
  226. testSchema->AddColumn(c1);
  227. testSchema->AddColumn(c2);
  228. // RandomDataOp
  229. std::shared_ptr<RandomDataOp> myRandomDataOp;
  230. rc = RandomDataOp::Builder()
  231. .SetNumWorkers(4)
  232. .SetDataSchema(std::move(testSchema))
  233. .SetTotalRows(50) // 50 samples for now
  234. .Build(&myRandomDataOp);
  235. ASSERT_TRUE(rc.IsOk());
  236. rc = myTree->AssociateNode(myRandomDataOp);
  237. ASSERT_TRUE(rc.IsOk());
  238. // CacheOp
  239. // size of 0, spilling is true
  240. CacheClient::Builder builder;
  241. builder.SetSessionId(env_session).SetCacheMemSz(0).SetSpill(true);
  242. std::shared_ptr<CacheClient> myClient;
  243. rc = builder.Build(&myClient);
  244. ASSERT_TRUE(rc.IsOk());
  245. std::shared_ptr<CacheOp> myCacheOp;
  246. int64_t num_samples = 0;
  247. int64_t start_index = 0;
  248. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  249. rc = CacheOp::Builder()
  250. .SetNumWorkers(5)
  251. .SetClient(myClient)
  252. .SetSampler(std::move(seq_sampler))
  253. .Build(&myCacheOp);
  254. ASSERT_TRUE(rc.IsOk());
  255. rc = myTree->AssociateNode(myCacheOp);
  256. ASSERT_TRUE(rc.IsOk());
  257. // RepeatOp
  258. uint32_t numRepeats = 4;
  259. std::shared_ptr<RepeatOp> myRepeatOp;
  260. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  261. ASSERT_TRUE(rc.IsOk());
  262. rc = myTree->AssociateNode(myRepeatOp);
  263. ASSERT_TRUE(rc.IsOk());
  264. // Assign tree relations and root
  265. myCacheOp->set_total_repeats(numRepeats);
  266. myCacheOp->set_num_repeats_per_epoch(numRepeats);
  267. rc = myRepeatOp->AddChild(myCacheOp);
  268. ASSERT_TRUE(rc.IsOk());
  269. // Always set to 1 under a CacheOp because we read from it only once. The CacheOp is the one that repeats.
  270. myRandomDataOp->set_total_repeats(1);
  271. myRandomDataOp->set_num_repeats_per_epoch(1);
  272. rc = myCacheOp->AddChild(myRandomDataOp);
  273. ASSERT_TRUE(rc.IsOk());
  274. rc = myTree->AssignRoot(myRepeatOp);
  275. ASSERT_TRUE(rc.IsOk());
  276. MS_LOG(INFO) << "Launching tree and begin iteration";
  277. rc = myTree->Prepare();
  278. ASSERT_TRUE(rc.IsOk());
  279. // quick check to see what tree looks like
  280. std::ostringstream ss;
  281. ss << *myTree; // some funny const error if I try to write directly to ms log stream
  282. MS_LOG(INFO) << "Here's the tree:\n" << ss.str();
  283. std::cout << *myClient << std::endl;
  284. rc = myTree->Launch();
  285. ASSERT_TRUE(rc.IsOk());
  286. // Start the loop of reading tensors from our pipeline
  287. DatasetIterator dI(myTree);
  288. TensorRow tensorList;
  289. rc = dI.FetchNextTensorRow(&tensorList);
  290. ASSERT_TRUE(rc.IsOk());
  291. int rowCount = 0;
  292. while (!tensorList.empty()) {
  293. // Don't display these rows, just count them
  294. MS_LOG(INFO) << "Row fetched #: " << rowCount;
  295. rc = dI.FetchNextTensorRow(&tensorList);
  296. ASSERT_TRUE(rc.IsOk());
  297. rowCount++;
  298. }
  299. ASSERT_EQ(rowCount, 200);
  300. rc = myClient->DestroyCache();
  301. ASSERT_TRUE(rc.IsOk());
  302. }
  303. //// Simple test with a repeated cache op over random data producer.
  304. //// This one will exceed memory and require a spill.
  305. ////
  306. //// RepeatOp
  307. //// |
  308. //// CacheOp
  309. //// |
  310. //// RandomDataOp
  311. ////
  312. TEST_F(MindDataTestCacheOp, DISABLED_TestRandomDataCacheSpill) {
  313. // Clear the rc of the master thread if any
  314. (void)TaskManager::GetMasterThreadRc();
  315. Status rc;
  316. int32_t rank = 0; // not used
  317. MS_LOG(INFO) << "UT test TestRandomDataCacheSpill";
  318. session_id_type env_session;
  319. rc = GetSessionFromEnv(&env_session);
  320. ASSERT_TRUE(rc.IsOk());
  321. // Start with an empty execution tree
  322. auto myTree = std::make_shared<ExecutionTree>();
  323. // Create a schema using the C api's
  324. std::unique_ptr<DataSchema> testSchema = std::make_unique<DataSchema>();
  325. // 2 columns. First column is an "image" 640,480,3
  326. TensorShape c1Shape({640, 480, 3});
  327. ColDescriptor c1("image", DataType(DataType::DE_INT8), TensorImpl::kFlexible,
  328. rank, // not used
  329. &c1Shape);
  330. // Column 2 will just be a scalar label number
  331. TensorShape c2Shape({}); // empty shape is a 1-value scalar Tensor
  332. ColDescriptor c2("label", DataType(DataType::DE_UINT32), TensorImpl::kFlexible, rank, &c2Shape);
  333. testSchema->AddColumn(c1);
  334. testSchema->AddColumn(c2);
  335. // RandomDataOp
  336. std::shared_ptr<RandomDataOp> myRandomDataOp;
  337. rc = RandomDataOp::Builder()
  338. .SetNumWorkers(4)
  339. .SetDataSchema(std::move(testSchema))
  340. .SetTotalRows(10)
  341. .Build(&myRandomDataOp);
  342. ASSERT_TRUE(rc.IsOk());
  343. rc = myTree->AssociateNode(myRandomDataOp);
  344. ASSERT_TRUE(rc.IsOk());
  345. // CacheOp
  346. int64_t num_samples = 0;
  347. int64_t start_index = 0;
  348. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  349. CacheClient::Builder builder;
  350. builder.SetSessionId(env_session).SetCacheMemSz(4).SetSpill(true);
  351. std::shared_ptr<CacheClient> myClient;
  352. rc = builder.Build(&myClient);
  353. ASSERT_TRUE(rc.IsOk());
  354. std::shared_ptr<CacheOp> myCacheOp;
  355. rc = CacheOp::Builder()
  356. .SetNumWorkers(4)
  357. .SetClient(myClient)
  358. .SetSampler(std::move(seq_sampler))
  359. .Build(&myCacheOp);
  360. ASSERT_TRUE(rc.IsOk());
  361. rc = myTree->AssociateNode(myCacheOp);
  362. ASSERT_TRUE(rc.IsOk());
  363. // RepeatOp
  364. uint32_t numRepeats = 4;
  365. std::shared_ptr<RepeatOp> myRepeatOp;
  366. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  367. ASSERT_TRUE(rc.IsOk());
  368. rc = myTree->AssociateNode(myRepeatOp);
  369. ASSERT_TRUE(rc.IsOk());
  370. // Assign tree relations and root
  371. myCacheOp->set_total_repeats(numRepeats);
  372. myCacheOp->set_num_repeats_per_epoch(numRepeats);
  373. rc = myRepeatOp->AddChild(myCacheOp);
  374. ASSERT_TRUE(rc.IsOk());
  375. // Always set to 1 under a CacheOp because we read from it only once. The CacheOp is the one that repeats.
  376. myRandomDataOp->set_total_repeats(1);
  377. myRandomDataOp->set_num_repeats_per_epoch(1);
  378. rc = myCacheOp->AddChild(myRandomDataOp);
  379. ASSERT_TRUE(rc.IsOk());
  380. rc = myTree->AssignRoot(myRepeatOp);
  381. ASSERT_TRUE(rc.IsOk());
  382. MS_LOG(INFO) << "Launching tree and begin iteration";
  383. rc = myTree->Prepare();
  384. ASSERT_TRUE(rc.IsOk());
  385. std::cout << *myClient << std::endl;
  386. rc = myTree->Launch();
  387. ASSERT_TRUE(rc.IsOk());
  388. // Start the loop of reading tensors from our pipeline
  389. DatasetIterator dI(myTree);
  390. TensorRow tensorList;
  391. rc = dI.FetchNextTensorRow(&tensorList);
  392. ASSERT_TRUE(rc.IsOk());
  393. int rowCount = 0;
  394. while (!tensorList.empty()) {
  395. // Don't display these rows, just count them
  396. MS_LOG(INFO) << "Row fetched #: " << rowCount;
  397. rc = dI.FetchNextTensorRow(&tensorList);
  398. ASSERT_TRUE(rc.IsOk());
  399. rowCount++;
  400. }
  401. ASSERT_EQ(rowCount, 40);
  402. rc = myClient->DestroyCache();
  403. ASSERT_TRUE(rc.IsOk());
  404. }
  405. TEST_F(MindDataTestCacheOp, DISABLED_TestImageFolderCacheMerge) {
  406. // Clear the rc of the master thread if any
  407. (void)TaskManager::GetMasterThreadRc();
  408. Status rc;
  409. int64_t num_samples = 0;
  410. int64_t start_index = 0;
  411. session_id_type env_session;
  412. rc = GetSessionFromEnv(&env_session);
  413. ASSERT_TRUE(rc.IsOk());
  414. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  415. CacheClient::Builder ccbuilder;
  416. ccbuilder.SetSessionId(env_session).SetCacheMemSz(0).SetSpill(true);
  417. std::shared_ptr<CacheClient> myClient;
  418. rc = ccbuilder.Build(&myClient);
  419. ASSERT_TRUE(rc.IsOk());
  420. std::shared_ptr<CacheLookupOp> myLookupOp;
  421. rc = CacheLookupOp::Builder().SetNumWorkers(4).SetClient(myClient).SetSampler(seq_sampler).Build(&myLookupOp);
  422. std::shared_ptr<CacheMergeOp> myMergeOp;
  423. rc = CacheMergeOp::Builder().SetNumWorkers(4).SetClient(myClient).Build(&myMergeOp);
  424. std::shared_ptr<ImageFolderOp> so;
  425. ImageFolderOp::Builder builder;
  426. builder.SetOpConnectorSize(3)
  427. .SetNumWorkers(3)
  428. .SetExtensions({".jpg", ".JPEG"})
  429. .SetRecursive(true)
  430. .SetImageFolderDir(datasets_root_path_ + "/testPK/data");
  431. rc = builder.Build(&so);
  432. so->SetSampler(myLookupOp);
  433. ASSERT_TRUE(rc.IsOk());
  434. // RepeatOp
  435. uint32_t numRepeats = 4;
  436. std::shared_ptr<RepeatOp> myRepeatOp;
  437. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  438. ASSERT_TRUE(rc.IsOk());
  439. auto myTree = std::make_shared<ExecutionTree>();
  440. rc = myTree->AssociateNode(so);
  441. ASSERT_TRUE(rc.IsOk());
  442. rc = myTree->AssociateNode(myLookupOp);
  443. ASSERT_TRUE(rc.IsOk());
  444. rc = myTree->AssociateNode(myMergeOp);
  445. ASSERT_TRUE(rc.IsOk());
  446. rc = myTree->AssociateNode(myRepeatOp);
  447. ASSERT_TRUE(rc.IsOk());
  448. rc = myTree->AssignRoot(myRepeatOp);
  449. ASSERT_TRUE(rc.IsOk());
  450. myMergeOp->set_total_repeats(numRepeats);
  451. myMergeOp->set_num_repeats_per_epoch(numRepeats);
  452. rc = myRepeatOp->AddChild(myMergeOp);
  453. ASSERT_TRUE(rc.IsOk());
  454. myLookupOp->set_total_repeats(numRepeats);
  455. myLookupOp->set_num_repeats_per_epoch(numRepeats);
  456. rc = myMergeOp->AddChild(myLookupOp);
  457. ASSERT_TRUE(rc.IsOk());
  458. so->set_total_repeats(numRepeats);
  459. so->set_num_repeats_per_epoch(numRepeats);
  460. rc = myMergeOp->AddChild(so);
  461. ASSERT_TRUE(rc.IsOk());
  462. rc = myTree->Prepare();
  463. ASSERT_TRUE(rc.IsOk());
  464. rc = myTree->Launch();
  465. ASSERT_TRUE(rc.IsOk());
  466. // Start the loop of reading tensors from our pipeline
  467. DatasetIterator dI(myTree);
  468. TensorRow tensorList;
  469. rc = dI.FetchNextTensorRow(&tensorList);
  470. ASSERT_TRUE(rc.IsOk());
  471. int rowCount = 0;
  472. while (!tensorList.empty()) {
  473. rc = dI.FetchNextTensorRow(&tensorList);
  474. ASSERT_TRUE(rc.IsOk());
  475. if (rc.IsError()) {
  476. std::cout << rc << std::endl;
  477. break;
  478. }
  479. rowCount++;
  480. }
  481. ASSERT_EQ(rowCount, 176);
  482. std::cout << "Row count : " << rowCount << std::endl;
  483. rc = myClient->DestroyCache();
  484. ASSERT_TRUE(rc.IsOk());
  485. }