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.

skip_op.h 3.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_SKIP_OP_H_
  17. #define DATASET_ENGINE_DATASETOPS_SKIP_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 SkipOp : public PipelineOp {
  25. public:
  26. class Builder {
  27. public:
  28. // Builder constructor. Creates the builder object.
  29. // @note No default args
  30. // @param count - The number of skip to do
  31. // @return This is a constructor.
  32. explicit Builder(int32_t count);
  33. // Default destructor
  34. ~Builder() = default;
  35. // The builder "build" method creates the final object.
  36. // @return shared_ptr to the new StorageOp object
  37. Status Build(std::shared_ptr<SkipOp> *);
  38. private:
  39. int32_t build_max_skips_;
  40. Status SanityCheck() const;
  41. };
  42. // Constructor of the SkipOp.
  43. // @note The builder class should be used to call it
  44. // @param count - The number of skips to do
  45. explicit SkipOp(int32_t count);
  46. // Destructor
  47. ~SkipOp();
  48. // A print method typically used for debugging
  49. // @param out - The output stream to write output to
  50. // @param show_all - A bool to control if you want to show all info or just a summary
  51. void Print(std::ostream &out, bool show_all) const override;
  52. // Class functor operator () override.
  53. // Most dataset ops operate by launching a thread (see ExecutionTree).
  54. // However, the SkipOp is defined as a inlined operator, so it is invalid to launch the
  55. // functor since this op runs inlined inside another operator. The function is overloaded to
  56. // ensure that it is not called by mistake (it will generate an error).
  57. // @return Status - The error code return
  58. Status operator()() override;
  59. // This function returns the buffer that is at the top of our output connector. The caller is
  60. // typically our parent node, when the parent is asking us to provide the next buffer of data.
  61. // Since SkipOp is an inlined op, getting a buffer from us will simply bounce you to get
  62. // a buffer from our child.
  63. // @param p_buffer - output pointer to the buffer that it will fetch.
  64. // @param worker_id - The worker id
  65. // @param retry_if_eoe Set this flag to true to allow calling pop() again after the first pop() returns EOE.
  66. // @return Status - The error code return
  67. Status GetNextBuffer(std::unique_ptr<DataBuffer> *p_buffer, int32_t worker_id, bool retry_if_eoe) override;
  68. // Base-class override for handling cases when an eoe is received.
  69. // @param worker_id - The worker id
  70. Status EoeReceived(int32_t worker_id) override;
  71. // Base-class override for handling cases when an eof is received.
  72. // @param worker_id - The worker id
  73. Status EofReceived(int32_t worker_id) override;
  74. private:
  75. int32_t max_skips_; // The number of skips that the user requested
  76. int32_t skip_count_; // A counter for the current number of executed skips
  77. };
  78. } // namespace dataset
  79. } // namespace mindspore
  80. #endif // DATASET_ENGINE_DATASETOPS_SKIP_OP_H_