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