Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ benchmark_sources/third_party/*
benchmark_sources/tflite-micro
benchmark_sources/tensorflow/*
benchmark_sources/signal/*

benchmark_sources/models/cifar10_resnet8/dataset/*
benchmark_sources/models/vww/dataset/*

__pycache__/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Overview

This repository contains the system for running TinyML Benchmarks on a system with the CV32E40X scalar core and Vicuna 2.0 on the CV-X-IF interface. It currently supports two benchmarks from the [MLPerfTiny Suite](https://github.com/mlcommons/tiny), anomaly detection (toycar) and keyword spotting (aww).
This repository contains the system for running TinyML Benchmarks on a system with the CV32E40X scalar core and Vicuna 2.0 on the CV-X-IF interface. It currently supports four benchmarks from the [MLPerfTiny Suite](https://github.com/mlcommons/tiny), anomaly detection (toycar), keyword spotting (aww), image classification (resnet8), and visual wake words (vww).

Due to the limitations of CMake support for native and cross-compiliation within the same project, two separate CMake projects are used. The first, defined in the **/build_model** directory, uses Verilator version v5.030 to create a executable Verilator model of Vicuna for the selected configuration. The second, defined in **/build_benchmarks**, uses the LLVM version 18.1.4 and [Tensorflow Lite for Microcontrollers](https://github.com/tensorflow/tflite-micro) to compile the benchmarks for the selected configuration of Vicuna. Each compiled benchmark is registered with CTest.

Expand Down
6 changes: 6 additions & 0 deletions benchmark_sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,24 @@ target_link_libraries(tflm PRIVATE

add_subdirectory(Int8/toycar)
add_subdirectory(Int8/aww)
add_subdirectory(Int8/resnet8)
add_subdirectory(Int8/vww)

if(RISCV_F)
if(RISCV_ZFH)
if(FH_OPS)
add_subdirectory(FP16/toycar_16_bit_ops)
add_subdirectory(FP16/aww_16_bit_ops)
add_subdirectory(FP16/resnet8_16_bit_ops)
add_subdirectory(FP16/vww_16_bit_ops)
else()
add_subdirectory(FP16/toycar_32_bit_ops)
endif()
else()
add_subdirectory(FP32/toycar)
add_subdirectory(FP32/aww)
add_subdirectory(FP32/resnet8)
add_subdirectory(FP32/vww)
endif()
endif()

1 change: 1 addition & 0 deletions benchmark_sources/FP16/resnet8_16_bit_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_Benchmark(resnet8_fp16 ${CMAKE_CURRENT_SOURCE_DIR} ${BUILD_DIR}/benchmark_sources/FP16/resnet8)
105 changes: 105 additions & 0 deletions benchmark_sources/FP16/resnet8_16_bit_ops/resnet8_fp16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include "resnet8_fp16_data/resnet8_fp16_input_data.h"
#include "resnet8_fp16_data/resnet8_fp16_model_data.h"
#include "resnet8_fp16_data/resnet8_fp16_model_settings.h"
#include "resnet8_fp16_data/resnet8_fp16_output_data_ref.h"

#include "tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"

extern "C" {
#include "runtime.h"
#include "uart.h"
#include "terminate_benchmark.h"
}

constexpr size_t tensor_arena_size = 256 * 1024 * 4;
alignas(16) uint8_t tensor_arena[tensor_arena_size];

int run_test()
{
//tflite::MicroErrorReporter micro_error_reporter;
//tflite::ErrorReporter *error_reporter = &micro_error_reporter;

const tflite::Model *model = tflite::GetModel(resnet8_fp16_model_data);

static tflite::MicroMutableOpResolver<8> resolver;
resolver.AddFullyConnected();
resolver.AddConv2D();
resolver.AddDepthwiseConv2D();
resolver.AddAveragePool2D();
resolver.AddReshape();
resolver.AddSoftmax();
resolver.AddAdd();
resolver.AddDequantize();

tflite::MicroInterpreter interpreter(model, resolver, tensor_arena, tensor_arena_size);

if (interpreter.AllocateTensors() != kTfLiteOk)
{
//TF_LITE_REPORT_ERROR(error_reporter, "ERROR: In AllocateTensors().");
return -1;
}

//for (size_t i = 0; i < resnet8_fp16_data_sample_cnt; i++)
for (size_t i = 0; i < 1; i++)
{
memcpy(interpreter.input(0)->data.f, (float *)resnet8_fp16_input_data[i], resnet8_fp16_input_data_len[i] * 2); //Bytes to copy is 4*len

if (interpreter.Invoke() != kTfLiteOk)
{
//TF_LITE_REPORT_ERROR(error_reporter, "ERROR: In Invoke().");
return -1;
}

int8_t top_index = 0;
_Float16* output_ptr = (_Float16*)interpreter.output(0)->data.f;
for (size_t j = 0; j < resnet8_fp16_model_label_cnt; j++)
{
if (output_ptr[j] > output_ptr[top_index])
{
top_index = j;
}
}

if (top_index != resnet8_fp16_output_data_ref[i])
{
//uart_printf("ERROR: at #%d, top_index %d resnet8_fp16_output_data_ref %d \n", i, top_index, resnet8_fp16_output_data_ref[i]);
return -1;
}
else
{
//uart_printf("Sample #%d pass, top_index %d matches ref %d \n", i, top_index, resnet8_fp16_output_data_ref[i]);
}
}
return 0;
}

int main(int argc, char *argv[])
{
int ret = run_test();
if (ret != 0)
{
#if defined(PRINT_OUTPUTS)
uart_printf("Test Failed!\n");
#endif
benchmark_failure();

}
else
{
#if defined(PRINT_OUTPUTS)
uart_printf("Test Success!\n");
#endif
benchmark_success();
}

return ret;
}
Loading