ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Interpreter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
17#ifndef LUCI_INTERPRETER_INTERPRETER_H
18#define LUCI_INTERPRETER_INTERPRETER_H
19
20#include "luci_interpreter/core/Tensor.h"
21
24
26#include <luci/IR/Module.h>
27
28#include <memory>
29#include <vector>
30#include <unordered_map>
31
32namespace luci_interpreter
33{
34
36{
37public:
39
40 // Called when the value of a tensor has been updated during execution.
41 virtual void postTensorWrite(const luci::CircleNode *node, const Tensor *tensor);
42
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);
48};
49
51{
52public:
53 explicit Interpreter(const luci::Module *module);
54
55 explicit Interpreter(const luci::Module *module, IMemoryManager *memory_manager);
56
58
59 void writeInputTensor(const luci::CircleInput *input_node, const void *data, size_t data_size);
60
61 void readOutputTensor(const luci::CircleOutput *output_node, void *data, size_t data_size);
62
64
65 void interpret();
66
67 void attachObserver(ExecutionObserver *observer);
68
69 const Tensor *getTensor(const loco::Node *node) { return _node_to_tensor[node]; }
70
71private:
72 // _default_memory_manager should be before _runtime_module due to
73 // the order of deletion in the destructor
74 std::unique_ptr<IMemoryManager> _default_memory_manager = nullptr;
75 std::unique_ptr<class RuntimeModule> _runtime_module;
76
77 // Observer functionality support.
78 std::unique_ptr<struct RuntimeToIR> _runtime_to_ir;
79 std::unordered_map<const loco::Node *, Tensor *> _node_to_tensor;
80 std::unique_ptr<class EventNotifier> _event_notifier;
81 std::vector<ExecutionObserver *> _observers;
82};
83
84} // namespace luci_interpreter
85
86#endif // LUCI_INTERPRETER_INTERPRETER_H
Logical unit of computation.
Definition Node.h:54
CircleNode used for Input of the Graph.
Definition CircleInput.h:36
CircleNode for Output of the Graph.
Collection of 'loco::Graph's.
Definition Module.h:33
virtual void postOperatorExecute(const luci::CircleNode *node)
virtual void preOperatorExecute(const luci::CircleNode *node)
virtual void postTensorWrite(const luci::CircleNode *node, const Tensor *tensor)
const Tensor * getTensor(const loco::Node *node)
Definition Interpreter.h:69
void attachObserver(ExecutionObserver *observer)
size_t getOutputTensorSize(const luci::CircleOutput *output_node)
void writeInputTensor(const luci::CircleInput *input_node, const void *data, size_t data_size)
void readOutputTensor(const luci::CircleOutput *output_node, void *data, size_t data_size)
const T * data(const std::vector< T, Alloc > &v)
CircleOutput * output_node(loco::Graph *g, const loco::GraphOutputIndex &index)
Find a CircleOutput node with a given output index.
CircleInput * input_node(loco::Graph *g, const loco::GraphInputIndex &index)
Find a Pull node with a given input index.