blob: 0ba243ea54216866f8afe254616d706843e8a1ac [file] [log] [blame]
// Fssd_25_8bit_v2 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/risp4ml/pipeline/pipeline.h"
#include "samples/util/util.h"
// Compiled module embedded here to avoid file IO:
#include "samples/quant_model/fssd_quant_input_c.h"
#if !defined(BUILD_EMITC)
#include "samples/quant_model/fssd_25_8bit_v2_bytecode_module_static.h"
#include "samples/quant_model/fssd_25_8bit_v2_bytecode_module_static_c.h"
#else
#include "samples/quant_model/fssd_25_8bit_v2_c_module_static_c.h"
#include "samples/quant_model/fssd_25_8bit_v2_c_module_static_emitc.h"
#endif
const MlModel kModel = {
.num_input = 1,
.num_input_dim = {4},
.input_shape = {{1, 320, 320, 3}},
.input_length = {320 * 320 * 3},
.input_size_bytes = {sizeof(uint8_t)},
.num_output = 8,
.output_length = {20 * 20 * 48, 20 * 20 * 3, 10 * 10 * 48, 10 * 10 * 3,
5 * 5 * 48, 5 * 5 * 3, 3 * 3 * 48, 3 * 3 * 3},
.output_size_bytes = sizeof(uint8_t),
.hal_element_type = IREE_HAL_ELEMENT_TYPE_UINT_8,
.entry_func = "module.main",
.model_name = "fssd_25_8bit_v2_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_fssd_25_8bit_v2_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 fssd_25_8bit_v2_bytecode_module_static_linked_llvm_library_query(
max_version,
/*reserved=*/reserved);
#else
return fssd_25_8bit_v2_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);
ImageU8 input = {
.width = 640, .height = 480, .num_channels = 1, .data = fssd_quant_input};
ImageU8 output = {
.width = 320, .height = 320, .num_channels = 3, .data = buffer[0]};
isp_pipeline(&input, &output);
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();
}