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>
24 #include <util/TracingCtx.h>
37 } // namespace frontend
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
104 NNFW_STATUS load_model_from_nnpackage(const char *package_file_path);
105 NNFW_STATUS prepare();
108 NNFW_STATUS run_async();
111 NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer, size_t length);
112 NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
114 NNFW_STATUS input_size(uint32_t *number);
115 NNFW_STATUS output_size(uint32_t *number);
117 NNFW_STATUS set_input_layout(uint32_t index, NNFW_LAYOUT layout);
118 NNFW_STATUS set_output_layout(uint32_t index, NNFW_LAYOUT layout);
120 NNFW_STATUS apply_tensorinfo(uint32_t index, nnfw_tensorinfo ti); // Will be deprecated
121 NNFW_STATUS set_input_tensorinfo(uint32_t index, const nnfw_tensorinfo *ti);
123 NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
124 NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
126 NNFW_STATUS set_available_backends(const char *backends);
127 NNFW_STATUS set_op_backend(const char *op, const char *backend);
133 NNFW_STATUS set_config(const char *key, const char *value);
134 NNFW_STATUS get_config(const char *key, char *value, size_t value_size);
135 NNFW_STATUS load_circle_from_buffer(uint8_t *buffer, size_t size);
136 NNFW_STATUS load_model_from_modelfile(const char *file_path);
142 NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
143 NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
144 NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);
147 onert::ir::Graph *primary_subgraph();
148 bool isStateInitialized();
149 bool isStateModelLoaded();
150 bool isStatePrepared();
151 bool isStateRunning();
152 bool isStateFinishedRun();
153 bool isStatePreparedOrFinishedRun();
156 State _state{State::INITIALIZED};
157 std::shared_ptr<onert::ir::Subgraphs> _subgraphs;
158 std::unique_ptr<onert::compiler::Compiler> _compiler;
159 std::unique_ptr<onert::exec::Execution> _execution;
160 std::shared_ptr<onert::frontend::custom::KernelRegistry> _kernel_registry;
162 std::unique_ptr<onert::util::TracingCtx> _tracing_ctx;
165 #endif // __API_NNFW_API_INTERNAL_H__