9 #ifndef DOXYGEN_SHOULD_SKIP_THIS 11 #define MENOH_CPP_API_ERROR_CHECK(statement) \ 13 auto ec = statement; \ 15 throw error(ec, menoh_get_last_error_message()); \ 19 #endif // DOXYGEN_SHOULD_SKIP_THIS 58 class error :
public std::runtime_error {
61 : runtime_error(message), ec_(static_cast<
error_code_t>(ec)) {}
75 class variable_profile_table;
109 void reset() noexcept { impl_.reset(); }
124 impl_.get(), input_name.c_str()));
130 impl_.get(), output_name.c_str()));
138 impl_.get(), attribute_name.c_str(), value));
143 std::vector<int32_t>
const& value) {
146 impl_.get(), attribute_name.c_str(), value.size(),
155 impl_.get(), attribute_name.c_str(), value));
160 std::vector<float>
const& value) {
163 impl_.get(), attribute_name.c_str(), value.size(),
168 std::vector<int>
const& dims,
169 void* buffer_handle) {
171 impl_.get(), parameter_name.c_str(),
172 static_cast<menoh_dtype>(dtype), dims.size(), dims.data(),
177 std::unique_ptr<menoh_model_data, decltype(&menoh_delete_model_data)>
224 impl_.get(), name.c_str(), &dtype));
228 impl_.get(), name.c_str(), &dims_size));
229 std::vector<int32_t> dims(dims_size);
230 for(
int i = 0; i < dims_size; ++i) {
233 impl_.get(), name.c_str(), i, &dims.at(i)));
276 std::vector<int32_t>
const& dims) {
279 impl_.get(), name.c_str(),
static_cast<menoh_dtype>(dtype),
280 dims.size(), dims.data()));
289 impl_.get(), name.c_str()));
297 [[deprecated(
"Use add_output_name() instead")]]
342 impl_.get(), name.c_str(), &buff));
345 impl_.get(), name.c_str(), &dtype));
348 impl_.get(), name.c_str(), &dims_size));
349 std::vector<int32_t> dims(dims_size);
350 for(
int i = 0; i < dims_size; ++i) {
352 impl_.get(), name.c_str(), i, &dims.at(i)));
365 std::unique_ptr<menoh_model, decltype(&menoh_delete_model)> impl_;
390 void* buffer_handle) {
393 impl_.get(), name.c_str(), buffer_handle));
402 std::string
const& backend_name,
403 std::string
const& backend_config =
"") {
407 backend_config.c_str(), &h));
422 #undef MENOH_CPP_API_ERROR_CHECK menoh_model_builder is helper for creation of model.
menoh_error_code MENOH_API menoh_build_model(const menoh_model_builder_handle builder, const menoh_model_data_handle model_data, const char *backend_name, const char *backend_config, menoh_model_handle *dst_model_handle)
Factory function for menoh_model.
variable_profile_table(menoh_variable_profile_table_handle h)
Definition: menoh.hpp:214
Definition: menoh.hpp:320
menoh_error_code MENOH_API menoh_model_data_add_output_name_to_current_node(menoh_model_data_handle model_data, const char *output_name)
Add a new output name to latest added node in model_data.
menoh_model_data_handle get() const noexcept
Definition: menoh.hpp:98
menoh_error_code MENOH_API menoh_make_model_data(menoh_model_data_handle *dst_handle)
Make empty model_data.
model build_model(model_data const &model_data, std::string const &backend_name, std::string const &backend_config="")
Factory function for model.
Definition: menoh.hpp:401
dtype_t dtype
Definition: menoh.hpp:203
menoh_error_code MENOH_API menoh_variable_profile_table_get_dims_size(const menoh_variable_profile_table_handle variable_profile_table, const char *variable_name, int32_t *dst_size)
Accessor function for variable_profile_table.
menoh_error_code MENOH_API menoh_model_data_add_attribute_int_to_current_node(menoh_model_data_handle model_data, const char *attribute_name, int32_t value)
Add a new int attribute to latest added node in model_data.
menoh_error_code MENOH_API menoh_variable_profile_table_get_dims_at(const menoh_variable_profile_table_handle variable_profile_table, const char *variable_name, int32_t index, int32_t *dst_size)
Accessor function for variable_profile_table.
menoh_error_code MENOH_API menoh_variable_profile_table_builder_add_input_profile(menoh_variable_profile_table_builder_handle builder, const char *name, menoh_dtype dtype, int32_t dims_size, const int32_t *dims)
Add input profile.
void add_output_profile(std::string const &name, dtype_t)
Add output profile. That profile contains name and dtype.
Definition: menoh.hpp:298
menoh_error_code MENOH_API menoh_model_get_variable_buffer_handle(const menoh_model_handle model, const char *variable_name, void **dst_data)
Get a buffer handle attached to target variable.
model_data(menoh_model_data_handle h)
Definition: menoh.hpp:91
The error class thrown when any error occured.
Definition: menoh.hpp:58
menoh_error_code MENOH_API menoh_model_builder_attach_external_buffer(menoh_model_builder_handle builder, const char *variable_name, void *buffer_handle)
Attach a buffer which allocated by users.
void add_attribute_floats_to_current_node(std::string const &attribute_name, std::vector< float > const &value)
Definition: menoh.hpp:159
menoh_error_code MENOH_API menoh_model_data_optimize(menoh_model_data_handle model_data, const menoh_variable_profile_table_handle variable_profile_table)
Optimize function for menoh_model_data.
menoh_model is the main component to execute model inference.
menoh_error_code MENOH_API menoh_make_model_data_from_onnx(const char *onnx_filename, menoh_model_data_handle *dst_handle)
Load onnx file and make model_data.
void run()
Run model inference.
Definition: menoh.hpp:362
menoh_error_code MENOH_API menoh_make_model_builder(const menoh_variable_profile_table_handle variable_profile_table, menoh_model_builder_handle *dst_handle)
Factory function for menoh_model_builder.
void add_input_profile(std::string const &name, dtype_t dtype, std::vector< int32_t > const &dims)
Add input profile. That profile contains name, dtype and dims.
Definition: menoh.hpp:275
variable_profile_table build_variable_profile_table(model_data const &model_data)
Factory function for variable_profile_table.
Definition: menoh.hpp:304
The builder class to build variable_profile_table.
Definition: menoh.hpp:264
dtype_t
Definition: menoh.hpp:73
int32_t menoh_dtype
Definition: menoh.h:51
menoh_variable_profile_table_handle get() const noexcept
Accessor to internal handle.
Definition: menoh.hpp:242
void add_parameter(std::string const ¶meter_name, dtype_t dtype, std::vector< int > const &dims, void *buffer_handle)
Definition: menoh.hpp:167
void add_attribute_float_to_current_node(std::string const &attribute_name, float value)
Definition: menoh.hpp:151
menoh_error_code MENOH_API menoh_model_data_add_input_name_to_current_node(menoh_model_data_handle model_data, const char *input_name)
Add a new input name to latest added node in model_data.
variable_profile_table_builder()
Definition: menoh.hpp:266
void add_input_name_to_current_node(std::string const &input_name)
Definition: menoh.hpp:121
void MENOH_API menoh_delete_model_data(menoh_model_data_handle model_data)
Model_data delete function.
void add_attribute_int_to_current_node(std::string const &attribute_name, int32_t value)
Definition: menoh.hpp:134
model_data make_model_data_from_onnx(std::string const &onnx_filename)
Load ONNX file and make model_data.
Definition: menoh.hpp:183
model_builder(variable_profile_table const &variable_profile_table)
Definition: menoh.hpp:373
void MENOH_API menoh_delete_model(menoh_model_handle model)
Delete function for model.
menoh_error_code MENOH_API menoh_model_get_variable_dtype(const menoh_model_handle model, const char *variable_name, menoh_dtype *dst_dtype)
Get dtype of target variable.
void add_output_name_to_current_node(std::string const &output_name)
Definition: menoh.hpp:127
error_code_t error_code() const noexcept
Definition: menoh.hpp:66
menoh_variable_profile_table_builder is the builder for creation of menoh_variable_profile_table.
The builder class to build model.
Definition: menoh.hpp:371
model data class
Definition: menoh.hpp:80
Definition: menoh.hpp:202
menoh_error_code MENOH_API menoh_model_data_add_attribute_float_to_current_node(menoh_model_data_handle model_data, const char *attribute_name, float value)
Add a new float attribute to latest added node in model_data.
menoh_error_code MENOH_API menoh_model_data_add_attribute_ints_to_current_node(menoh_model_data_handle model_data, const char *attribute_name, int32_t size, const int32_t *value)
Add a new int array attribute to latest added node in model_data.
menoh_error_code MENOH_API menoh_model_get_variable_dims_at(const menoh_model_handle model, const char *variable_name, int32_t index, int32_t *dst_size)
Get an element of dims of target variable specified by index.
model_data make_model_data_from_onnx_data_on_memory(const uint8_t *onnx_data, uint32_t size)
Make model_data from onnx binary data on memory.
Definition: menoh.hpp:191
menoh_error_code MENOH_API menoh_variable_profile_table_builder_add_output_name(menoh_variable_profile_table_builder_handle builder, const char *name)
Add output name.
void MENOH_API menoh_delete_variable_profile_table_builder(menoh_variable_profile_table_builder_handle builder)
Delete function for variable_profile_table_builder.
variable_profile get_variable_profile(std::string const &name) const
Accessor to variable profile.
Definition: menoh.hpp:221
void reset() noexcept
Release internal alocated memory.
Definition: menoh.hpp:109
menoh_error_code MENOH_API menoh_model_data_add_attribute_floats_to_current_node(menoh_model_data_handle model_data, const char *attribute_name, int32_t size, const float *value)
Add a new float array attribute to latest added node in model_data.
void MENOH_API menoh_delete_model_builder(menoh_model_builder_handle model_builder)
Delete function for model_builder.
menoh_error_code MENOH_API menoh_make_model_data_from_onnx_data_on_memory(const uint8_t *onnx_data, int32_t size, menoh_model_data_handle *dst_handle)
make model_data from onnx binary data on memory
menoh_error_code MENOH_API menoh_variable_profile_table_get_dtype(const menoh_variable_profile_table_handle variable_profile_table, const char *variable_name, menoh_dtype *dst_dtype)
Accessor function for variable_profile_table.
error(menoh_error_code ec, std::string const &message)
Definition: menoh.hpp:60
void add_output_name(std::string const &name)
Add a name of required output.
Definition: menoh.hpp:286
error_code_t
Definition: menoh.hpp:27
dtype_t dtype
Definition: menoh.hpp:321
#define MENOH_CPP_API_ERROR_CHECK(statement)
Definition: menoh.hpp:11
void optimize(variable_profile_table const &vpt)
Optimize model_data.
Definition: menoh.hpp:255
int32_t menoh_error_code
Definition: menoh.h:83
variable get_variable(std::string const &name) const
Accsessor to internal variable.
Definition: menoh.hpp:339
model(menoh_model_handle h)
Definition: menoh.hpp:332
void attach_external_buffer(std::string const &name, void *buffer_handle)
Users can attach external buffers to variables.
Definition: menoh.hpp:389
void add_attribute_ints_to_current_node(std::string const &attribute_name, std::vector< int32_t > const &value)
Definition: menoh.hpp:142
menoh_error_code MENOH_API menoh_build_variable_profile_table(const menoh_variable_profile_table_builder_handle builder, const menoh_model_data_handle model_data, menoh_variable_profile_table_handle *dst_handle)
Factory function for variable_profile_table.
menoh_variable_profile_table contains information of dims of variables.
menoh_error_code MENOH_API menoh_model_data_add_new_node(menoh_model_data_handle model_data, const char *op_type)
Add a new node to model_data.
void add_new_node(std::string const &op_type)
Definition: menoh.hpp:116
menoh_error_code MENOH_API menoh_model_data_add_parameter(menoh_model_data_handle model_data, const char *parameter_name, menoh_dtype dtype, int32_t dims_size, const int32_t *dims, void *buffer_handle)
Add a new parameter in model_data.
error(error_code_t ec, std::string const &message)
Definition: menoh.hpp:63
std::vector< int32_t > dims
Definition: menoh.hpp:204
Key value store for variable_profile.
Definition: menoh.hpp:208
void MENOH_API menoh_delete_variable_profile_table(menoh_variable_profile_table_handle variable_profile_table)
Delete function for variable_profile_table.
menoh_model_data contains model parameters and computation graph structure.
model_data()
Definition: menoh.hpp:82
std::vector< int32_t > dims
Definition: menoh.hpp:322
menoh_error_code MENOH_API menoh_model_get_variable_dims_size(const menoh_model_handle model, const char *variable_name, int32_t *dst_size)
Get size of dims of target variable.
menoh_error_code MENOH_API menoh_make_variable_profile_table_builder(menoh_variable_profile_table_builder_handle *dst_handle)
Factory function for variable_profile_table_builder.
void * buffer_handle
Definition: menoh.hpp:323
The main component to run inference.
Definition: menoh.hpp:327
menoh_error_code MENOH_API menoh_model_run(menoh_model_handle model)
Run model inference.