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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. .SetRowsPerBuffer(4)
  232. .SetNumWorkers(4)
  233. .SetDataSchema(std::move(testSchema))
  234. .SetTotalRows(50) // 50 samples for now
  235. .Build(&myRandomDataOp);
  236. ASSERT_TRUE(rc.IsOk());
  237. rc = myTree->AssociateNode(myRandomDataOp);
  238. ASSERT_TRUE(rc.IsOk());
  239. // CacheOp
  240. // size of 0, spilling is true
  241. CacheClient::Builder builder;
  242. builder.SetSessionId(env_session).SetCacheMemSz(0).SetSpill(true);
  243. std::shared_ptr<CacheClient> myClient;
  244. rc = builder.Build(&myClient);
  245. ASSERT_TRUE(rc.IsOk());
  246. std::shared_ptr<CacheOp> myCacheOp;
  247. int64_t num_samples = 0;
  248. int64_t start_index = 0;
  249. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  250. rc = CacheOp::Builder()
  251. .SetNumWorkers(5)
  252. .SetClient(myClient)
  253. .SetRowsPerBuffer(4)
  254. .SetSampler(std::move(seq_sampler))
  255. .Build(&myCacheOp);
  256. ASSERT_TRUE(rc.IsOk());
  257. rc = myTree->AssociateNode(myCacheOp);
  258. ASSERT_TRUE(rc.IsOk());
  259. // RepeatOp
  260. uint32_t numRepeats = 4;
  261. std::shared_ptr<RepeatOp> myRepeatOp;
  262. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  263. ASSERT_TRUE(rc.IsOk());
  264. rc = myTree->AssociateNode(myRepeatOp);
  265. ASSERT_TRUE(rc.IsOk());
  266. // Assign tree relations and root
  267. myCacheOp->set_total_repeats(numRepeats);
  268. myCacheOp->set_num_repeats_per_epoch(numRepeats);
  269. rc = myRepeatOp->AddChild(myCacheOp);
  270. ASSERT_TRUE(rc.IsOk());
  271. // Always set to 1 under a CacheOp because we read from it only once. The CacheOp is the one that repeats.
  272. myRandomDataOp->set_total_repeats(1);
  273. myRandomDataOp->set_num_repeats_per_epoch(1);
  274. rc = myCacheOp->AddChild(myRandomDataOp);
  275. ASSERT_TRUE(rc.IsOk());
  276. rc = myTree->AssignRoot(myRepeatOp);
  277. ASSERT_TRUE(rc.IsOk());
  278. MS_LOG(INFO) << "Launching tree and begin iteration";
  279. rc = myTree->Prepare();
  280. ASSERT_TRUE(rc.IsOk());
  281. // quick check to see what tree looks like
  282. std::ostringstream ss;
  283. ss << *myTree; // some funny const error if I try to write directly to ms log stream
  284. MS_LOG(INFO) << "Here's the tree:\n" << ss.str();
  285. std::cout << *myClient << std::endl;
  286. rc = myTree->Launch();
  287. ASSERT_TRUE(rc.IsOk());
  288. // Start the loop of reading tensors from our pipeline
  289. DatasetIterator dI(myTree);
  290. TensorRow tensorList;
  291. rc = dI.FetchNextTensorRow(&tensorList);
  292. ASSERT_TRUE(rc.IsOk());
  293. int rowCount = 0;
  294. while (!tensorList.empty()) {
  295. // Don't display these rows, just count them
  296. MS_LOG(INFO) << "Row fetched #: " << rowCount;
  297. rc = dI.FetchNextTensorRow(&tensorList);
  298. ASSERT_TRUE(rc.IsOk());
  299. rowCount++;
  300. }
  301. ASSERT_EQ(rowCount, 200);
  302. rc = myClient->DestroyCache();
  303. ASSERT_TRUE(rc.IsOk());
  304. }
  305. //// Simple test with a repeated cache op over random data producer.
  306. //// This one will exceed memory and require a spill.
  307. ////
  308. //// RepeatOp
  309. //// |
  310. //// CacheOp
  311. //// |
  312. //// RandomDataOp
  313. ////
  314. TEST_F(MindDataTestCacheOp, DISABLED_TestRandomDataCacheSpill) {
  315. // Clear the rc of the master thread if any
  316. (void)TaskManager::GetMasterThreadRc();
  317. Status rc;
  318. int32_t rank = 0; // not used
  319. MS_LOG(INFO) << "UT test TestRandomDataCacheSpill";
  320. session_id_type env_session;
  321. rc = GetSessionFromEnv(&env_session);
  322. ASSERT_TRUE(rc.IsOk());
  323. // Start with an empty execution tree
  324. auto myTree = std::make_shared<ExecutionTree>();
  325. // Create a schema using the C api's
  326. std::unique_ptr<DataSchema> testSchema = std::make_unique<DataSchema>();
  327. // 2 columns. First column is an "image" 640,480,3
  328. TensorShape c1Shape({640, 480, 3});
  329. ColDescriptor c1("image", DataType(DataType::DE_INT8), TensorImpl::kFlexible,
  330. rank, // not used
  331. &c1Shape);
  332. // Column 2 will just be a scalar label number
  333. TensorShape c2Shape({}); // empty shape is a 1-value scalar Tensor
  334. ColDescriptor c2("label", DataType(DataType::DE_UINT32), TensorImpl::kFlexible, rank, &c2Shape);
  335. testSchema->AddColumn(c1);
  336. testSchema->AddColumn(c2);
  337. // RandomDataOp
  338. std::shared_ptr<RandomDataOp> myRandomDataOp;
  339. rc = RandomDataOp::Builder()
  340. .SetRowsPerBuffer(2)
  341. .SetNumWorkers(4)
  342. .SetDataSchema(std::move(testSchema))
  343. .SetTotalRows(10)
  344. .Build(&myRandomDataOp);
  345. ASSERT_TRUE(rc.IsOk());
  346. rc = myTree->AssociateNode(myRandomDataOp);
  347. ASSERT_TRUE(rc.IsOk());
  348. // CacheOp
  349. int64_t num_samples = 0;
  350. int64_t start_index = 0;
  351. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  352. CacheClient::Builder builder;
  353. builder.SetSessionId(env_session).SetCacheMemSz(4).SetSpill(true);
  354. std::shared_ptr<CacheClient> myClient;
  355. rc = builder.Build(&myClient);
  356. ASSERT_TRUE(rc.IsOk());
  357. std::shared_ptr<CacheOp> myCacheOp;
  358. rc = CacheOp::Builder()
  359. .SetNumWorkers(4)
  360. .SetClient(myClient)
  361. .SetRowsPerBuffer(3)
  362. .SetSampler(std::move(seq_sampler))
  363. .Build(&myCacheOp);
  364. ASSERT_TRUE(rc.IsOk());
  365. rc = myTree->AssociateNode(myCacheOp);
  366. ASSERT_TRUE(rc.IsOk());
  367. // RepeatOp
  368. uint32_t numRepeats = 4;
  369. std::shared_ptr<RepeatOp> myRepeatOp;
  370. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  371. ASSERT_TRUE(rc.IsOk());
  372. rc = myTree->AssociateNode(myRepeatOp);
  373. ASSERT_TRUE(rc.IsOk());
  374. // Assign tree relations and root
  375. myCacheOp->set_total_repeats(numRepeats);
  376. myCacheOp->set_num_repeats_per_epoch(numRepeats);
  377. rc = myRepeatOp->AddChild(myCacheOp);
  378. ASSERT_TRUE(rc.IsOk());
  379. // Always set to 1 under a CacheOp because we read from it only once. The CacheOp is the one that repeats.
  380. myRandomDataOp->set_total_repeats(1);
  381. myRandomDataOp->set_num_repeats_per_epoch(1);
  382. rc = myCacheOp->AddChild(myRandomDataOp);
  383. ASSERT_TRUE(rc.IsOk());
  384. rc = myTree->AssignRoot(myRepeatOp);
  385. ASSERT_TRUE(rc.IsOk());
  386. MS_LOG(INFO) << "Launching tree and begin iteration";
  387. rc = myTree->Prepare();
  388. ASSERT_TRUE(rc.IsOk());
  389. std::cout << *myClient << std::endl;
  390. rc = myTree->Launch();
  391. ASSERT_TRUE(rc.IsOk());
  392. // Start the loop of reading tensors from our pipeline
  393. DatasetIterator dI(myTree);
  394. TensorRow tensorList;
  395. rc = dI.FetchNextTensorRow(&tensorList);
  396. ASSERT_TRUE(rc.IsOk());
  397. int rowCount = 0;
  398. while (!tensorList.empty()) {
  399. // Don't display these rows, just count them
  400. MS_LOG(INFO) << "Row fetched #: " << rowCount;
  401. rc = dI.FetchNextTensorRow(&tensorList);
  402. ASSERT_TRUE(rc.IsOk());
  403. rowCount++;
  404. }
  405. ASSERT_EQ(rowCount, 40);
  406. rc = myClient->DestroyCache();
  407. ASSERT_TRUE(rc.IsOk());
  408. }
  409. TEST_F(MindDataTestCacheOp, DISABLED_TestImageFolderCacheMerge) {
  410. // Clear the rc of the master thread if any
  411. (void)TaskManager::GetMasterThreadRc();
  412. Status rc;
  413. int64_t num_samples = 0;
  414. int64_t start_index = 0;
  415. session_id_type env_session;
  416. rc = GetSessionFromEnv(&env_session);
  417. ASSERT_TRUE(rc.IsOk());
  418. auto seq_sampler = std::make_shared<SequentialSamplerRT>(num_samples, start_index);
  419. CacheClient::Builder ccbuilder;
  420. ccbuilder.SetSessionId(env_session).SetCacheMemSz(0).SetSpill(true);
  421. std::shared_ptr<CacheClient> myClient;
  422. rc = ccbuilder.Build(&myClient);
  423. ASSERT_TRUE(rc.IsOk());
  424. std::shared_ptr<CacheLookupOp> myLookupOp;
  425. rc = CacheLookupOp::Builder().SetNumWorkers(4).SetClient(myClient).SetSampler(seq_sampler).Build(&myLookupOp);
  426. std::shared_ptr<CacheMergeOp> myMergeOp;
  427. rc = CacheMergeOp::Builder().SetNumWorkers(4).SetClient(myClient).Build(&myMergeOp);
  428. std::shared_ptr<ImageFolderOp> so;
  429. ImageFolderOp::Builder builder;
  430. builder.SetOpConnectorSize(3)
  431. .SetNumWorkers(3)
  432. .SetRowsPerBuffer(2)
  433. .SetExtensions({".jpg", ".JPEG"})
  434. .SetRecursive(true)
  435. .SetImageFolderDir(datasets_root_path_ + "/testPK/data");
  436. rc = builder.Build(&so);
  437. so->SetSampler(myLookupOp);
  438. ASSERT_TRUE(rc.IsOk());
  439. // RepeatOp
  440. uint32_t numRepeats = 4;
  441. std::shared_ptr<RepeatOp> myRepeatOp;
  442. rc = RepeatOp::Builder(numRepeats).Build(&myRepeatOp);
  443. ASSERT_TRUE(rc.IsOk());
  444. auto myTree = std::make_shared<ExecutionTree>();
  445. rc = myTree->AssociateNode(so);
  446. ASSERT_TRUE(rc.IsOk());
  447. rc = myTree->AssociateNode(myLookupOp);
  448. ASSERT_TRUE(rc.IsOk());
  449. rc = myTree->AssociateNode(myMergeOp);
  450. ASSERT_TRUE(rc.IsOk());
  451. rc = myTree->AssociateNode(myRepeatOp);
  452. ASSERT_TRUE(rc.IsOk());
  453. rc = myTree->AssignRoot(myRepeatOp);
  454. ASSERT_TRUE(rc.IsOk());
  455. myMergeOp->set_total_repeats(numRepeats);
  456. myMergeOp->set_num_repeats_per_epoch(numRepeats);
  457. rc = myRepeatOp->AddChild(myMergeOp);
  458. ASSERT_TRUE(rc.IsOk());
  459. myLookupOp->set_total_repeats(numRepeats);
  460. myLookupOp->set_num_repeats_per_epoch(numRepeats);
  461. rc = myMergeOp->AddChild(myLookupOp);
  462. ASSERT_TRUE(rc.IsOk());
  463. so->set_total_repeats(numRepeats);
  464. so->set_num_repeats_per_epoch(numRepeats);
  465. rc = myMergeOp->AddChild(so);
  466. ASSERT_TRUE(rc.IsOk());
  467. rc = myTree->Prepare();
  468. ASSERT_TRUE(rc.IsOk());
  469. rc = myTree->Launch();
  470. ASSERT_TRUE(rc.IsOk());
  471. // Start the loop of reading tensors from our pipeline
  472. DatasetIterator dI(myTree);
  473. TensorRow tensorList;
  474. rc = dI.FetchNextTensorRow(&tensorList);
  475. ASSERT_TRUE(rc.IsOk());
  476. int rowCount = 0;
  477. while (!tensorList.empty()) {
  478. rc = dI.FetchNextTensorRow(&tensorList);
  479. ASSERT_TRUE(rc.IsOk());
  480. if (rc.IsError()) {
  481. std::cout << rc << std::endl;
  482. break;
  483. }
  484. rowCount++;
  485. }
  486. ASSERT_EQ(rowCount, 176);
  487. std::cout << "Row count : " << rowCount << std::endl;
  488. rc = myClient->DestroyCache();
  489. ASSERT_TRUE(rc.IsOk());
  490. }