// 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_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();
    }
  }
  return result;
}

iree_status_t process_output(const MlModel *model,
                              iree_hal_buffer_mapping_t *buffers,
                              MlOutput *output) {
  return iree_ok_status();
}
