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.

runtime_context.h 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_RUNTIME_CONTEXT_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_RUNTIME_CONTEXT_H_
  18. #include <memory>
  19. #include <utility>
  20. #include "minddata/dataset/core/client.h"
  21. #include "minddata/dataset/engine/consumers/tree_consumer.h"
  22. namespace mindspore::dataset {
  23. class TreeConsumer;
  24. /// Class that represents single runtime instance which can consume data from a data pipeline
  25. class RuntimeContext {
  26. public:
  27. /// Default constructor
  28. RuntimeContext() = default;
  29. /// Initialize the runtime, for now we just call the global init
  30. /// \return Status error code
  31. Status Init();
  32. /// Set the tree consumer
  33. /// \param tree_consumer to be assigned
  34. void AssignConsumer(std::shared_ptr<TreeConsumer> tree_consumer);
  35. /// Get the tree consumer
  36. /// \return Raw pointer to the tree consumer.
  37. TreeConsumer *GetConsumer();
  38. /// Method to terminate the runtime, this will not release the resources
  39. /// \return Status error code
  40. virtual Status Terminate() = 0;
  41. virtual ~RuntimeContext() = default;
  42. protected:
  43. std::shared_ptr<TreeConsumer> tree_consumer_;
  44. };
  45. /// Class that represents C++ single runtime instance which can consume data from a data pipeline
  46. class NativeRuntimeContext : public RuntimeContext {
  47. public:
  48. /// Method to terminate the runtime, this will not release the resources
  49. /// \return Status error code
  50. Status Terminate() override;
  51. ~NativeRuntimeContext() override;
  52. private:
  53. /// Internal function to perform the termination
  54. /// \return Status error code
  55. Status TerminateImpl();
  56. };
  57. } // namespace mindspore::dataset
  58. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_RUNTIME_CONTEXT_H_