| // Barcode quant model |
| // MlModel struct initialization to include model I/O info. |
| // Bytecode loading, input/output processes. |
| |
| #include <springbok.h> |
| |
| #include "iree/base/api.h" |
| #include "iree/hal/api.h" |
| #include "samples/util/util.h" |
| |
| // Compiled module embedded here to avoid file IO: |
| #include "samples/quant_model/barcode_bytecode_module_dylib_c.h" |
| |
| const MlModel kModel = { |
| .num_input = 1, |
| .num_input_dim = {4}, |
| .input_shape = {{1, 320, 320, 1}}, |
| .input_length = {320 * 320 * 1}, |
| .input_size_bytes = {sizeof(uint8_t)}, |
| .num_output = 12, |
| .output_length = {20 * 20 * 36, 20 * 20 * 9, 10 * 10 * 72, 10 * 10 * 18, |
| 5 * 5 * 72, 5 * 5 * 18, 3 * 3 * 72, 3 * 3 * 18, |
| 2 * 2 * 72, 2 * 2 * 18, 72, 18}, |
| .output_size_bytes = sizeof(uint8_t), |
| .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8, |
| .entry_func = "module.main", |
| .model_name = "barcode_quant", |
| }; |
| |
| const iree_const_byte_span_t load_bytecode_module_data() { |
| const struct iree_file_toc_t *module_file_toc = |
| samples_quant_model_barcode_bytecode_module_dylib_create(); |
| return iree_make_const_byte_span(module_file_toc->data, |
| module_file_toc->size); |
| } |
| |
| iree_status_t load_input_data(const MlModel *model, void **buffer, |
| iree_byte_span_t **byte_span) { |
| iree_status_t result = alloc_input_buffer(model, buffer); |
| // Populate initial value |
| srand(768954); |
| if (iree_status_is_ok(result)) { |
| for (int i = 0; i < model->input_length[0]; ++i) { |
| ((uint8_t *)*buffer)[i] = (uint8_t)rand(); |
| } |
| } |
| byte_span[0] = malloc(sizeof(iree_byte_span_t)); |
| *byte_span[0] = iree_make_byte_span( |
| buffer[0], model->input_size_bytes[0] * model->input_length[0]); |
| return result; |
| } |
| |
| iree_status_t process_output(const MlModel *model, |
| iree_hal_buffer_mapping_t *buffers, |
| MlOutput *output) { |
| return iree_ok_status(); |
| } |