| // conv 1x1 tosa op test. | |
| #include "model_util/util.h" | |
| #if defined(BUILD_VMVX) | |
| #include "samples/microbenchmarks/conv1x1_test_vmvx_emitc.h" | |
| #else | |
| #include "samples/microbenchmarks/conv1x1_test_c.h" | |
| #include "samples/microbenchmarks/conv1x1_test_emitc.h" | |
| #endif | |
| const MlModel kModel = { | |
| .num_input = 1, | |
| .num_input_dim = {4}, | |
| .input_shape = {{1, 112, 112, 8}}, | |
| .input_length = {112 * 112 * 8}, | |
| .input_size_bytes = {sizeof(int8_t)}, | |
| .num_output = 1, | |
| .output_length = {112 * 112 * 16}, | |
| .output_size_bytes = sizeof(int8_t), | |
| .hal_element_type = IREE_HAL_ELEMENT_TYPE_SINT_8, | |
| .entry_func = "module.main", | |
| .model_name = "conv1x1_quant", | |
| }; | |
| iree_status_t create_module(iree_vm_instance_t *instance, | |
| iree_vm_module_t **module) { | |
| return module_create(instance, iree_allocator_system(), module); | |
| } | |
| #if !defined(BUILD_VMVX) | |
| iree_hal_executable_library_query_fn_t library_query(void) { | |
| return conv1x1_test_linked_llvm_cpu_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 to effectively 0 w.r.t conv1x1, so the output is the | |
| // same as the bias. | |
| memset((int8_t *)buffer[0], -128, | |
| model->input_length[0] * model->input_size_bytes[0]); | |
| 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, | |
| uint32_t *output_length) { | |
| iree_status_t result = iree_ok_status(); | |
| // Output is ((bias + input_zp) * multiplier) >> shift + output_zp after | |
| // rescale. | |
| const int8_t kExpectedOutput[] = {-128, -128, -125, -128, -128, 127, | |
| -107, -128, -128, -128, -128, -105, | |
| 74, 127, -128, 69}; | |
| for (int i = 0; i < model->output_length[0] / sizeof(kExpectedOutput); ++i) { | |
| for (int j = 0; j < sizeof(kExpectedOutput); ++j) { | |
| if ((((const int8_t *)buffers[0] | |
| .contents.data)[i * sizeof(kExpectedOutput) + j]) != | |
| kExpectedOutput[j]) { | |
| result = iree_make_status(IREE_STATUS_UNKNOWN, "result mismatches"); | |
| break; | |
| } | |
| } | |
| } | |
| return result; | |
| } |