sw:vec-iree: Make public models builable by default Also remove mobilenet_v2_1.0_float.tflite model example. It is a 13MB model, so it is probably not suitable for Shodan. Change-Id: Iedf451e406c62c317341f86322ffffb89ac4774c
diff --git a/samples/float_model_embedding/CMakeLists.txt b/samples/float_model_embedding/CMakeLists.txt index 30d67f0..919aa1b 100644 --- a/samples/float_model_embedding/CMakeLists.txt +++ b/samples/float_model_embedding/CMakeLists.txt
@@ -1,30 +1,28 @@ #------------------------------------------------------------------------------- -# Build the mlir bytecode modules with iree-translate. Note the last two flags -# and "+experimental-v" are for RVV support. +# Build the mlir bytecode modules with iree-translate. Note the last three flags +# are for RVV support. #------------------------------------------------------------------------------- -if(NOT ${BUILD_INTERNAL_MODELS}) - return() -endif() +springbok_bytecode_module( + NAME + mobilenet_v1_bytecode_module_dylib + SRC + "$ENV{ROOTDIR}/ml/ml-models-public/float_models/mobilenet_v1_0.25_224_float.tflite" + C_IDENTIFIER + "samples_float_model_embedding_mobilenet_v1_bytecode_module_dylib" + FLAGS + "-iree-input-type=tosa" + "-riscv-v-vector-bits-min=512" + "-riscv-v-fixed-length-vector-lmul-max=8" + "-riscv-v-fixed-length-vector-elen-max=32" + PUBLIC +) + +if(${BUILD_INTERNAL_MODELS}) if(NOT ${BUILD_WITH_SPRINGBOK}) springbok_bytecode_module( NAME - mobilenet_v2_bytecode_module_dylib - SRC - "$ENV{ROOTDIR}/ml/ml-models/float_models/mobilenet_v2_1.0_224_float.tflite" - C_IDENTIFIER - "samples_float_model_embedding_mobilenet_v2_bytecode_module_dylib" - FLAGS - "-iree-input-type=tosa" - "-riscv-v-vector-bits-min=512" - "-riscv-v-fixed-length-vector-lmul-max=8" - "-riscv-v-fixed-length-vector-elen-max=32" - PUBLIC - ) - - springbok_bytecode_module( - NAME scenenet_v2_bytecode_module_dylib SRC "$ENV{ROOTDIR}/ml/ml-models/float_models/scenenet_v2_float.tflite" @@ -86,21 +84,6 @@ springbok_bytecode_module( NAME - mobilenet_v1_bytecode_module_dylib - SRC - "$ENV{ROOTDIR}/ml/ml-models/float_models/mobilenet_v1_0.25_224_float.tflite" - C_IDENTIFIER - "samples_float_model_embedding_mobilenet_v1_bytecode_module_dylib" - FLAGS - "-iree-input-type=tosa" - "-riscv-v-vector-bits-min=512" - "-riscv-v-fixed-length-vector-lmul-max=8" - "-riscv-v-fixed-length-vector-elen-max=32" - PUBLIC -) - -springbok_bytecode_module( - NAME person_detection_bytecode_module_dylib SRC "$ENV{ROOTDIR}/ml/ml-models/float_models/person_detection_float.tflite" @@ -144,6 +127,8 @@ PUBLIC ) +endif(${BUILD_INTERNAL_MODELS}) + #------------------------------------------------------------------------------- # Binaries to execute the MLIR bytecode modules #------------------------------------------------------------------------------- @@ -158,17 +143,23 @@ # Currently only the person_detection model can run with springbok (b/196910893) -if(NOT ${BUILD_WITH_SPRINGBOK}) - iree_cc_binary( - NAME - mobilenet_v2_embedded_sync - SRCS - "mobilenet_v2.c" - DEPS - ::mobilenet_v2_bytecode_module_dylib_c - samples::util::util - ) +iree_cc_binary( + NAME + mobilenet_v1_embedded_sync + SRCS + "mobilenet_v1.c" + DEPS + ::mobilenet_v1_bytecode_module_dylib_c + samples::util::util + LINKOPTS + "LINKER:--defsym=__stack_size__=100k" +) +if(NOT ${BUILD_INTERNAL_MODELS}) + return() +endif() + +if(NOT ${BUILD_WITH_SPRINGBOK}) iree_cc_binary( NAME scenenet_v2_embedded_sync @@ -218,18 +209,6 @@ iree_cc_binary( NAME - mobilenet_v1_embedded_sync - SRCS - "mobilenet_v1.c" - DEPS - ::mobilenet_v1_bytecode_module_dylib_c - samples::util::util - LINKOPTS - "LINKER:--defsym=__stack_size__=100k" -) - -iree_cc_binary( - NAME person_detection_embedded_sync SRCS "person_detection.c"
diff --git a/samples/float_model_embedding/mobilenet_v2.c b/samples/float_model_embedding/mobilenet_v2.c deleted file mode 100644 index 7d139ef..0000000 --- a/samples/float_model_embedding/mobilenet_v2.c +++ /dev/null
@@ -1,55 +0,0 @@ -// Mobilenet_v2_1.0_224 float 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: -#include "samples/float_model_embedding/mobilenet_v2_bytecode_module_dylib_c.h" - -const MlModel kModel = { - .num_input_dim = 4, - .input_shape = {1, 224, 224, 3}, - .input_length = 224 * 224 * 3, - .input_size_bytes = sizeof(float), - .num_output = 1, - .output_length = {1001}, - .output_size_bytes = sizeof(float), - .hal_element_type = IREE_HAL_ELEMENT_TYPE_FLOAT_32, - .model_name = "mobilenet_v2_1.0_224_float", -}; - -const iree_const_byte_span_t load_bytecode_module_data() { - const struct iree_file_toc_t *module_file_toc = - samples_float_model_embedding_mobilenet_v2_bytecode_module_dylib_create(); - return iree_make_const_byte_span(module_file_toc->data, - module_file_toc->size); -} - -iree_status_t load_input_data(const MlModel *model, void **buffer) { - // Populate initial value - srand(33333333); - for (int i = 0; i < model->input_length; ++i) { - int x = rand(); - ((float *)*buffer)[i] = (float)x / (float)RAND_MAX; - } - return iree_ok_status(); -} - -iree_status_t check_output_data(const MlModel *model, - iree_hal_buffer_mapping_t *mapped_memory, - int index_output) { - iree_status_t result = iree_ok_status(); - if (index_output > model->num_output || - mapped_memory->contents.data_length / model->output_size_bytes != - model->output_length[index_output]) { - result = iree_make_status(IREE_STATUS_UNKNOWN, "output length mismatches"); - } - LOG_INFO("Output #%d data length: %d \n", index_output, - mapped_memory->contents.data_length / model->output_size_bytes); - return result; -}
diff --git a/samples/quant_model_embedding/CMakeLists.txt b/samples/quant_model_embedding/CMakeLists.txt index 9a36686..5bf4381 100644 --- a/samples/quant_model_embedding/CMakeLists.txt +++ b/samples/quant_model_embedding/CMakeLists.txt
@@ -1,19 +1,15 @@ #------------------------------------------------------------------------------- -# Build the mlir bytecode modules with iree-translate. Note the last two flags -# and "+experimental-v" are for RVV support. +# Build the mlir bytecode modules with iree-translate. Note the last three flags +# are for RVV support. #------------------------------------------------------------------------------- -if(NOT ${BUILD_INTERNAL_MODELS}) - return() -endif() - if(NOT ${BUILD_WITH_SPRINGBOK}) # TODO(b/198476354): uncomment below after operator tosa.clz is supported # springbok_bytecode_module( # NAME # mobilenet_v2_bytecode_module_dylib # SRC -# "$ENV{ROOTDIR}/ml/ml-models/quant_models/mobilenet_v2_1.0_224_quant.tflite" +# "$ENV{ROOTDIR}/ml/ml-models-public/quant_models/mobilenet_v2_1.0_224_quant.tflite" # C_IDENTIFIER # "samples_quant_model_embedding_mobilenet_v2_bytecode_module_dylib" # FLAGS @@ -23,7 +19,42 @@ # "-riscv-v-fixed-length-vector-elen-max=32" # PUBLIC # ) +endif() +# TODO(b/198476354): uncomment below after operator tosa.clz is supported +# springbok_bytecode_module( +# NAME +# mobilenet_v1_bytecode_module_dylib +# SRC +# "$ENV{ROOTDIR}/ml/ml-models-public/quant_models/mobilenet_v1_0.25_224_quant.tflite" +# C_IDENTIFIER +# "samples_quant_model_embedding_mobilenet_v1_bytecode_module_dylib" +# FLAGS +# "-iree-input-type=tosa" +# "-riscv-v-vector-bits-min=512" +# "-riscv-v-fixed-length-vector-lmul-max=8" +# "-riscv-v-fixed-length-vector-elen-max=32" +# PUBLIC +# ) + +# springbok_bytecode_module( +# NAME +# person_detection_bytecode_module_dylib +# SRC +# "$ENV{ROOTDIR}/ml/ml-models-public/quant_models/person_detection.tflite" +# C_IDENTIFIER +# "samples_quant_model_embedding_person_detection_bytecode_module_dylib" +# FLAGS +# "-iree-input-type=tosa" +# "-riscv-v-vector-bits-min=512" +# "-riscv-v-fixed-length-vector-lmul-max=8" +# "-riscv-v-fixed-length-vector-elen-max=32" +# PUBLIC +# ) + +if(${BUILD_INTERNAL_MODELS}) + +if(NOT ${BUILD_WITH_SPRINGBOK}) springbok_bytecode_module( NAME scenenet_v2_bytecode_module_dylib @@ -85,37 +116,6 @@ PUBLIC ) -# TODO(b/198476354): uncomment below after operator tosa.clz is supported -#springbok_bytecode_module( -# NAME -# mobilenet_v1_bytecode_module_dylib -# SRC -# "$ENV{ROOTDIR}/ml/ml-models/quant_models/mobilenet_v1_0.25_224_quant.tflite" -# C_IDENTIFIER -# "samples_quant_model_embedding_mobilenet_v1_bytecode_module_dylib" -# FLAGS -# "-iree-input-type=tosa" -# "-riscv-v-vector-bits-min=512" -# "-riscv-v-fixed-length-vector-lmul-max=8" -# "-riscv-v-fixed-length-vector-elen-max=32" -# PUBLIC -#) - -#springbok_bytecode_module( -# NAME -# person_detection_bytecode_module_dylib -# SRC -# "$ENV{ROOTDIR}/ml/ml-models/quant_models/person_detection_quant.tflite" -# C_IDENTIFIER -# "samples_quant_model_embedding_person_detection_bytecode_module_dylib" -# FLAGS -# "-iree-input-type=tosa" -# "-riscv-v-vector-bits-min=512" -# "-riscv-v-fixed-length-vector-lmul-max=8" -# "-riscv-v-fixed-length-vector-elen-max=32" -# PUBLIC -#) - springbok_bytecode_module( NAME voice_commands_bytecode_module_dylib @@ -131,6 +131,8 @@ PUBLIC ) +endif(${BUILD_INTERNAL_MODELS}) + #------------------------------------------------------------------------------- # Binaries to execute the MLIR bytecode modules #------------------------------------------------------------------------------- @@ -156,7 +158,38 @@ # ::mobilenet_v2_bytecode_module_dylib_c # samples::util::util # ) +endif() +# TODO(b/198476354): uncomment below after operator tosa.clz is supported +# iree_cc_binary( +# NAME +# mobilenet_v1_embedded_sync +# SRCS +# "mobilenet_v1.c" +# DEPS +# ::mobilenet_v1_bytecode_module_dylib_c +# samples::util::util +# LINKOPTS +# "LINKER:--defsym=__stack_size__=100k" +# ) + +# iree_cc_binary( +# NAME +# person_detection_embedded_sync +# SRCS +# "person_detection.c" +# DEPS +# ::person_detection_bytecode_module_dylib_c +# samples::util::util +# LINKOPTS +# "LINKER:--defsym=__stack_size__=100k" +# ) + +if(NOT ${BUILD_INTERNAL_MODELS}) + return() +endif() + +if(NOT ${BUILD_WITH_SPRINGBOK}) iree_cc_binary( NAME scenenet_v2_embedded_sync @@ -204,31 +237,6 @@ "LINKER:--defsym=__stack_size__=100k" ) -# TODO(b/198476354): uncomment below after operator tosa.clz is supported -#iree_cc_binary( -# NAME -# mobilenet_v1_embedded_sync -# SRCS -# "mobilenet_v1.c" -# DEPS -# ::mobilenet_v1_bytecode_module_dylib_c -# samples::util::util -# LINKOPTS -# "LINKER:--defsym=__stack_size__=100k" -#) - -#iree_cc_binary( -# NAME -# person_detection_embedded_sync -# SRCS -# "person_detection.c" -# DEPS -# ::person_detection_bytecode_module_dylib_c -# samples::util::util -# LINKOPTS -# "LINKER:--defsym=__stack_size__=100k" -#) - iree_cc_binary( NAME voice_commands_embedded_sync