Browse Source

!13782 update example and run script

From: @zhujingxuan
Reviewed-by: @wangchengyuan,@wangchengyuan,@zhanghaibo5
Signed-off-by: @wangchengyuan,@wangchengyuan
pull/13782/MERGE
mindspore-ci-bot Gitee 5 years ago
parent
commit
3bd84e3705
19 changed files with 109 additions and 3 deletions
  1. +0
    -0
      mindspore/lite/micro/example/mnist_x86/CMakeLists.txt
  2. +0
    -0
      mindspore/lite/micro/example/mnist_x86/README.md
  3. +0
    -0
      mindspore/lite/micro/example/mnist_x86/benchmark/benchmark.cc
  4. +0
    -0
      mindspore/lite/micro/example/mnist_x86/benchmark/load_input.c
  5. +0
    -0
      mindspore/lite/micro/example/mnist_x86/benchmark/load_input.h
  6. +94
    -0
      mindspore/lite/micro/example/mnist_x86/mnist.sh
  7. +15
    -3
      mindspore/lite/micro/example/mnist_x86/mnist_codegen.sh
  8. +0
    -0
      mindspore/lite/micro/example/mnist_x86/mnist_input.bin
  9. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/CMakeLists.txt
  10. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/net.bin
  11. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/net.c
  12. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/net.cmake
  13. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/net.h
  14. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/session.cc
  15. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/session.h
  16. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/tensor.cc
  17. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/tensor.h
  18. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/weight.c
  19. +0
    -0
      mindspore/lite/micro/example/mnist_x86/src/weight.h

mindspore/lite/micro/example/mnist/CMakeLists.txt → mindspore/lite/micro/example/mnist_x86/CMakeLists.txt View File


mindspore/lite/micro/example/mnist/README.md → mindspore/lite/micro/example/mnist_x86/README.md View File


mindspore/lite/micro/example/mnist/benchmark/benchmark.cc → mindspore/lite/micro/example/mnist_x86/benchmark/benchmark.cc View File


mindspore/lite/micro/example/mnist/benchmark/load_input.c → mindspore/lite/micro/example/mnist_x86/benchmark/load_input.c View File


mindspore/lite/micro/example/mnist/benchmark/load_input.h → mindspore/lite/micro/example/mnist_x86/benchmark/load_input.h View File


+ 94
- 0
mindspore/lite/micro/example/mnist_x86/mnist.sh View File

@@ -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

mindspore/lite/micro/example/mnist/mnist.sh → mindspore/lite/micro/example/mnist_x86/mnist_codegen.sh View File

@@ -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

mindspore/lite/micro/example/mnist/mnist_input.bin → mindspore/lite/micro/example/mnist_x86/mnist_input.bin View File


mindspore/lite/micro/example/mnist/src/CMakeLists.txt → mindspore/lite/micro/example/mnist_x86/src/CMakeLists.txt View File


mindspore/lite/micro/example/mnist/src/net.bin → mindspore/lite/micro/example/mnist_x86/src/net.bin View File


mindspore/lite/micro/example/mnist/src/net.c → mindspore/lite/micro/example/mnist_x86/src/net.c View File


mindspore/lite/micro/example/mnist/src/net.cmake → mindspore/lite/micro/example/mnist_x86/src/net.cmake View File


mindspore/lite/micro/example/mnist/src/net.h → mindspore/lite/micro/example/mnist_x86/src/net.h View File


mindspore/lite/micro/example/mnist/src/session.cc → mindspore/lite/micro/example/mnist_x86/src/session.cc View File


mindspore/lite/micro/example/mnist/src/session.h → mindspore/lite/micro/example/mnist_x86/src/session.h View File


mindspore/lite/micro/example/mnist/src/tensor.cc → mindspore/lite/micro/example/mnist_x86/src/tensor.cc View File


mindspore/lite/micro/example/mnist/src/tensor.h → mindspore/lite/micro/example/mnist_x86/src/tensor.h View File


mindspore/lite/micro/example/mnist/src/weight.c → mindspore/lite/micro/example/mnist_x86/src/weight.c View File


mindspore/lite/micro/example/mnist/src/weight.h → mindspore/lite/micro/example/mnist_x86/src/weight.h View File


Loading…
Cancel
Save