// Voice_commands 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/voice_commands_bytecode_module_dylib_c.h"

const MlModel kModel = {
    .num_input_dim = 3,
    .input_shape = {1, 198, 32},
    .input_length = 198 * 32,
    .input_size_bytes = sizeof(uint8_t),
    .num_output = 1,
    .output_length = {63},
    .output_size_bytes = sizeof(float),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .model_name = "voice_commands_quant",
};

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