// mnist float 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/float_model_embedding/mnist_bytecode_module_dylib_c.h"

const MlModel kModel = {
    .num_input_dim = 4,
    .input_shape = {1, 28, 28, 1},
    .input_length = 28 * 28 * 1,
    .input_size_bytes = sizeof(float),
    .num_output = 1,
    .output_length = {10},
    .output_size_bytes = sizeof(float),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_FLOAT_32,
    .entry_func = "module.predict",
    .model_name = "mnist",
};

const iree_const_byte_span_t load_bytecode_module_data() {
  const struct iree_file_toc_t *module_file_toc =
      samples_float_model_embedding_mnist_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(74886738);
  for (int i = 0; i < model->input_length; ++i) {
    int x = rand();
    ((float *)*buffer)[i] = (float)x / (float)RAND_MAX;
  }
  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;
}
