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.2 kB

6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 SkipOp object
  37. Status Build(std::shared_ptr<SkipOp> *);
  38. private:
  39. int32_t build_max_skips_;
  40. int32_t builder_op_connector_size_;
  41. Status SanityCheck() const;
  42. };
  43. // Constructor of the SkipOp.
  44. // @note The builder class should be used to call it
  45. // @param count - The number of skips to do
  46. explicit SkipOp(int32_t count, int32_t op_connector_size);
  47. // Destructor
  48. ~SkipOp();
  49. // A print method typically used for debugging
  50. // @param out - The output stream to write output to
  51. // @param show_all - A bool to control if you want to show all info or just a summary
  52. void Print(std::ostream &out, bool show_all) const override;
  53. // Class functor operator () override.
  54. // All dataset ops operate by launching a thread (see ExecutionTree). This class functor will
  55. // provide the master loop that drives the logic for performing the work
  56. // @return Status - The error code return
  57. Status operator()() override;
  58. // Base-class override for handling cases when an eoe is received.
  59. // @param worker_id - The worker id
  60. Status EoeReceived(int32_t worker_id) override;
  61. // Base-class override for handling cases when an eof is received.
  62. // @param worker_id - The worker id
  63. Status EofReceived(int32_t worker_id) override;
  64. // Base-class override for NodePass visitor acceptor.
  65. // @param p - Pointer to the NodePass to be accepted.
  66. // @param modified - Whether this node visit modified the pipeline.
  67. // @return - Status of the node visit.
  68. Status Accept(NodePass *p, bool *modified) override;
  69. // Op name getter
  70. // @return Name of the current Op
  71. std::string Name() const override { return "SkipOp"; }
  72. private:
  73. int32_t max_skips_; // The number of skips that the user requested
  74. int32_t skip_count_; // A counter for the current number of executed skips
  75. };
  76. } // namespace dataset
  77. } // namespace mindspore
  78. #endif // DATASET_ENGINE_DATASETOPS_SKIP_OP_H_