2 * Copyright (c) 2019 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 __API_NNFW_API_INTERNAL_H__
18 #define __API_NNFW_API_INTERNAL_H__
21 #include "nnfw_experimental.h"
23 #include <util/GeneralConfigSource.h>
36 } // namespace frontend
49 } // namespace compiler
56 * @brief Enum class to express the session's state
58 * State transition diagram:
73 * | PREPARED | --------+
78 * +--------------+ run |
80 * +-----> | FINISHED_RUN | | | run_async
82 * | +--------------+ |
84 * | await | run_async |
86 * | +--------------+ |
87 * +------ | RUNNING | <-------+
92 INITIALIZED, //< Session is initialized and nothing has done to it
93 MODEL_LOADED, //< Model is loaded
94 PREPARED, //< Prepared(compiled) for execution
95 RUNNING, //< Execution is in progress (only for asynchronous execution)
96 FINISHED_RUN //< Executed at least once
103 NNFW_STATUS load_model_from_file(const char *package_file_path);
104 NNFW_STATUS prepare();
107 NNFW_STATUS run_async();
110 NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer, size_t length);
111 NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
113 NNFW_STATUS input_size(uint32_t *number);
114 NNFW_STATUS output_size(uint32_t *number);
116 NNFW_STATUS set_input_layout(uint32_t index, NNFW_LAYOUT layout);
117 NNFW_STATUS set_output_layout(uint32_t index, NNFW_LAYOUT layout);
119 NNFW_STATUS apply_tensorinfo(uint32_t index, nnfw_tensorinfo ti); // Will be deprecated
120 NNFW_STATUS set_input_tensorinfo(uint32_t index, const nnfw_tensorinfo *ti);
122 NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
123 NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
125 NNFW_STATUS set_available_backends(const char *backends);
126 NNFW_STATUS set_op_backend(const char *op, const char *backend);
132 NNFW_STATUS set_config(const char *key, const char *value);
133 NNFW_STATUS get_config(const char *key, char *value, size_t value_size);
134 NNFW_STATUS load_circle_from_buffer(uint8_t *buffer, size_t size);
140 NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
141 NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
142 NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);
145 onert::ir::Graph *primary_subgraph();
146 bool isStateInitialized();
147 bool isStateModelLoaded();
148 bool isStatePrepared();
149 bool isStateRunning();
150 bool isStateFinishedRun();
151 bool isStatePreparedOrFinishedRun();
154 State _state{State::INITIALIZED};
155 std::shared_ptr<onert::ir::Subgraphs> _subgraphs;
156 std::unique_ptr<onert::compiler::Compiler> _compiler;
157 std::shared_ptr<onert::exec::Execution> _execution;
158 std::shared_ptr<onert::frontend::custom::KernelRegistry> _kernel_registry;
161 #endif // __API_NNFW_API_INTERNAL_H__