2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef LUCI_INTERPRETER_INTERPRETER_H
18 #define LUCI_INTERPRETER_INTERPRETER_H
20 #include "luci_interpreter/core/Tensor.h"
22 #include <luci/IR/Nodes/CircleInput.h>
23 #include <luci/IR/Nodes/CircleOutput.h>
25 #include "luci_interpreter/MemoryManager.h"
26 #include <luci/IR/Module.h>
30 #include <unordered_map>
32 namespace luci_interpreter
35 class ExecutionObserver
38 virtual ~ExecutionObserver();
40 // Called when the value of a tensor has been updated during execution.
41 virtual void postTensorWrite(const luci::CircleNode *node, const Tensor *tensor);
43 // Called before / after executing an operator.
44 // Note that these methods are not called for auxiliary operators (CircleInput, CircleOutput,
45 // CircleConst and Circle*Out).
46 virtual void preOperatorExecute(const luci::CircleNode *node);
47 virtual void postOperatorExecute(const luci::CircleNode *node);
53 explicit Interpreter(const luci::Module *module, IMemoryManager *memory_manager = nullptr);
57 void writeInputTensor(const luci::CircleInput *input_node, const void *data, size_t data_size);
59 void readOutputTensor(const luci::CircleOutput *output_node, void *data, size_t data_size);
63 void attachObserver(ExecutionObserver *observer);
65 const Tensor *getTensor(const loco::Node *node) { return _node_to_tensor[node]; }
68 // _default_memory_manager should be before _runtime_module due to
69 // the order of deletion in the destructor
70 std::unique_ptr<IMemoryManager> _default_memory_manager = nullptr;
71 std::unique_ptr<class RuntimeModule> _runtime_module;
72 IMemoryManager *_memory_manager = nullptr;
74 // Observer functionality support.
75 std::unique_ptr<struct RuntimeToIR> _runtime_to_ir;
76 std::unordered_map<const loco::Node *, Tensor *> _node_to_tensor;
77 std::unique_ptr<class EventNotifier> _event_notifier;
78 std::vector<ExecutionObserver *> _observers;
81 } // namespace luci_interpreter
83 #endif // LUCI_INTERPRETER_INTERPRETER_H