| // Fssd_25_8bit_v2 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_embedding/fssd_25_8bit_v2_bytecode_module_dylib_c.h" |
| |
| const MlModel kModel = { |
| .num_input_dim = 4, |
| .input_shape = {1, 320, 320, 3}, |
| .input_length = 320 * 320 * 3, |
| .input_size_bytes = sizeof(uint8_t), |
| .num_output = 8, |
| .output_length = {20 * 20 * 48, 20 * 20 * 3, 10 * 10 * 48, 10 * 10 * 3, |
| 5 * 5 * 48, 5 * 5 * 3, 3 * 3 * 48, 3 * 3 * 3}, |
| .output_size_bytes = sizeof(uint8_t), |
| .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8, |
| .model_name = "fssd_25_8bit_v2_quant", |
| }; |
| |
| const iree_const_byte_span_t load_bytecode_module_data() { |
| const struct iree_file_toc_t *module_file_toc = |
| samples_quant_model_embedding_fssd_25_8bit_v2_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) { |
| // Populate initial value |
| srand(11111111); |
| for (int i = 0; i < model->input_length; ++i) { |
| ((uint8_t *)*buffer)[i] = (uint8_t)rand(); |
| } |
| return iree_ok_status(); |
| } |
| |
| iree_status_t check_output_data(const MlModel *model, |
| iree_hal_buffer_mapping_t *mapped_memory, |
| int index_output) { |
| iree_status_t result = iree_ok_status(); |
| if (index_output > model->num_output || |
| mapped_memory->contents.data_length / model->output_size_bytes != |
| model->output_length[index_output]) { |
| result = iree_make_status(IREE_STATUS_UNKNOWN, "output length mismatches"); |
| } |
| LOG_INFO("Output #%d data length: %d \n", index_output, |
| mapped_memory->contents.data_length / model->output_size_bytes); |
| return result; |
| } |