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.

pipeline_op.h 3.9 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef DATASET_ENGINE_DATASETOPS_PIPELINE_OP_H_
  17. #define DATASET_ENGINE_DATASETOPS_PIPELINE_OP_H_
  18. #include <memory>
  19. #include <vector>
  20. #include "dataset/engine/datasetops/dataset_op.h"
  21. namespace mindspore {
  22. namespace dataset {
  23. // forward declare
  24. class ExecutionTree;
  25. class DataBuffer;
  26. class PipelineOp : public DatasetOp {
  27. public:
  28. // Constructor
  29. // @param op_connector_size - size of the output connector
  30. // @return Builder setter method returns reference to the builder.
  31. // @param sampler - The sampler for the op
  32. explicit PipelineOp(int32_t op_connector_size, std::shared_ptr<Sampler> sampler = nullptr);
  33. // Destructor
  34. ~PipelineOp() = default;
  35. // A print method typically used for debugging
  36. // @param out - The output stream to write output to
  37. // @param show_all - A bool to control if you want to show all info or just a summary
  38. void Print(std::ostream &out, bool show_all) const override;
  39. // << Stream output operator overload
  40. // @notes This allows you to write the debug print info using stream operators
  41. // @param out - reference to the output stream being overloaded
  42. // @param po - reference to the PipelineOp to display
  43. // @return - the output stream must be returned
  44. friend std::ostream &operator<<(std::ostream &out, const PipelineOp &po) {
  45. po.Print(out, false);
  46. return out;
  47. }
  48. // Getter
  49. // @return The number of workers inside this op. Pipeline ops only have a single worker.
  50. int32_t num_workers() const override { return 1; }
  51. // Getter
  52. // @return the number of threads consuming from the previous Connector
  53. int32_t num_consumers() const override { return 1; }
  54. // Getter
  55. // @return The number of threads that push data to the output connector
  56. int32_t num_producers() const override { return 1; }
  57. // During tree prepare phase, operators may have specific pre-operations to perform depending on
  58. // their role.
  59. // @notes Derived versions of this function should always call it's superclass version first
  60. // before providing their own implementations.
  61. Status PrepareNodePreAction() override {
  62. // Run common code from super class before adding PipelineOp specific logic
  63. return (DatasetOp::PrepareNodePreAction());
  64. }
  65. // During tree prepare phase, operators may have specific post-operations to perform depending on
  66. // their role.
  67. // @notes Derived versions of this function should always call it's superclass version first
  68. // before providing their own implementations.
  69. Status PrepareNodePostAction() override {
  70. // Run common code from super class before adding PipelineOp specific logic
  71. return (DatasetOp::PrepareNodePostAction());
  72. }
  73. protected:
  74. // *******************************************************************************
  75. // I'm predicting there will be common arguments or functionality for pipeline ops,
  76. // just not sure yet what those are. perhaps this intermediate class between
  77. // DatasetOp and the actual ops is not needed at all?
  78. // For example, if there's no common code for all of the non-parallel ops, then
  79. // they can just inherit from DatasetOp directly and we can put this class into the
  80. // trash.
  81. };
  82. } // namespace dataset
  83. } // namespace mindspore
  84. #endif // DATASET_ENGINE_DATASETOPS_PIPELINE_OP_H_