// 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(float),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .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;
}
