// Scenenet_v2 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/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(float),
    .num_output = 1,
    .output_length = {170},
    .output_size_bytes = sizeof(float),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_FLOAT_32,
    .entry_func = "module.main",
    .model_name = "scenenet_v2_float",
};

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