blob: 63aea14278902c51e214291d0035d951bbfef599 [file] [log] [blame]
Lun Donga5635112021-09-01 11:33:30 -07001// Daredevil quant model
2// MlModel struct initialization to include model I/O info.
3// Bytecode loading, input/output processes.
4
5#include <springbok.h>
6
7#include "iree/base/api.h"
8#include "iree/hal/api.h"
9#include "samples/util/util.h"
10
11// Compiled module embedded here to avoid file IO:
12#include "samples/quant_model_embedding/daredevil_bytecode_module_dylib_c.h"
13
14const MlModel kModel = {
15 .num_input_dim = 3,
16 .input_shape = {1, 96, 64},
17 .input_length = 96 * 64,
18 .input_size_bytes = sizeof(uint8_t),
19 .num_output = 1,
20 .output_length = {527},
21 .output_size_bytes = sizeof(uint8_t),
22 .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
23 .model_name = "daredevil_quant",
24};
25
26const iree_const_byte_span_t load_bytecode_module_data() {
27 const struct iree_file_toc_t *module_file_toc =
28 samples_quant_model_embedding_daredevil_bytecode_module_dylib_create();
29 return iree_make_const_byte_span(module_file_toc->data,
30 module_file_toc->size);
31}
32
33iree_status_t load_input_data(const MlModel *model, void **buffer) {
34 // Populate initial value
35 srand(3689964);
36 for (int i = 0; i < model->input_length; ++i) {
Lun Dongc369f682021-09-02 11:33:37 -070037 ((uint8_t *)*buffer)[i] = (uint8_t)rand();
Lun Donga5635112021-09-01 11:33:30 -070038 }
39 return iree_ok_status();
40}
41
42iree_status_t check_output_data(const MlModel *model,
43 iree_hal_buffer_mapping_t *mapped_memory,
44 int index_output) {
45 iree_status_t result = iree_ok_status();
46 if (index_output > model->num_output ||
47 mapped_memory->contents.data_length / model->output_size_bytes !=
48 model->output_length[index_output]) {
49 result = iree_make_status(IREE_STATUS_UNKNOWN, "output length mismatches");
50 }
51 LOG_INFO("Output #%d data length: %d \n", index_output,
52 mapped_memory->contents.data_length / model->output_size_bytes);
53 return result;
54}