diff options
author | Chunseok Lee <chunseok.lee@samsung.com> | 2018-05-04 17:57:16 +0900 |
---|---|---|
committer | Chunseok Lee <chunseok.lee@samsung.com> | 2018-05-04 17:57:16 +0900 |
commit | 07659ccd9fe7b1cf1547cc6cad78bcf489f0a361 (patch) | |
tree | cf3a123812b7f1ad8b50d7d0ace891e0c03c6110 /tools | |
parent | da6f7a3e8360a49fd073a6e0031a4da134d9d984 (diff) | |
download | nnfw-07659ccd9fe7b1cf1547cc6cad78bcf489f0a361.tar.gz nnfw-07659ccd9fe7b1cf1547cc6cad78bcf489f0a361.tar.bz2 nnfw-07659ccd9fe7b1cf1547cc6cad78bcf489f0a361.zip |
Imported Upstream version 0.1upstream/0.1submit/tizen/20180504.091146
Diffstat (limited to 'tools')
-rw-r--r-- | tools/.FORMATCHECKED | 0 | ||||
-rw-r--r-- | tools/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/cross/apt_proxy | 0 | ||||
-rw-r--r-- | tools/cross/arm/sources.list.trusty | 11 | ||||
-rw-r--r-- | tools/cross/arm/sources.list.xenial | 11 | ||||
-rw-r--r-- | tools/cross/arm64/sources.list.trusty | 11 | ||||
-rw-r--r-- | tools/cross/arm64/sources.list.xenial | 11 | ||||
-rwxr-xr-x | tools/cross/armel/tizen-build-rootfs.sh | 43 | ||||
-rwxr-xr-x | tools/cross/armel/tizen-fetch.sh | 169 | ||||
-rw-r--r-- | tools/cross/armel/tizen.patch | 18 | ||||
-rwxr-xr-x | tools/cross/build_android_rootfs.sh | 62 | ||||
-rwxr-xr-x | tools/cross/build_rootfs.sh | 122 | ||||
-rw-r--r-- | tools/nnapi_test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tools/nnapi_test/src/nnapi_test.cc | 59 | ||||
-rw-r--r-- | tools/test_driver/nnfw_kernel_env_list.txt | 7 | ||||
-rwxr-xr-x | tools/test_driver/print_to_json.sh | 152 | ||||
-rwxr-xr-x | tools/test_driver/test_driver.sh | 417 |
17 files changed, 1099 insertions, 0 deletions
diff --git a/tools/.FORMATCHECKED b/tools/.FORMATCHECKED new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tools/.FORMATCHECKED diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..9b82628cb --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(nnapi_test) diff --git a/tools/cross/apt_proxy b/tools/cross/apt_proxy new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tools/cross/apt_proxy diff --git a/tools/cross/arm/sources.list.trusty b/tools/cross/arm/sources.list.trusty new file mode 100644 index 000000000..8aa98a259 --- /dev/null +++ b/tools/cross/arm/sources.list.trusty @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ trusty main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-security main restricted universe multiverse diff --git a/tools/cross/arm/sources.list.xenial b/tools/cross/arm/sources.list.xenial new file mode 100644 index 000000000..56fbb36a5 --- /dev/null +++ b/tools/cross/arm/sources.list.xenial @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse diff --git a/tools/cross/arm64/sources.list.trusty b/tools/cross/arm64/sources.list.trusty new file mode 100644 index 000000000..8aa98a259 --- /dev/null +++ b/tools/cross/arm64/sources.list.trusty @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ trusty main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ trusty-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-security main restricted universe multiverse diff --git a/tools/cross/arm64/sources.list.xenial b/tools/cross/arm64/sources.list.xenial new file mode 100644 index 000000000..56fbb36a5 --- /dev/null +++ b/tools/cross/arm64/sources.list.xenial @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse diff --git a/tools/cross/armel/tizen-build-rootfs.sh b/tools/cross/armel/tizen-build-rootfs.sh new file mode 100755 index 000000000..2d0084d03 --- /dev/null +++ b/tools/cross/armel/tizen-build-rootfs.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -e + +__ARM_SOFTFP_CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +if [[ -z "$ROOTFS_DIR" ]]; then + echo "ROOTFS_DIR is not defined." + exit 1; +fi + +# Clean-up (TODO-Cleanup: We may already delete $ROOTFS_DIR at ./cross/build-rootfs.sh.) +# hk0110 +if [ -d "$ROOTFS_DIR" ]; then + umount $ROOTFS_DIR/* + rm -rf $ROOTFS_DIR +fi + +TIZEN_TMP_DIR=$ROOTFS_DIR/tizen_tmp +mkdir -p $TIZEN_TMP_DIR + +# Download files +echo ">>Start downloading files" +VERBOSE=1 $__ARM_SOFTFP_CrossDir/tizen-fetch.sh $TIZEN_TMP_DIR +echo "<<Finish downloading files" + +echo ">>Start constructing Tizen rootfs" +TIZEN_RPM_FILES=`ls $TIZEN_TMP_DIR/*.rpm` +cd $ROOTFS_DIR +for f in $TIZEN_RPM_FILES; do + rpm2cpio $f | cpio -idm --quiet +done +echo "<<Finish constructing Tizen rootfs" + +# Cleanup tmp +rm -rf $TIZEN_TMP_DIR + +# Configure Tizen rootfs +echo ">>Start configuring Tizen rootfs" +rm ./usr/lib/libunwind.so +ln -s libunwind.so.8 ./usr/lib/libunwind.so +ln -sfn asm-arm ./usr/include/asm +patch -p1 < $__ARM_SOFTFP_CrossDir/tizen.patch +echo "<<Finish configuring Tizen rootfs" diff --git a/tools/cross/armel/tizen-fetch.sh b/tools/cross/armel/tizen-fetch.sh new file mode 100755 index 000000000..4f63b24c2 --- /dev/null +++ b/tools/cross/armel/tizen-fetch.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +set -e + +if [[ -z "${VERBOSE// }" ]] || [ "$VERBOSE" -ne "$VERBOSE" ] 2>/dev/null; then + VERBOSE=0 +fi + +Log() +{ + if [ $VERBOSE -ge $1 ]; then + echo ${@:2} + fi +} + +Inform() +{ + Log 1 -e "\x1B[0;34m$@\x1B[m" +} + +Debug() +{ + Log 2 -e "\x1B[0;32m$@\x1B[m" +} + +Error() +{ + >&2 Log 0 -e "\x1B[0;31m$@\x1B[m" +} + +Fetch() +{ + URL=$1 + FILE=$2 + PROGRESS=$3 + if [ $VERBOSE -ge 1 ] && [ $PROGRESS ]; then + CURL_OPT="--progress-bar" + else + CURL_OPT="--silent" + fi + curl $CURL_OPT $URL > $FILE +} + +hash curl 2> /dev/null || { Error "Require 'curl' Aborting."; exit 1; } +hash xmllint 2> /dev/null || { Error "Require 'xmllint' Aborting."; exit 1; } +hash sha256sum 2> /dev/null || { Error "Require 'sha256sum' Aborting."; exit 1; } + +TMPDIR=$1 +if [ ! -d $TMPDIR ]; then + TMPDIR=./tizen_tmp + Debug "Create temporary directory : $TMPDIR" + mkdir -p $TMPDIR +fi + +TIZEN_URL=http://download.tizen.org/releases/daily/tizen +BUILD_XML=build.xml +REPOMD_XML=repomd.xml +PRIMARY_XML=primary.xml +TARGET_URL="http://__not_initialized" + +Xpath_get() +{ + XPATH_RESULT='' + XPATH=$1 + XML_FILE=$2 + RESULT=$(xmllint --xpath $XPATH $XML_FILE) + if [[ -z ${RESULT// } ]]; then + Error "Can not find target from $XML_FILE" + Debug "Xpath = $XPATH" + exit 1 + fi + XPATH_RESULT=$RESULT +} + +fetch_tizen_pkgs_init() +{ + TARGET=$1 + PROFILE=$2 + Debug "Initialize TARGET=$TARGET, PROFILE=$PROFILE" + + TMP_PKG_DIR=$TMPDIR/tizen_${PROFILE}_pkgs + if [ -d $TMP_PKG_DIR ]; then rm -rf $TMP_PKG_DIR; fi + mkdir -p $TMP_PKG_DIR + + PKG_URL=$TIZEN_URL/$PROFILE/latest + + BUILD_XML_URL=$PKG_URL/$BUILD_XML + TMP_BUILD=$TMP_PKG_DIR/$BUILD_XML + TMP_REPOMD=$TMP_PKG_DIR/$REPOMD_XML + TMP_PRIMARY=$TMP_PKG_DIR/$PRIMARY_XML + TMP_PRIMARYGZ=${TMP_PRIMARY}.gz + + Fetch $BUILD_XML_URL $TMP_BUILD + + Debug "fetch $BUILD_XML_URL to $TMP_BUILD" + + TARGET_XPATH="//build/buildtargets/buildtarget[@name=\"$TARGET\"]/repo[@type=\"binary\"]/text()" + Xpath_get $TARGET_XPATH $TMP_BUILD + TARGET_PATH=$XPATH_RESULT + TARGET_URL=$PKG_URL/$TARGET_PATH + + REPOMD_URL=$TARGET_URL/repodata/repomd.xml + PRIMARY_XPATH='string(//*[local-name()="data"][@type="primary"]/*[local-name()="location"]/@href)' + + Fetch $REPOMD_URL $TMP_REPOMD + + Debug "fetch $REPOMD_URL to $TMP_REPOMD" + + Xpath_get $PRIMARY_XPATH $TMP_REPOMD + PRIMARY_XML_PATH=$XPATH_RESULT + PRIMARY_URL=$TARGET_URL/$PRIMARY_XML_PATH + + Fetch $PRIMARY_URL $TMP_PRIMARYGZ + + Debug "fetch $PRIMARY_URL to $TMP_PRIMARYGZ" + + gunzip $TMP_PRIMARYGZ + + Debug "unzip $TMP_PRIMARYGZ to $TMP_PRIMARY" +} + +fetch_tizen_pkgs() +{ + ARCH=$1 + PACKAGE_XPATH_TPL='string(//*[local-name()="metadata"]/*[local-name()="package"][*[local-name()="name"][text()="_PKG_"]][*[local-name()="arch"][text()="_ARCH_"]]/*[local-name()="location"]/@href)' + + PACKAGE_CHECKSUM_XPATH_TPL='string(//*[local-name()="metadata"]/*[local-name()="package"][*[local-name()="name"][text()="_PKG_"]][*[local-name()="arch"][text()="_ARCH_"]]/*[local-name()="checksum"]/text())' + + for pkg in ${@:2} + do + Inform "Fetching... $pkg" + XPATH=${PACKAGE_XPATH_TPL/_PKG_/$pkg} + XPATH=${XPATH/_ARCH_/$ARCH} + Xpath_get $XPATH $TMP_PRIMARY + PKG_PATH=$XPATH_RESULT + + XPATH=${PACKAGE_CHECKSUM_XPATH_TPL/_PKG_/$pkg} + XPATH=${XPATH/_ARCH_/$ARCH} + Xpath_get $XPATH $TMP_PRIMARY + CHECKSUM=$XPATH_RESULT + + PKG_URL=$TARGET_URL/$PKG_PATH + PKG_FILE=$(basename $PKG_PATH) + PKG_PATH=$TMPDIR/$PKG_FILE + + Debug "Download $PKG_URL to $PKG_PATH" + Fetch $PKG_URL $PKG_PATH true + + echo "$CHECKSUM $PKG_PATH" | sha256sum -c - > /dev/null + if [ $? -ne 0 ]; then + Error "Fail to fetch $PKG_URL to $PKG_PATH" + Debug "Checksum = $CHECKSUM" + exit 1 + fi + done +} + +Inform "Initialize arm base" +fetch_tizen_pkgs_init standard base +Inform "fetch common packages" +fetch_tizen_pkgs armv7l glibc glibc-devel +fetch_tizen_pkgs noarch linux-glibc-devel +fetch_tizen_pkgs armv7l libgcc libstdc++ libstdc++-devel libunwind libunwind-devel + + +Inform "Initialize standard unified" +fetch_tizen_pkgs_init standard unified +Inform "fetch nnfw packages" +fetch_tizen_pkgs armv7l gtest-devel tensorflow-lite-devel boost-devel libarmcl-devel boost-program-options boost-system boost-filesystem + diff --git a/tools/cross/armel/tizen.patch b/tools/cross/armel/tizen.patch new file mode 100644 index 000000000..d223427c9 --- /dev/null +++ b/tools/cross/armel/tizen.patch @@ -0,0 +1,18 @@ +diff -u -r a/usr/lib/libc.so b/usr/lib/libc.so +--- a/usr/lib/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-littlearm) +-GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux.so.3 ) ) +diff -u -r a/usr/lib/libpthread.so b/usr/lib/libpthread.so +--- a/usr/lib/libpthread.so 2016-12-30 23:00:19.408951841 +0900 ++++ b/usr/lib/libpthread.so 2016-12-30 23:00:39.068951801 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-littlearm) +-GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a ) ++GROUP ( libpthread.so.0 libpthread_nonshared.a ) diff --git a/tools/cross/build_android_rootfs.sh b/tools/cross/build_android_rootfs.sh new file mode 100755 index 000000000..3baea2e2c --- /dev/null +++ b/tools/cross/build_android_rootfs.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -x + +# Different from other architectures, the result does not contain only RootFS. +# $__Rootfs/bin : Toolchains +# $__Rootfs/sysroot : RootFS + +usage() +{ + echo "Usage: $0 [BuildArch] [NDKVersion] [APILevel]" + echo "BuildArch : arm or arm64" + echo "NDKVersion : r16b or higher (Must start with 'r')" + echo "APILevel : 27 or higher" + exit 1 +} + +__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +__BuildArch=arm64 +__NDKVersion=r16b +__APILevel="27" +__UnprocessedBuildArgs= + +for i in "$@" ; do + lowerI="$(echo $i | awk '{print tolower($0)}')" + case $lowerI in + -?|-h|--help) + usage + exit 1 + ;; + arm) + __BuildArch=arm + ;; + arm64) + __BuildArch=arm64 + ;; + r16b) + __NDKVersion=r16b + ;; + 27) + __APILevel="27" + ;; + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i" + ;; + esac +done + +__RootfsDir=${ROOTFS_DIR:-"${__CrossDir}/rootfs/${__BuildArch}.android"} +__TempDir=${TEMP_DIR:-"/tmp"} + +NDK_DIR=android-ndk-${__NDKVersion} +NDK_ZIP=${NDK_DIR}-linux-x86_64.zip + +echo "Downloading Android NDK" +wget -nv -nc https://dl.google.com/android/repository/$NDK_ZIP -O $__TempDir/$NDK_ZIP + +echo "Unzipping Android NDK" +unzip -qq -o $__TempDir/$NDK_ZIP -d $__TempDir + +echo "Generating standalone toolchain and rootfs to $__RootfsDir" + +$__TempDir/$NDK_DIR/build/tools/make-standalone-toolchain.sh --arch=$__BuildArch --platform=android-$__APILevel --install-dir=$__RootfsDir diff --git a/tools/cross/build_rootfs.sh b/tools/cross/build_rootfs.sh new file mode 100755 index 000000000..f52ca6338 --- /dev/null +++ b/tools/cross/build_rootfs.sh @@ -0,0 +1,122 @@ +#!/usr/bin/env bash +set -x + +usage() +{ + echo "Usage: $0 [BuildArch] [LinuxCodeName] [--skipunmount] [--skipproxy]" + echo "BuildArch can be: arm(default), arm64 and armel" + echo "LinuxCodeName - optional, Code name for Linux, can be: xenial(default), trusty" + echo " If BuildArch is armel, this can be tizen(default)" + echo "--skipunmount - optional, will skip the unmount of rootfs folder." + echo "--skipproxy - optional, will skip the adding proxy information for Seoul R&D Campus." + exit 1 +} + +__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +__InitialDir=$PWD +__UbuntuRepo="http://ports.ubuntu.com/" + +__BuildArch=arm +__UbuntuArch=armhf +__LinuxCodeName=xenial +__SkipUnmount=0 +__SkipProxy=0 + +# base development support +__UbuntuPackages="build-essential" + +# other development supports +__UbuntuPackages+=" libboost-all-dev" + +# symlinks fixer +__UbuntuPackages+=" symlinks" + +__UnprocessedBuildArgs= + +for i in "$@" ; do + lowerI="$(echo $i | awk '{print tolower($0)}')" + case $lowerI in + -?|-h|--help) + usage + exit 1 + ;; + arm) + __BuildArch=arm + __UbuntuArch=armhf + ;; + arm64) + __BuildArch=arm64 + __UbuntuArch=arm64 + ;; + armel) + __BuildArch=armel + __Tizen=tizen + __UbuntuArch= + __UbuntuRepo= + __LinuxCodeName= + ;; + tizen) + if [ "$__BuildArch" != "armel" ]; then + echo "Tizen is available only for armel." + usage; + exit 1; + fi + __Tizen=tizen + __UbuntuArch= + __UbuntuRepo= + __LinuxCodeName= + ;; + trusty) + __LinuxCodeName=trusty + ;; + xenial) + __LinuxCodeName=xenial + ;; + --skipunmount) + __SkipUnmount=1 + ;; + --skipproxy) + __SkipProxy=1 + ;; + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i" + ;; + esac +done + +__RootfsDir="$__CrossDir/rootfs/$__BuildArch" + +if [[ -n "$ROOTFS_DIR" ]]; then + __RootfsDir=$ROOTFS_DIR +fi + +if [ -d "$__RootfsDir" ]; then + if [ $__SkipUnmount == 0 ]; then + umount $__RootfsDir/* + fi + rm -rf $__RootfsDir +fi + +if [ $__SkipProxy == 0 ] && [ "$__Tizen" != "tizen" ]; then + mkdir -p $__RootfsDir/etc/apt/apt.conf.d + cp $__CrossDir/apt_proxy $__RootfsDir/etc/apt/apt.conf.d/90proxy +fi + +if [[ -n $__LinuxCodeName ]]; then + qemu-debootstrap --arch $__UbuntuArch $__LinuxCodeName $__RootfsDir $__UbuntuRepo + cp $__CrossDir/$__BuildArch/sources.list.$__LinuxCodeName $__RootfsDir/etc/apt/sources.list + chroot $__RootfsDir apt-get update + chroot $__RootfsDir apt-get -f -y install + chroot $__RootfsDir apt-get -y install $__UbuntuPackages + chroot $__RootfsDir symlinks -cr /usr + + if [ $__SkipUnmount == 0 ]; then + umount $__RootfsDir/* + fi +elif [ "$__Tizen" == "tizen" ]; then + ROOTFS_DIR=$__RootfsDir $__CrossDir/$__BuildArch/tizen-build-rootfs.sh +else + echo "Unsupported target platform." + usage; + exit 1 +fi diff --git a/tools/nnapi_test/CMakeLists.txt b/tools/nnapi_test/CMakeLists.txt new file mode 100644 index 000000000..cd9f2a524 --- /dev/null +++ b/tools/nnapi_test/CMakeLists.txt @@ -0,0 +1,5 @@ +list(APPEND SOURCES "src/nnapi_test.cc") + +add_executable(nnapi_test ${SOURCES}) +target_link_libraries(nnapi_test nnfw_support_tflite) +install(TARGETS nnapi_test DESTINATION bin) diff --git a/tools/nnapi_test/src/nnapi_test.cc b/tools/nnapi_test/src/nnapi_test.cc new file mode 100644 index 000000000..515311a3c --- /dev/null +++ b/tools/nnapi_test/src/nnapi_test.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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. + */ + +#include "tensorflow/contrib/lite/kernels/register.h" +#include "tensorflow/contrib/lite/model.h" + +#include "util/environment.h" + +#include "support/tflite/interp/FlatBufferBuilder.h" +#include "support/tflite/Diff.h" + +#include <iostream> + +using namespace tflite; +using namespace tflite::ops::builtin; + +int main(const int argc, char **argv) +{ + int verbose = 0; + int tolerance = 1; + + nnfw::util::env::IntAccessor("VERBOSE").access(verbose); + nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance); + + if (argc < 2) + { + std::cerr << "nnapi_test\n\n"; + std::cerr << "Usage: " << argv[0] << " <.tflite>\n\n"; + return 1; + } + + const auto filename = argv[1]; + + StderrReporter error_reporter; + + auto model = FlatBufferModel::BuildFromFile(filename, &error_reporter); + + const nnfw::support::tflite::interp::FlatBufferBuilder builder(*model); + + RandomTestParam param; + + param.verbose = verbose; + param.tolerance = tolerance; + + return RandomTestRunner{0, param}.run(builder); +} diff --git a/tools/test_driver/nnfw_kernel_env_list.txt b/tools/test_driver/nnfw_kernel_env_list.txt new file mode 100644 index 000000000..9cb3fc46c --- /dev/null +++ b/tools/test_driver/nnfw_kernel_env_list.txt @@ -0,0 +1,7 @@ +NNFW_KERNEL_convFloat32 +NNFW_KERNEL_averagePoolFloat32 +NNFW_KERNEL_maxPoolFloat32 +NNFW_KERNEL_softmaxFloat32 +NNFW_KERNEL_fullyConnectedFloat32 +NNFW_KERNEL_concatenationFloat32 +NNFW_KERNEL_reshapeGeneric diff --git a/tools/test_driver/print_to_json.sh b/tools/test_driver/print_to_json.sh new file mode 100755 index 000000000..857fa0423 --- /dev/null +++ b/tools/test_driver/print_to_json.sh @@ -0,0 +1,152 @@ +#!/bin/bash +# +# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved +# +# 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. + +function echo_to_file +{ + echo -e "$1" >> $RESULT_JSON +} + +function print_comma() # , +{ + echo_to_file "," +} + +function print_brace_start() # { +{ + echo_to_file "{" +} + +function print_brace_end() # } +{ + echo_to_file "}" +} + +function print_bracket_start() # "$NAME": [ +{ + local NAME=$1 + echo_to_file "\"$NAME\":[" +} + +function print_bracket_end() # ] +{ + echo_to_file "]" +} + +function print_key_value() # "$KEY": "$VALUE" +{ + local KEY=$1 + local VALUE=$2 + echo_to_file "\"$KEY\": \"$VALUE\"" +} + +function print_key_value_no_quot() # "$KEY": $VALUE +{ + local KEY=$1 + local VALUE=$2 + echo_to_file "\"$KEY\": $VALUE" +} + +function print_key_value_dbl() # "dblValue": $VALUE +{ + local VALUE=$1 + echo_to_file "\"dblValue\": $VALUE" # value should not include "" +} + +function print_results() +{ + local NAME=$1 + local MEAN=$2 + + print_bracket_start "results" + print_brace_start + print_key_value "name" "Mean_of_$NAME" + print_comma + print_key_value "unit" "ms" + print_comma + print_key_value_dbl "$MEAN" + print_brace_end + print_bracket_end +} + +function print_test() +{ + local NAME=$1 + local RESULT=$2 + + print_brace_start + print_key_value "name" "$NAME" + print_comma + print_results "$NAME" "$RESULT" + print_brace_end +} + +function print_tests() +{ + local MODEL=$1 + local REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark/$MODEL + local TEST_RESULTS=$(find $REPORT_MODEL_DIR -name "*.result" -exec basename {} \;) + local TEST_NUM=$(find $REPORT_MODEL_DIR -name "*.result" | wc -l) + + print_bracket_start "tests" + + local i=0 + for TEST in $TEST_RESULTS; do + local NAME=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $1}') + local RESULT=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $2}') + print_test $NAME $RESULT + if [[ $i -ne $TEST_NUM-1 ]]; then + print_comma + fi + i=$((i+1)) + done + + print_bracket_end +} + +function print_groups() +{ + local MODEL_NUM=$(cat $MODELS_FILE | wc -l) + local MODELS=$(cat $MODELS_FILE | awk '{print $1}' | uniq) + + print_bracket_start "groups" + + local i=0 + for MODEL in $MODELS; do + print_brace_start + print_key_value "name" " $MODEL" + print_comma + print_tests $MODEL + print_brace_end + if [[ $i -ne $MODEL_NUM-1 ]]; then + print_comma + fi + i=$((i+1)) + done + + print_bracket_end +} + +function print_to_json() +{ + RESULT_JSON=$ARTIFACT_PATH/report/benchmark_result.json + rm -f $RESULT_JSON + + MODELS_FILE=$ARTIFACT_PATH/report/benchmark/benchmark_models.txt + + print_brace_start + print_groups + print_brace_end +} diff --git a/tools/test_driver/test_driver.sh b/tools/test_driver/test_driver.sh new file mode 100755 index 000000000..3bff910f5 --- /dev/null +++ b/tools/test_driver/test_driver.sh @@ -0,0 +1,417 @@ +#!/bin/bash +# +# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved +# +# 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 +# NOTE: Supposed that this script would be executed with an artifact path. +# The artifact path has tests/(test suite) and Product/ +# Reference this PR(https://github.sec.samsung.net/STAR/nnfw/pull/375). + +function Usage() +{ + echo "Usage: ./$0 --artifactpath=. # run all tests" + echo "Usage: ./$0 --artifactpath=/home/dragon/nnfw --frameworktest --verification --benchmark # run fw test & verfication and benchmark" + echo "" + echo "--artifactpath - (should be passed) path that has tests/ and Product/" + echo "" + echo "Following three options are needed when you want to tests of specific types. If you don't pass any one, unittest and verification will be run" + echo "--unittest - (default=on) run unit test" + echo "--frameworktest - (default=off)run framework test" + echo "--verification - (default=on) run verification" + echo "" + echo "Following option is only needed when you want to test benchmark." + echo "--benchmark - (default=off) run benchmark" + echo "--benchmark_acl - (default=off) run benchmark-acl" + echo "" + echo "etc." + echo "--framework_driverbin - (default=../../Product/out/bin/tflite_run) runner for runnning framework tests" + echo "--verification_driverbin - (default=../../Product/out/bin/nnapi_test) runner for runnning verification tests" + echo "--benchmark_driverbin - (default=../../Product/out/bin/tflite_benchmark) runner for runnning benchmark" + echo "--runtestsh - (default=\$ARTIFACT_PATH/tests/framework/run_test.sh) run_test.sh with path where it is for framework test and verification" + echo "--unittestdir - (default=\$ARTIFACT_PATH/Product/out/unittest) directory that has unittest binaries for unit test" + echo "" + echo "--ldlibrarypath - (default=\$ARTIFACT_PATH/Product/out/lib) path that you want to include libraries" + echo "--usennapi - (default=on) declare USE_NNAPI=1" + echo "--nousennapi - (default=off) declare nothing about USE_NNAPI" + echo "--acl_envon - (default=off) declare envs for ACL" + echo "" +} + +ARTIFACT_PATH="" +FRAMEWORK_DRIVER_BIN="" +VERIFICATION_DRIVER_BIN="" +BENCHMARK_DRIVER_BIN="" +RUN_TEST_SH="" +UNIT_TEST_DIR="" +LD_LIBRARY_PATH_IN_SHELL="" +USE_NNAPI="USE_NNAPI=1" +ALLTEST_ON="true" +UNITTEST_ON="false" +FRAMEWORKTEST_ON="false" +VERIFICATION_ON="false" +BENCHMARK_ON="false" +BENCHMARK_ACL_ON="false" +MODEL_LIST="inceptionv3/inception_nonslim inceptionv3/inception_slim" +ACL_ENV_ON="false" + +for i in "$@" +do + case $i in + -h|--help|help) + Usage + exit 1 + ;; + --artifactpath=*) + ARTIFACT_PATH=${i#*=} + ;; + --framework_driverbin=*) + FRAMEWORK_DRIVER_BIN=${i#*=} + ;; + --verification_driverbin=*) + VERIFICATION_DRIVER_BIN=${i#*=} + ;; + --benchmark_driverbin=*) + BENCHMARK_DRIVER_BIN=${i#*=} + ;; + --runtestsh=*) + RUN_TEST_SH=${i#*=} + ;; + --unittestdir=*) + UNIT_TEST_DIR=${i#*=} + ;; + --ldlibrarypath=*) + LD_LIBRARY_PATH_IN_SHELL=${i#*=} + ;; + --usennapi) + USE_NNAPI="USE_NNAPI=1" + ;; + --nousennapi) + USE_NNAPI="" + ;; + --unittest) + ALLTEST_ON="false" + UNITTEST_ON="true" + ;; + --frameworktest) + ALLTEST_ON="false" + FRAMEWORKTEST_ON="true" + ;; + --verification) + ALLTEST_ON="false" + VERIFICATION_ON="true" + ;; + --benchmark) + ALLTEST_ON="false" + BENCHMARK_ON="true" + ;; + --benchmark_acl) + ALLTEST_ON="false" + BENCHMARK_ACL_ON="true" + ;; + --acl_envon) + ACL_ENV_ON="true" + ;; + *) + # Be careful that others params are handled as $ARTIFACT_PATH + ARTIFACT_PATH="$i" + ;; + esac + shift +done + +if [ ! -e "$ARTIFACT_PATH" ]; then + echo "Pass on with proper ARTIFACT_PATH" + exit 1 +fi +ARTIFACT_PATH="$(readlink -f $ARTIFACT_PATH)" + +if [ -z "$RUN_TEST_SH" ]; then + RUN_TEST_SH=$ARTIFACT_PATH/tests/framework/run_test.sh +fi + +if [ ! -e "$RUN_TEST_SH" ]; then + echo "Cannot find $RUN_TEST_SH" + exit 1 +fi + +if [ -z "$UNIT_TEST_DIR" ]; then + UNIT_TEST_DIR=$ARTIFACT_PATH/Product/out/unittest +fi + +if [ -z "$LD_LIBRARY_PATH_IN_SHELL" ]; then + LD_LIBRARY_PATH="$ARTIFACT_PATH/Product/out/lib:$LD_LIBRARY_PATH" +else + LD_LIBRARY_PATH="$LD_LIBRARY_PATH_IN_SHELL:$LD_LIBRARY_PATH" +fi + +# Set env +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH +if [ -n "$USE_NNAPI" ]; then + export "$USE_NNAPI" +fi + +function switch_nnfw_kernel_env() +{ + local switch=$1 # "ON" or "OFF" + local mode=$2 # "acl" or "neon" or "" + local NNFW_KERNEL_ENV_FILE=$ARTIFACT_PATH/tools/test_driver/nnfw_kernel_env_list.txt + + for ENV in $(cat $NNFW_KERNEL_ENV_FILE); do + if [[ "$switch" == "ON" ]]; then + export "$ENV=$mode" + else + unset "$ENV" + fi + done +} + +if [ "$ACL_ENV_ON" == "true" ]; then + switch_nnfw_kernel_env "ON" "acl" +fi + +# Run unittest in each part such as Runtime, ACL +if [ "$ALLTEST_ON" == "true" ] || [ "$UNITTEST_ON" == "true" ]; then + if [ ! -e "$ARTIFACT_PATH/report" ]; then + mkdir -p $ARTIFACT_PATH/report + fi + + echo "" + echo "============================================" + echo "Unittest start" + echo "============================================" + + num_unittest=0 + for TEST_BIN in `ls $UNIT_TEST_DIR`; do + num_unittest=$((num_unittest+1)) + echo "============================================" + echo "Starting set $num_unittest: $TEST_BIN..." + echo "============================================" + $UNIT_TEST_DIR/$TEST_BIN --gtest_output=xml:$ARTIFACT_PATH/report/$TEST_BIN.xml + echo "============================================" + echo "Finishing set $num_unittest: $TEST_BIN..." + echo "============================================" + done + echo "============================================" + echo "Completed total $num_unittest set of unittest" + echo "Unittest end" + echo "============================================" +fi + +# Run tflite_run with various tflite models +if [ "$FRAMEWORKTEST_ON" == "true" ]; then + if [ -z "$FRAMEWORK_DRIVER_BIN" ]; then + FRAMEWORK_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_run + fi + + if [ ! -e "$ARTIFACT_PATH/report" ]; then + mkdir -p $ARTIFACT_PATH/report + fi + + echo "" + echo "============================================" + echo "Framework Test with tflite_run..." + $RUN_TEST_SH --driverbin=$FRAMEWORK_DRIVER_BIN \ + --reportdir=$ARTIFACT_PATH/report \ + --tapname=framework_test.tap \ + > $ARTIFACT_PATH/report/framework_test.log 2>&1 + echo "============================================" + cat $ARTIFACT_PATH/report/framework_test.tap + echo "============================================" + echo "" +fi + +# Run nnapi_test with various tflite models +if [ "$ALLTEST_ON" == "true" ] || [ "$VERIFICATION_ON" == "true" ]; then + if [ -z "$VERIFICATION_DRIVER_BIN" ]; then + VERIFICATION_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/nnapi_test + fi + + if [ ! -e "$ARTIFACT_PATH/report" ]; then + mkdir -p $ARTIFACT_PATH/report + fi + + echo "" + echo "============================================" + echo "Verification with nnapi_test..." + $RUN_TEST_SH --driverbin=$VERIFICATION_DRIVER_BIN \ + --reportdir=$ARTIFACT_PATH/report \ + --tapname=verification.tap \ + > $ARTIFACT_PATH/report/verification.log 2>&1 + echo "============================================" + cat $ARTIFACT_PATH/report/verification.tap + echo "============================================" + echo "" +fi + +# Benchmark test +function get_result_of_benchmark_test() +{ + local RUN_TEST_SH=$1 + local DRIVER_BIN=$2 + local MODEL=$3 + local LOG_FILE=$4 + + $RUN_TEST_SH --driverbin=$DRIVER_BIN $MODEL > $LOG_FILE 2>&1 + + local RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'` + echo "$RESULT" +} + +function print_result_of_benchmark_test() +{ + local NAME=$1 + local RESULT=$2 + local RESULT_FILE=$3 + + echo "$NAME $RESULT" > $RESULT_FILE +} + +function run_benchmark_test() +{ + local DRIVER_BIN= + local LOG_FILE= + local RESULT_FILE= + local RESULT= + local REPORT_MODEL_DIR= + + if [ -z "$BENCHMARK_DRIVER_BIN" ]; then + DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_benchmark + else + DRIVER_BIN=$BENCHMARK_DRIVER_BIN + fi + + export COUNT=5 + echo "============================================" + local i=0 + for MODEL in $MODEL_LIST; do + echo "Benchmark test with tflite_benchmark & `echo $MODEL`" + echo $MODEL >> $MODELS_FILE + + REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark/$MODEL + mkdir -p $REPORT_MODEL_DIR + + # TFLite+CPU + LOG_FILE=$REPORT_MODEL_DIR/tflite_cpu.txt + RESULT_FILE=$REPORT_MODEL_DIR/tflite_cpu.result + echo -n "TFLite + CPU................... " + unset USE_NNAPI + RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE) + echo "$RESULT ms" + print_result_of_benchmark_test "TFLite_CPU" $RESULT $RESULT_FILE + + + # TFLite+NNAPI(CPU fallback) + LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.txt + RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.result + echo -n "TFLite + NNAPI(CPU)............ " + export USE_NNAPI=1 + RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE) + echo "$RESULT ms" + print_result_of_benchmark_test "TFLite_NNAPI_CPU" $RESULT $RESULT_FILE + + # TFLite+NNAPI(ACL) + LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.txt + RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.result + echo -n "TFLite + NNAPI(ACL)............ " + switch_nnfw_kernel_env "ON" "acl" + RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE) + echo "$RESULT ms" + print_result_of_benchmark_test "TFLite_NNAPI_ACL" $RESULT $RESULT_FILE + unset USE_NNAPI + switch_nnfw_kernel_env "OFF" + + if [[ $i -ne $(echo $MODEL_LIST | wc -w)-1 ]]; then + echo "" + fi + i=$((i+1)) + done + echo "============================================" + unset COUNT +} + +function run_benchmark_acl() +{ + local REPORT_DIR=$ARTIFACT_PATH/report/benchmark + local DRIVER_DIR=$ARTIFACT_PATH/Product/out/bin + local LOG_FILE="" + local RESULT_FILE="" + local RESULT="" + + export COUNT=5 + echo "============================================" + local i=0 + for BENCHMARK_ACL_BIN in $(ls $DRIVER_DIR/benchmark_*); do + BENCHMARK_ACL_BIN_BASENAME=$(basename $BENCHMARK_ACL_BIN) + mkdir -p $REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME + echo "Benchmark/acl test by $BENCHMARK_ACL_BIN_BASENAME" + echo $BENCHMARK_ACL_BIN_BASENAME >> $MODELS_FILE + + # ACL(NEON) + LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.txt + RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.result + echo -n "ACL(NEON)...... " + $BENCHMARK_ACL_BIN 0 > $LOG_FILE 2>&1 + RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'` + echo "$RESULT ms" + echo "ACL(NEON)" $RESULT > $RESULT_FILE + + # ACL(OpenCL) + LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.txt + RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.result + echo -n "ACL(OpenCL).... " + $BENCHMARK_ACL_BIN 1 > $LOG_FILE 2>&1 + RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'` + echo "$RESULT ms" + echo "ACL(OpenCL)" $RESULT > $RESULT_FILE + + if [[ $i -ne $(ls $DRIVER_DIR/benchmark_* | wc -w)-1 ]]; then + echo "" + fi + i=$((i+1)) + done + echo "============================================" + unset COUNT +} + +if [ "$BENCHMARK_ON" == "true" ] || [ "$BENCHMARK_ACL_ON" == "true" ]; then + if [ ! -e "$ARTIFACT_PATH/report" ]; then + mkdir -p $ARTIFACT_PATH/report + fi + REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark + mkdir -p $REPORT_MODEL_DIR + MODELS_FILE=$ARTIFACT_PATH/report/benchmark/benchmark_models.txt + rm -f $MODELS_FILE +fi + +# Run tflite_benchmark with Iv3_non_slim & Iv3_slim +if [ "$BENCHMARK_ON" == "true" ]; then + echo "" + run_benchmark_test + echo "" +fi + +# Run benchmark/acl/benchmark_googlenet,mobilenet and inception_v3 +if [ "$BENCHMARK_ACL_ON" == "true" ]; then + echo "" + run_benchmark_acl + echo "" +fi + +# make json file +if [ "$BENCHMARK_ON" == "true" ] || [ "$BENCHMARK_ACL_ON" == "true" ]; then + # functions to fill json with benchmark results + source $ARTIFACT_PATH/tools/test_driver/print_to_json.sh + print_to_json +fi |