/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Daredevil 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/daredevil_bytecode_module_static.h"
#include "samples/quant_model/daredevil_bytecode_module_static_c.h"
#else
#include "samples/quant_model/daredevil_c_module_static_c.h"
#include "samples/quant_model/daredevil_c_module_static_emitc.h"
#endif

const MlModel kModel = {
    .num_input = 1,
    .num_input_dim = {3},
    .input_shape = {{1, 96, 64}},
    .input_length = {96 * 64},
    .input_size_bytes = {sizeof(uint8_t)},
    .num_output = 1,
    .output_length = {527},
    .output_size_bytes = sizeof(uint8_t),
    .hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
    .entry_func = "module.main",
    .model_name = "daredevil_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_daredevil_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
}

iree_hal_executable_library_query_fn_t library_query(void) {
#if !defined(BUILD_EMITC)
  return &daredevil_bytecode_module_static_linked_llvm_library_query;
#else
  return &daredevil_c_module_static_linked_llvm_library_query;
#endif
}

iree_status_t load_input_data(const MlModel *model, void **buffer,
                              iree_const_byte_span_t **byte_span) {
  iree_status_t result = alloc_input_buffer(model, buffer);
  // Populate initial value
  srand(3689964);
  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_const_byte_span_t));
  *byte_span[0] = iree_make_const_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();
}
