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.

iterator.cc 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright 2020 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 "minddata/dataset/include/iterator.h"
  17. #include "minddata/dataset/core/client.h"
  18. #include "minddata/dataset/engine/consumers/tree_consumer.h"
  19. #include "minddata/dataset/include/datasets.h"
  20. namespace mindspore {
  21. namespace dataset {
  22. // Get the next row from the data pipeline.
  23. bool Iterator::GetNextRow(TensorMap *row) {
  24. Status rc = consumer_->GetNextAsMap(row);
  25. if (rc.IsError()) {
  26. MS_LOG(ERROR) << "GetNextRow: Failed to get next row. Error status: " << rc;
  27. row->clear();
  28. return false;
  29. }
  30. return true;
  31. }
  32. // Get the next row from the data pipeline.
  33. bool Iterator::GetNextRow(TensorVec *row) {
  34. Status rc = consumer_->GetNextAsVector(row);
  35. if (rc.IsError()) {
  36. MS_LOG(ERROR) << "GetNextRow: Failed to get next row. Error status: " << rc;
  37. row->clear();
  38. return false;
  39. }
  40. return true;
  41. }
  42. // Shut down the data pipeline.
  43. void Iterator::Stop() {
  44. Status rc = runtime_context_->Terminate();
  45. if (rc.IsError()) {
  46. MS_LOG(ERROR) << rc.ToString();
  47. }
  48. }
  49. // Function to build and launch the execution tree.
  50. Status Iterator::BuildAndLaunchTree(std::shared_ptr<Dataset> ds) {
  51. runtime_context_ = std::make_unique<NativeRuntimeContext>();
  52. RETURN_IF_NOT_OK(runtime_context_->Init());
  53. auto consumer = std::make_unique<IteratorConsumer>();
  54. consumer_ = consumer.get();
  55. RETURN_IF_NOT_OK(consumer->Init(ds->IRNode()));
  56. runtime_context_->AssignConsumer(std::move(consumer));
  57. return Status::OK();
  58. }
  59. } // namespace dataset
  60. } // namespace mindspore