// Scenenet_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/scenenet_v2_bytecode_module_dylib_c.h"

const MlModel kModel = {
    .num_input_dim = 4,
    .input_shape = {1, 192, 192, 3},
    .input_length = 192 * 192 * 3,
    .input_size_bytes = sizeof(uint8_t),
    .num_output = 1,
    .output_length = {170},
    .output_size_bytes = sizeof(uint8_t),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .entry_func = "module.main",
    .model_name = "scenenet_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_scenenet_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(55555555);
  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;
}
