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.

take_op.h 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef DATASET_ENGINE_DATASETOPS_TAKE_OP_H_
  17. #define DATASET_ENGINE_DATASETOPS_TAKE_OP_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "dataset/engine/datasetops/pipeline_op.h"
  22. namespace mindspore {
  23. namespace dataset {
  24. class TakeOp : public PipelineOp {
  25. public:
  26. // The nested builder class inside of the TakeOp is used to help manage all of the arguments
  27. // for constructing it. This take op is very simple though, so this builder is really just
  28. // provided for a consistent look and feel for creators of Dataset operators overall.
  29. class Builder {
  30. public:
  31. // Builder constructor. Creates the builder object.
  32. // @note No default args
  33. // @param count - The number of takes to do
  34. // @return This is a constructor.
  35. explicit Builder(int32_t count);
  36. // Default destructor
  37. ~Builder() = default;
  38. // The builder "build" method creates the final object.
  39. // @return shared_ptr to the new TakeOp object
  40. Status Build(std::shared_ptr<TakeOp> *);
  41. private:
  42. int32_t build_max_takes_;
  43. int32_t builder_op_connector_size_;
  44. Status SanityCheck() const;
  45. };
  46. // Constructor of the TakeOp.
  47. // @note The builder class should be used to call it
  48. // @param count - The number of takes to do
  49. explicit TakeOp(int32_t count, int32_t op_connector_size);
  50. // Destructor
  51. ~TakeOp() = default;
  52. // A print method typically used for debugging
  53. // @param out - The output stream to write output to
  54. // @param show_all - A bool to control if you want to show all info or just a summary
  55. void Print(std::ostream &out, bool show_all) const override;
  56. // << Stream output operator overload
  57. // @notes This allows you to write the debug print info using stream operators
  58. // @param out - reference to the output stream being overloaded
  59. // @param ro - reference to the TakeOp to display
  60. // @return - the output stream must be returned
  61. friend std::ostream &operator<<(std::ostream &out, const TakeOp &ro) {
  62. ro.Print(out, false);
  63. return out;
  64. }
  65. // All dataset ops operate by launching a thread (see ExecutionTree). This class functor will
  66. // provide the master loop that drives the logic for performing the work
  67. // @return Status - The error code return
  68. Status operator()() override;
  69. // During tree prepare phase, operators may have specific post-operations to perform depending on
  70. // their role.
  71. // @notes Derived versions of this function should always call it's superclass version first
  72. // before providing their own implementations.
  73. Status PrepareNodePostAction() override;
  74. // Base-class override for NodePass visitor acceptor.
  75. // @param p - Pointer to the NodePass to be accepted.
  76. // @param modified - Whether this node visit modified the pipeline.
  77. // @return - Status of the node visit.
  78. Status Accept(NodePass *p, bool *modified) override;
  79. // Op name getter
  80. // @return Name of the current Op
  81. std::string Name() const override { return "TakeOp"; }
  82. private:
  83. int32_t max_takes_; // The number of takes that the user requested
  84. int32_t take_count_; // A counter for the current number of executed takes
  85. Status FillBuffer(std::unique_ptr<DataBuffer> *buffer, std::unique_ptr<DataBuffer> *data_buffer);
  86. };
  87. } // namespace dataset
  88. } // namespace mindspore
  89. #endif // DATASET_ENGINE_DATASETOPS_TAKE_OP_H_