// Semantic_lift 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:
#if !defined(BUILD_EMITC)
#include "samples/quant_model/semantic_lift_bytecode_module_static.h"
#include "samples/quant_model/semantic_lift_bytecode_module_static_c.h"
#else
#include "samples/quant_model/semantic_lift_c_module_static_c.h"
#include "samples/quant_model/semantic_lift_c_module_static_emitc.h"
#endif

const MlModel kModel = {
    .num_input = 1,
    .num_input_dim = {4},
    .input_shape = {{1, 128, 128, 3}},
    .input_length = {128 * 128 * 3},
    .input_size_bytes = {sizeof(uint8_t)},
    .num_output = 3,
    .output_length = {2, 2, 2},
    .output_size_bytes = sizeof(uint8_t),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .entry_func = "module.main",
    .model_name = "semantic_lift_quant",
};

iree_status_t create_module(iree_vm_module_t **module) {
#if !defined(BUILD_EMITC)
  const struct iree_file_toc_t *module_file_toc =
      samples_quant_model_semantic_lift_bytecode_module_static_create();
  return iree_vm_bytecode_module_create(
      iree_make_const_byte_span(module_file_toc->data, module_file_toc->size),
      iree_allocator_null(), iree_allocator_system(), module);
#else
  return module_create(iree_allocator_system(), module);
#endif
}

const iree_hal_executable_library_header_t **library_query(
    iree_hal_executable_library_version_t max_version, void *reserved) {
#if !defined(BUILD_EMITC)
  return semantic_lift_bytecode_module_static_linked_llvm_library_query(
      max_version,
      /*reserved=*/reserved);
#else
  return semantic_lift_c_module_static_linked_llvm_library_query(
      max_version,
      /*reserved=*/reserved);
#endif
}

iree_status_t load_input_data(const MlModel *model, void **buffer,
                              iree_byte_span_t **byte_span) {
  iree_status_t result = alloc_input_buffer(model, buffer);
  // Populate initial value
  srand(66666666);
  if (iree_status_is_ok(result)) {
    for (int i = 0; i < model->input_length[0]; ++i) {
      ((uint8_t *)*buffer)[i] = (uint8_t)rand();
    }
  }
  byte_span[0] = malloc(sizeof(iree_byte_span_t));
  *byte_span[0] = iree_make_byte_span(
      buffer[0], model->input_size_bytes[0] * model->input_length[0]);
  return result;
}

iree_status_t process_output(const MlModel *model,
                             iree_hal_buffer_mapping_t *buffers,
                             MlOutput *output) {
  return iree_ok_status();
}
