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/TracingCtx.h>
34 class CustomKernelRegistry;
48 struct CompilerArtifact;
49 class CompilerOptions;
50 } // namespace compiler
57 * @brief Enum class to express the session's state
59 * State transition diagram:
74 * | PREPARED | --------+
79 * +--------------+ run |
81 * +-----> | FINISHED_RUN | | | run_async
83 * | +--------------+ |
85 * | await | run_async |
87 * | +--------------+ |
88 * +------ | RUNNING | <-------+
93 INITIALIZED, //< Session is initialized and nothing has done to it
94 MODEL_LOADED, //< Model is loaded
95 PREPARED, //< Prepared(compiled) for execution
96 RUNNING, //< Execution is in progress (only for asynchronous execution)
97 FINISHED_RUN //< Executed at least once
102 * @brief Factory method. It creates and initialize nnfw_session
104 * @note Use factory instead of constructor to get status
106 static NNFW_STATUS create(nnfw_session **session);
113 NNFW_STATUS load_model_from_nnpackage(const char *package_file_path);
114 NNFW_STATUS prepare();
115 NNFW_STATUS prepare_pipeline(const char *map_file_path);
118 NNFW_STATUS run_async();
121 NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer, size_t length);
122 NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
124 NNFW_STATUS input_size(uint32_t *number);
125 NNFW_STATUS output_size(uint32_t *number);
127 NNFW_STATUS set_input_layout(uint32_t index, NNFW_LAYOUT layout);
128 NNFW_STATUS set_output_layout(uint32_t index, NNFW_LAYOUT layout);
130 NNFW_STATUS apply_tensorinfo(uint32_t index, nnfw_tensorinfo ti); // Will be deprecated
131 NNFW_STATUS set_input_tensorinfo(uint32_t index, const nnfw_tensorinfo *ti);
133 NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
134 NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
136 NNFW_STATUS set_available_backends(const char *backends);
137 NNFW_STATUS set_op_backend(const char *op, const char *backend);
143 NNFW_STATUS set_config(const char *key, const char *value);
144 NNFW_STATUS get_config(const char *key, char *value, size_t value_size);
145 NNFW_STATUS load_circle_from_buffer(uint8_t *buffer, size_t size);
146 NNFW_STATUS load_model_from_modelfile(const char *file_path);
151 NNFW_STATUS push_pipeline_input(std::vector<void *> *inputs, std::vector<uint32_t> *lengths);
152 NNFW_STATUS pop_pipeline_output(std::vector<void *> *outputs);
154 NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
155 NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
156 NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);
158 * @brief Set backends with string-encoded mapping from operation index to backend type
161 NNFW_STATUS set_backends_per_operation(const char *backend_settings);
164 const onert::ir::Graph *primary_subgraph();
165 uint32_t getInputSize();
166 uint32_t getOutputSize();
168 bool isStateInitialized();
169 bool isStateModelLoaded();
170 bool isStatePrepared();
171 bool isStateRunning();
172 bool isStateFinishedRun();
173 bool isStatePreparedOrFinishedRun();
176 State _state{State::INITIALIZED};
177 std::shared_ptr<onert::ir::NNPkg> _nnpkg;
178 std::vector<std::unique_ptr<onert::compiler::CompilerOptions>> _coptions;
179 std::shared_ptr<onert::compiler::CompilerArtifact> _compiler_artifact;
180 std::unique_ptr<onert::exec::Execution> _execution;
181 std::shared_ptr<onert::api::CustomKernelRegistry> _kernel_registry;
182 std::vector<std::thread> _threads;
185 #endif // __API_NNFW_API_INTERNAL_H__