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