ml/ml-models-public: build selected models for Kelvin
For Kelvin, only build models that can fit its memory.
Add support for kelvin output header.
Change-Id: I06d7cda48f1659b51dacfb599da59bdaacaab3b6
diff --git a/float_models/CMakeLists.txt b/float_models/CMakeLists.txt
index 51fa579..68a422e 100644
--- a/float_models/CMakeLists.txt
+++ b/float_models/CMakeLists.txt
@@ -71,6 +71,11 @@
#
# to increase it.
+# Do not compile following models for Kelvin
+if (${BUILD_WITH_KELVIN})
+ return()
+endif()
+
iree_cc_binary(
NAME
mobilenet_v1_bytecode_static
diff --git a/float_models/iree_exec/mnist.c b/float_models/iree_exec/mnist.c
index 4ae4782..d4d2531 100644
--- a/float_models/iree_exec/mnist.c
+++ b/float_models/iree_exec/mnist.c
@@ -62,7 +62,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
// find the label index with best prediction
float best_out = 0.0;
@@ -81,5 +81,6 @@
LOG_INFO("Digit recognition result is: digit: %d", best_idx);
*output_length = sizeof(score);
+ *output_ptr = (uint32_t)&score;
return result;
}
diff --git a/float_models/iree_exec/mobilenet_v1.c b/float_models/iree_exec/mobilenet_v1.c
index 27946d9..e8cb740 100644
--- a/float_models/iree_exec/mobilenet_v1.c
+++ b/float_models/iree_exec/mobilenet_v1.c
@@ -62,7 +62,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
// find the label index with best prediction
float best_out = 0.0;
@@ -80,5 +80,6 @@
LOG_INFO("Image prediction result is: id: %d", best_idx + 1);
*output_length = sizeof(score);
+ *output_ptr = (uint32_t)&score;
return result;
}
diff --git a/quant_models/CMakeLists.txt b/quant_models/CMakeLists.txt
index b6fef98..d248bfa 100644
--- a/quant_models/CMakeLists.txt
+++ b/quant_models/CMakeLists.txt
@@ -28,6 +28,10 @@
"mobilenet_v1_0.25_224_quant.tflite"
C_IDENTIFIER
"quant_models_mobilenet_v1"
+ TFLITE_OUTPUT
+ # TODO(b/287490866): remove this argument after IREE fix is landed
+ "--output-array=MobilenetV1/Logits/SpatialSqueeze"
+ MobilenetV1/Logits/SpatialSqueeze
FLAGS
"-iree-input-type=tosa"
"-riscv-v-fixed-length-vector-lmul-max=8"
@@ -111,55 +115,6 @@
#
# to increase it.
-foreach(N RANGE 0 6)
- set(HPS_COPTS "-DHPS_QUANT_INPUT=hps_${N}_quant_input")
- list(APPEND HPS_COPTS "-DHPS_QUANT_INPUT_C_H=\"hps_${N}_quant_input_c.h\"")
- if (NOT BUILD_NO_WMMU)
- list(APPEND HPS_COPTS "-DNO_STATIC_INPUT")
- endif()
-
- iree_cc_binary(
- NAME
- hps_${N}_bytecode_static
- SRCS
- "iree_exec/hps.c"
- DEPS
- ::hps_${N}_quant_input_c
- ::hps_bytecode_module_static_c
- ::hps_bytecode_module_static_lib
- iree::vm::bytecode::module
- model_util::util_static
- COPTS
- ${HPS_COPTS}
- LINKOPTS
- "LINKER:--defsym=__stack_size__=200k"
- # TODO(b/241297921): determine HPS heap size
- "LINKER:--defsym=__heap_size__=5M"
- )
-
- sparrow_test(
- NAME
- hps_${N}_emitc_static
- SRCS
- "iree_exec/hps.c"
- DEPS
- ::hps_${N}_quant_input_c
- ::hps_c_module_static_emitc
- ::hps_c_module_static_lib
- model_util::util_static
- LINKOPTS
- "LINKER:--defsym=__stack_size__=200k"
- # TODO(b/241297921): determine HPS heap size
- "LINKER:--defsym=__heap_size__=5M"
- COPTS
- ${HPS_COPTS}
- "-DBUILD_EMITC"
- TESTFILES
- "iree_exec/hps_test.run"
- "iree_exec/hps_${N}_test.filecheck"
- )
-endforeach()
-
iree_cc_binary(
NAME
mobilenet_v1_bytecode_static
@@ -198,42 +153,6 @@
iree_cc_binary(
NAME
- mobilenet_v2_bytecode_static
- SRCS
- "iree_exec/mobilenet_v2.c"
- DEPS
- ::mobilenet_quant_input_c
- ::mobilenet_v2_bytecode_module_static_c
- ::mobilenet_v2_bytecode_module_static_lib
- iree::vm::bytecode::module
- model_util::util_static
- LINKOPTS
- "LINKER:--defsym=__stack_size__=300k"
- "LINKER:--defsym=__heap_size__=2m"
-)
-
-sparrow_test(
- NAME
- mobilenet_v2_emitc_static
- SRCS
- "iree_exec/mobilenet_v2.c"
- DEPS
- ::mobilenet_quant_input_c
- ::mobilenet_v2_c_module_static_emitc
- ::mobilenet_v2_c_module_static_lib
- model_util::util_static
- LINKOPTS
- "LINKER:--defsym=__stack_size__=300k"
- "LINKER:--defsym=__heap_size__=2m"
- COPTS
- "-DBUILD_EMITC"
- TESTFILES
- "iree_exec/mobilenet_v2_test.run"
- "iree_exec/mobilenet_v2_test.filecheck"
-)
-
-iree_cc_binary(
- NAME
person_detection_bytecode_vmvx
SRCS
"iree_exec/person_detection.c"
@@ -303,3 +222,93 @@
"iree_exec/person_detection_test.run"
"iree_exec/person_detection_test.filecheck"
)
+
+# Do not compile following models for Kelvin
+if (${BUILD_WITH_KELVIN})
+ return()
+endif()
+
+foreach(N RANGE 0 6)
+ set(HPS_COPTS "-DHPS_QUANT_INPUT=hps_${N}_quant_input")
+ list(APPEND HPS_COPTS "-DHPS_QUANT_INPUT_C_H=\"hps_${N}_quant_input_c.h\"")
+ if (NOT BUILD_NO_WMMU)
+ list(APPEND HPS_COPTS "-DNO_STATIC_INPUT")
+ endif()
+
+ iree_cc_binary(
+ NAME
+ hps_${N}_bytecode_static
+ SRCS
+ "iree_exec/hps.c"
+ DEPS
+ ::hps_${N}_quant_input_c
+ ::hps_bytecode_module_static_c
+ ::hps_bytecode_module_static_lib
+ iree::vm::bytecode::module
+ model_util::util_static
+ COPTS
+ ${HPS_COPTS}
+ LINKOPTS
+ "LINKER:--defsym=__stack_size__=200k"
+ # TODO(b/241297921): determine HPS heap size
+ "LINKER:--defsym=__heap_size__=5M"
+ )
+
+ sparrow_test(
+ NAME
+ hps_${N}_emitc_static
+ SRCS
+ "iree_exec/hps.c"
+ DEPS
+ ::hps_${N}_quant_input_c
+ ::hps_c_module_static_emitc
+ ::hps_c_module_static_lib
+ model_util::util_static
+ LINKOPTS
+ "LINKER:--defsym=__stack_size__=200k"
+ # TODO(b/241297921): determine HPS heap size
+ "LINKER:--defsym=__heap_size__=5M"
+ COPTS
+ ${HPS_COPTS}
+ "-DBUILD_EMITC"
+ TESTFILES
+ "iree_exec/hps_test.run"
+ "iree_exec/hps_${N}_test.filecheck"
+ )
+endforeach()
+
+iree_cc_binary(
+ NAME
+ mobilenet_v2_bytecode_static
+ SRCS
+ "iree_exec/mobilenet_v2.c"
+ DEPS
+ ::mobilenet_quant_input_c
+ ::mobilenet_v2_bytecode_module_static_c
+ ::mobilenet_v2_bytecode_module_static_lib
+ iree::vm::bytecode::module
+ model_util::util_static
+ LINKOPTS
+ "LINKER:--defsym=__stack_size__=300k"
+ "LINKER:--defsym=__heap_size__=2m"
+)
+
+sparrow_test(
+ NAME
+ mobilenet_v2_emitc_static
+ SRCS
+ "iree_exec/mobilenet_v2.c"
+ DEPS
+ ::mobilenet_quant_input_c
+ ::mobilenet_v2_c_module_static_emitc
+ ::mobilenet_v2_c_module_static_lib
+ model_util::util_static
+ LINKOPTS
+ "LINKER:--defsym=__stack_size__=300k"
+ "LINKER:--defsym=__heap_size__=2m"
+ COPTS
+ "-DBUILD_EMITC"
+ TESTFILES
+ "iree_exec/mobilenet_v2_test.run"
+ "iree_exec/mobilenet_v2_test.filecheck"
+)
diff --git a/quant_models/iree_exec/hps.c b/quant_models/iree_exec/hps.c
index d114e8f..4bbb983 100644
--- a/quant_models/iree_exec/hps.c
+++ b/quant_models/iree_exec/hps.c
@@ -66,7 +66,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
int8_t *data = (int8_t *)buffers[0].contents.data;
score.score_0 = data[0];
@@ -75,5 +75,6 @@
LOG_INFO("Score 0: %d, Score 1: %d", score.score_0, score.score_1);
*output_length = sizeof(score);
+ *output_ptr = (uint32_t)&score;
return result;
}
diff --git a/quant_models/iree_exec/mobilenet_v1.c b/quant_models/iree_exec/mobilenet_v1.c
index a5cd523..4c44dbb 100644
--- a/quant_models/iree_exec/mobilenet_v1.c
+++ b/quant_models/iree_exec/mobilenet_v1.c
@@ -63,7 +63,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
// find the label index with best prediction
int best_out = 0;
@@ -81,5 +81,6 @@
LOG_INFO("Image prediction result is: id: %d", best_idx + 1);
*output_length = sizeof(score);
+ *output_ptr = (uint32_t)&score;
return result;
}
diff --git a/quant_models/iree_exec/mobilenet_v2.c b/quant_models/iree_exec/mobilenet_v2.c
index 66a00d7..c625520 100644
--- a/quant_models/iree_exec/mobilenet_v2.c
+++ b/quant_models/iree_exec/mobilenet_v2.c
@@ -63,7 +63,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
// find the label index with best prediction
int best_out = 0;
@@ -81,5 +81,6 @@
LOG_INFO("Image prediction result is: id: %d", best_idx + 1);
*output_length = sizeof(score);
+ *output_ptr = (uint32_t)&score;
return result;
}
diff --git a/quant_models/iree_exec/person_detection.c b/quant_models/iree_exec/person_detection.c
index e7d948b..23c2187 100644
--- a/quant_models/iree_exec/person_detection.c
+++ b/quant_models/iree_exec/person_detection.c
@@ -78,7 +78,7 @@
iree_status_t process_output(const MlModel *model,
iree_hal_buffer_mapping_t *buffers,
- uint32_t *output_length) {
+ uint32_t *output_length, uint32_t *output_ptr) {
iree_status_t result = iree_ok_status();
int8_t *data = (int8_t *)buffers[0].contents.data;
detection.non_person_score = data[0];
@@ -88,5 +88,6 @@
detection.non_person_score, detection.person_score);
*output_length = sizeof(detection);
+ *output_ptr = (uint32_t)&detection;
return result;
}