diff --git a/mindspore/lite/micro/example/mnist/CMakeLists.txt b/mindspore/lite/micro/example/mnist_x86/CMakeLists.txt similarity index 100% rename from mindspore/lite/micro/example/mnist/CMakeLists.txt rename to mindspore/lite/micro/example/mnist_x86/CMakeLists.txt diff --git a/mindspore/lite/micro/example/mnist/README.md b/mindspore/lite/micro/example/mnist_x86/README.md similarity index 100% rename from mindspore/lite/micro/example/mnist/README.md rename to mindspore/lite/micro/example/mnist_x86/README.md diff --git a/mindspore/lite/micro/example/mnist/benchmark/benchmark.cc b/mindspore/lite/micro/example/mnist_x86/benchmark/benchmark.cc similarity index 100% rename from mindspore/lite/micro/example/mnist/benchmark/benchmark.cc rename to mindspore/lite/micro/example/mnist_x86/benchmark/benchmark.cc diff --git a/mindspore/lite/micro/example/mnist/benchmark/load_input.c b/mindspore/lite/micro/example/mnist_x86/benchmark/load_input.c similarity index 100% rename from mindspore/lite/micro/example/mnist/benchmark/load_input.c rename to mindspore/lite/micro/example/mnist_x86/benchmark/load_input.c diff --git a/mindspore/lite/micro/example/mnist/benchmark/load_input.h b/mindspore/lite/micro/example/mnist_x86/benchmark/load_input.h similarity index 100% rename from mindspore/lite/micro/example/mnist/benchmark/load_input.h rename to mindspore/lite/micro/example/mnist_x86/benchmark/load_input.h diff --git a/mindspore/lite/micro/example/mnist_x86/mnist.sh b/mindspore/lite/micro/example/mnist_x86/mnist.sh new file mode 100644 index 00000000000..bc79ef5e3d1 --- /dev/null +++ b/mindspore/lite/micro/example/mnist_x86/mnist.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +set -e + +GEN=OFF +while getopts 'g' OPT +do + case $OPT in + g) + GEN=ON;; + ?) + echo "Usage: add -g or left it empty" + esac +done + +BASEPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +MINDSPORE_ROOT_DIR=${${BASEPATH}%%/mindspore/lite/micro/example/mnist} + +echo "current dir is: ${BASEPATH}" + +INPUT_BIN=${BASEPATH}/mnist_input.bin +BENCHMARK_PATH=${BASEPATH} + +get_version() { + local VERSION_HEADER=${MINDSPORE_ROOT_DIR}/mindspore/lite/include/version.h + local VERSION_MAJOR=$(grep "const int ms_version_major =" ${VERSION_HEADER} | tr -dc "[0-9]") + local VERSION_MINOR=$(grep "const int ms_version_minor =" ${VERSION_HEADER} | tr -dc "[0-9]") + local VERSION_REVISION=$(grep "const int ms_version_revision =" ${VERSION_HEADER} | tr -dc "[0-9]") + VERSION_STR=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION} +} + +download_inference() { + local MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-inference-linux-x64" + local MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz" + local MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/linux/${MINDSPORE_FILE}" + + if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} + fi + + tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ || exit 1 + rm ${BASEPATH}/build/${MINDSPORE_FILE} || exit 1 + PKG_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME} +} + +download_mnist() { + MNIST_NAME=mnist + MNIST_FILE=${MNIST_NAME}.ms + local MNIST_DOWNLOAD_URL=https://download.mindspore.cn/model_zoo/official/lite/mnist_lite/${MNIST_FILE} + + if [ ! -e ${BASEPATH}/build/${MNIST_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MNIST_FILE} --no-check-certificate ${MNIST_DOWNLOAD_URL} + fi +} + +gen_mnist() { + local CODEGEN_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME}/tools/codegen + ${CODEGEN_PATH}/codegen --codePath=${BASEPATH}/build --modelPath=${BASEPATH}/build/${MNIST_FILE} +} + +mkdir -p build + +get_version +download_inference + +if [ "${GEN}" == "ON" ]; then + echo "downloading mnist.ms!" + download_mnist + echo "generating mnist" + gen_mnist + BENCHMARK_PATH=${BASEPATH}/build/${MNIST_NAME} +fi + +# 1. build benchmark +mkdir -p ${BASEPATH}/build/benchmark && cd ${BASEPATH}/build/benchmark || exit 1 +cmake -DPKG_PATH=${PKG_PATH} ${BENCHMARK_PATH} +make + +# 2. run benchmark +echo "net file: ${BENCHMARK_PATH}/src/mnist.bin" +./benchmark ${INPUT_BIN} ${BENCHMARK_PATH}/src/net.bin diff --git a/mindspore/lite/micro/example/mnist/mnist.sh b/mindspore/lite/micro/example/mnist_x86/mnist_codegen.sh similarity index 80% rename from mindspore/lite/micro/example/mnist/mnist.sh rename to mindspore/lite/micro/example/mnist_x86/mnist_codegen.sh index 0646e060bde..2fcde1581f1 100644 --- a/mindspore/lite/micro/example/mnist/mnist.sh +++ b/mindspore/lite/micro/example/mnist_x86/mnist_codegen.sh @@ -34,20 +34,32 @@ MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-inference-linux-x64" MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz" MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/linux/${MINDSPORE_FILE}" +MNIST_NAME=mnist +MNIST_FILE=${MNIST_NAME}.ms +MNIST_DOWNLOAD_URL=https://download.mindspore.cn/model_zoo/official/lite/mnist_lite/${MNIST_FILE} + mkdir -p build if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} fi +if [ ! -e ${BASEPATH}/build/${MNIST_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MNIST_FILE} --no-check-certificate ${MNIST_DOWNLOAD_URL} +fi + tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ || exit 1 rm ${BASEPATH}/build/${MINDSPORE_FILE} || exit 1 PKG_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME} -# build benchmark + +# 1. codegen +${BASEPATH}/build/${MINDSPORE_FILE_NAME}/tools/codegen/codegen --codePath=${BASEPATH}/build --modelPath=${BASEPATH}/build/${MNIST_FILE} + +# 2. build benchmark mkdir -p ${BASEPATH}/build/benchmark && cd ${BASEPATH}/build/benchmark || exit 1 -cmake -DPKG_PATH=${PKG_PATH} ${BASEPATH} +cmake -DPKG_PATH=${PKG_PATH} ${BASEPATH}/build/${MNIST_NAME} make -echo "net file: ${BASEPATH}/src/mnist.bin" # 3. run benchmark +echo "net file: ${BASEPATH}/src/mnist.bin" ./benchmark ${INPUT_BIN} ${BASEPATH}/src/net.bin diff --git a/mindspore/lite/micro/example/mnist/mnist_input.bin b/mindspore/lite/micro/example/mnist_x86/mnist_input.bin similarity index 100% rename from mindspore/lite/micro/example/mnist/mnist_input.bin rename to mindspore/lite/micro/example/mnist_x86/mnist_input.bin diff --git a/mindspore/lite/micro/example/mnist/src/CMakeLists.txt b/mindspore/lite/micro/example/mnist_x86/src/CMakeLists.txt similarity index 100% rename from mindspore/lite/micro/example/mnist/src/CMakeLists.txt rename to mindspore/lite/micro/example/mnist_x86/src/CMakeLists.txt diff --git a/mindspore/lite/micro/example/mnist/src/net.bin b/mindspore/lite/micro/example/mnist_x86/src/net.bin similarity index 100% rename from mindspore/lite/micro/example/mnist/src/net.bin rename to mindspore/lite/micro/example/mnist_x86/src/net.bin diff --git a/mindspore/lite/micro/example/mnist/src/net.c b/mindspore/lite/micro/example/mnist_x86/src/net.c similarity index 100% rename from mindspore/lite/micro/example/mnist/src/net.c rename to mindspore/lite/micro/example/mnist_x86/src/net.c diff --git a/mindspore/lite/micro/example/mnist/src/net.cmake b/mindspore/lite/micro/example/mnist_x86/src/net.cmake similarity index 100% rename from mindspore/lite/micro/example/mnist/src/net.cmake rename to mindspore/lite/micro/example/mnist_x86/src/net.cmake diff --git a/mindspore/lite/micro/example/mnist/src/net.h b/mindspore/lite/micro/example/mnist_x86/src/net.h similarity index 100% rename from mindspore/lite/micro/example/mnist/src/net.h rename to mindspore/lite/micro/example/mnist_x86/src/net.h diff --git a/mindspore/lite/micro/example/mnist/src/session.cc b/mindspore/lite/micro/example/mnist_x86/src/session.cc similarity index 100% rename from mindspore/lite/micro/example/mnist/src/session.cc rename to mindspore/lite/micro/example/mnist_x86/src/session.cc diff --git a/mindspore/lite/micro/example/mnist/src/session.h b/mindspore/lite/micro/example/mnist_x86/src/session.h similarity index 100% rename from mindspore/lite/micro/example/mnist/src/session.h rename to mindspore/lite/micro/example/mnist_x86/src/session.h diff --git a/mindspore/lite/micro/example/mnist/src/tensor.cc b/mindspore/lite/micro/example/mnist_x86/src/tensor.cc similarity index 100% rename from mindspore/lite/micro/example/mnist/src/tensor.cc rename to mindspore/lite/micro/example/mnist_x86/src/tensor.cc diff --git a/mindspore/lite/micro/example/mnist/src/tensor.h b/mindspore/lite/micro/example/mnist_x86/src/tensor.h similarity index 100% rename from mindspore/lite/micro/example/mnist/src/tensor.h rename to mindspore/lite/micro/example/mnist_x86/src/tensor.h diff --git a/mindspore/lite/micro/example/mnist/src/weight.c b/mindspore/lite/micro/example/mnist_x86/src/weight.c similarity index 100% rename from mindspore/lite/micro/example/mnist/src/weight.c rename to mindspore/lite/micro/example/mnist_x86/src/weight.c diff --git a/mindspore/lite/micro/example/mnist/src/weight.h b/mindspore/lite/micro/example/mnist_x86/src/weight.h similarity index 100% rename from mindspore/lite/micro/example/mnist/src/weight.h rename to mindspore/lite/micro/example/mnist_x86/src/weight.h