1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! This module provides "raw" declarations and linkage for `Menoh` C API.
//!
//! ***In nomarl use case, no need to use this module directly.***
//!
//! To get information of `Menoh` C API, please refer to [here](https://pfnet-research.github.io/menoh/)

use libc::{c_char, c_void, int32_t};

#[allow(non_camel_case_types)]
#[repr(C)]
pub struct menoh_model_data {
    private: [u8; 0],
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub struct menoh_model {
    private: [u8; 0],
}
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct menoh_model_builder {
    private: [u8; 0],
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub struct menoh_variable_profile_table {
    private: [u8; 0],
}
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct menoh_variable_profile_table_builder {
    private: [u8; 0],
}

#[allow(non_camel_case_types)]
pub type menoh_error_code = int32_t;
#[allow(non_camel_case_types)]
pub type menoh_dtype = int32_t;

#[allow(non_camel_case_types)]
pub type menoh_model_data_handle = *mut menoh_model_data;

#[allow(non_camel_case_types)]
pub type menoh_model_handle = *mut menoh_model;
#[allow(non_camel_case_types)]
pub type menoh_model_builder_handle = *mut menoh_model_builder;

#[allow(non_camel_case_types)]
pub type menoh_variable_profile_table_handle = *mut menoh_variable_profile_table;
#[allow(non_camel_case_types)]
pub type menoh_variable_profile_table_builder_handle = *mut menoh_variable_profile_table_builder;

#[allow(non_upper_case_globals)]
pub const menoh_error_code_success: menoh_error_code = 0;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_std_error: menoh_error_code = 1;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_unknown_error: menoh_error_code = 2;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_invalid_filename: menoh_error_code = 3;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_unsupported_onnx_opset_version: menoh_error_code = 4;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_onnx_parse_error: menoh_error_code = 5;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_invalid_dtype: menoh_error_code = 6;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_invalid_attribute_type: menoh_error_code = 7;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_unsupported_operator_attribute: menoh_error_code = 8;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_dimension_mismatch: menoh_error_code = 9;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_variable_not_found: menoh_error_code = 10;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_index_out_of_range: menoh_error_code = 11;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_json_parse_error: menoh_error_code = 12;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_invalid_backend_name: menoh_error_code = 13;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_unsupported_operator: menoh_error_code = 14;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_failed_to_configure_operator: menoh_error_code = 15;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_backend_error: menoh_error_code = 16;
#[allow(non_upper_case_globals)]
pub const menoh_error_code_same_named_variable_already_exist: menoh_error_code = 17;

#[allow(non_upper_case_globals)]
pub const menoh_dtype_float: menoh_dtype = 0;

#[link(name = "menoh")]
extern "C" {
    pub fn menoh_get_last_error_message() -> *const c_char;

    pub fn menoh_make_model_data_from_onnx(
        onnx_filename: *const c_char,
        dst_handle: *mut menoh_model_data_handle,
    ) -> menoh_error_code;
    pub fn menoh_delete_model_data(model_data: menoh_model_data_handle);
    pub fn menoh_model_data_optimize(
        model_data: menoh_model_data_handle,
        variable_profile_table: menoh_variable_profile_table_handle,
    ) -> menoh_error_code;

    pub fn menoh_make_variable_profile_table_builder(
        builder: *mut menoh_variable_profile_table_builder_handle,
    ) -> menoh_error_code;
    pub fn menoh_delete_variable_profile_table_builder(
        builder: menoh_variable_profile_table_builder_handle,
    );
    pub fn menoh_variable_profile_table_builder_add_input_profile_dims_2(
        builder: menoh_variable_profile_table_builder_handle,
        name: *const c_char,
        dtype: menoh_dtype,
        num: int32_t,
        size: int32_t,
    ) -> menoh_error_code;
    pub fn menoh_variable_profile_table_builder_add_input_profile_dims_4(
        builder: menoh_variable_profile_table_builder_handle,
        name: *const c_char,
        dtype: menoh_dtype,
        num: int32_t,
        channel: int32_t,
        height: int32_t,
        width: int32_t,
    ) -> menoh_error_code;
    pub fn menoh_variable_profile_table_builder_add_output_profile(
        builder: menoh_variable_profile_table_builder_handle,
        name: *const c_char,
        dtype: menoh_dtype,
    ) -> menoh_error_code;
    pub fn menoh_build_variable_profile_table(
        builder: menoh_variable_profile_table_builder_handle,
        model_data: menoh_model_data_handle,
        dst_handle: *mut menoh_variable_profile_table_handle,
    ) -> menoh_error_code;
    pub fn menoh_delete_variable_profile_table(
        variable_profile_table: menoh_variable_profile_table_handle,
    );
    pub fn menoh_variable_profile_table_get_dtype(
        variable_profile_table: menoh_variable_profile_table_handle,
        variable_name: *const c_char,
        dst_dtype: *mut menoh_dtype,
    ) -> menoh_error_code;
    pub fn menoh_variable_profile_table_get_dims_size(
        variable_profile_table: menoh_variable_profile_table_handle,
        variable_name: *const c_char,
        dst_size: *mut int32_t,
    ) -> menoh_error_code;
    pub fn menoh_variable_profile_table_get_dims_at(
        variable_profile_table: menoh_variable_profile_table_handle,
        variable_name: *const c_char,
        index: int32_t,
        dst_size: *mut int32_t,
    ) -> menoh_error_code;

    pub fn menoh_make_model_builder(
        variable_profile_table: menoh_variable_profile_table_handle,
        dst_handle: *mut menoh_model_builder_handle,
    ) -> menoh_error_code;
    pub fn menoh_delete_model_builder(handle: menoh_model_builder_handle);
    pub fn menoh_model_builder_attach_external_buffer(
        builder: menoh_model_builder_handle,
        variable_name: *const c_char,
        buffer_handle: *mut c_void,
    ) -> menoh_error_code;
    pub fn menoh_build_model(
        builder: menoh_model_builder_handle,
        model_data: menoh_model_data_handle,
        backend_name: *const c_char,
        backend_config: *const c_char,
        dst_model_handle: *mut menoh_model_handle,
    ) -> menoh_error_code;
    pub fn menoh_delete_model(model: menoh_model_handle);
    pub fn menoh_model_get_variable_buffer_handle(
        model: menoh_model_handle,
        variable_name: *const c_char,
        dst_data: *mut *mut c_void,
    ) -> menoh_error_code;
    pub fn menoh_model_get_variable_dtype(
        model: menoh_model_handle,
        variable_name: *const c_char,
        dst_dtype: *mut menoh_dtype,
    ) -> menoh_error_code;
    pub fn menoh_model_get_variable_dims_size(
        model: menoh_model_handle,
        variable_name: *const c_char,
        dst_size: *mut int32_t,
    ) -> menoh_error_code;
    pub fn menoh_model_get_variable_dims_at(
        model: menoh_model_handle,
        variable_name: *const c_char,
        index: int32_t,
        dst_size: *mut int32_t,
    ) -> menoh_error_code;
    pub fn menoh_model_run(model: menoh_model_handle) -> menoh_error_code;
}