// Daredevil 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/daredevil_bytecode_module_dylib_c.h"

const MlModel kModel = {
    .num_input_dim = 3,
    .input_shape = {1, 96, 64},
    .input_length = 96 * 64,
    .input_size_bytes = sizeof(uint8_t),
    .num_output = 1,
    .output_length = {527},
    .output_size_bytes = sizeof(uint8_t),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .entry_func = "module.main",
    .model_name = "daredevil_quant",
};

const iree_const_byte_span_t load_bytecode_module_data() {
  const struct iree_file_toc_t *module_file_toc =
      samples_quant_model_embedding_daredevil_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(3689964);
  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;
}
