From a9ec2b5cd641dfd6198fbf773358b1cbc2101607 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Sat, 22 Jun 2019 01:18:53 +0200 Subject: [PATCH] Building TFLite runtime on Linux/macOS/Windows --- taskcluster/darwin-amd64-tflite-opt.yml | 17 ++++++++++++++++ taskcluster/host-build.sh | 8 +++++++- taskcluster/linux-amd64-tflite-opt.yml | 24 +++++++++++++++++++++++ taskcluster/package.sh | 2 ++ taskcluster/tc-tests-utils.sh | 26 ++++++++++++++++++++++--- taskcluster/win-amd64-tflite-opt.yml | 17 ++++++++++++++++ taskcluster/win-build.sh | 6 +++++- taskcluster/win-opt-base.tyml | 1 + taskcluster/win-package.sh | 4 ++-- 9 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 taskcluster/darwin-amd64-tflite-opt.yml create mode 100644 taskcluster/linux-amd64-tflite-opt.yml create mode 100644 taskcluster/win-amd64-tflite-opt.yml diff --git a/taskcluster/darwin-amd64-tflite-opt.yml b/taskcluster/darwin-amd64-tflite-opt.yml new file mode 100644 index 00000000..5b1eaa70 --- /dev/null +++ b/taskcluster/darwin-amd64-tflite-opt.yml @@ -0,0 +1,17 @@ +build: + template_file: darwin-opt-base.tyml + routes: + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.osx-tflite" + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.${event.head.sha}.osx-tflite" + - "index.project.deepspeech.deepspeech.native_client.osx-tflite.${event.head.sha}" + - "notify.irc-channel.${notifications.irc}.on-exception" + - "notify.irc-channel.${notifications.irc}.on-failed" + tensorflow: "https://index.taskcluster.net/v1/task/project.deepspeech.tensorflow.pip.r1.13.174b4760eb1cba50482ed7d890e654060d360e4b.osx/artifacts/public/home.tar.xz" + scripts: + build: "taskcluster/host-build.sh tflite" + package: "taskcluster/package.sh" + nc_asset_name: "native_client.amd64.tflite.osx.tar.xz" + maxRunTime: 14400 + metadata: + name: "DeepSpeech OSX AMD64 TFLite" + description: "Building DeepSpeech for OSX AMD64, TFLite, optimized version" diff --git a/taskcluster/host-build.sh b/taskcluster/host-build.sh index 908bfcdf..2488a14a 100755 --- a/taskcluster/host-build.sh +++ b/taskcluster/host-build.sh @@ -2,6 +2,8 @@ set -xe +runtime=$1 + source $(dirname "$0")/tc-tests-utils.sh source ${DS_ROOT_TASK}/DeepSpeech/tf/tc-vars.sh @@ -11,7 +13,11 @@ BAZEL_TARGETS=" //native_client:generate_trie " -BAZEL_BUILD_FLAGS="${BAZEL_OPT_FLAGS} ${BAZEL_EXTRA_FLAGS}" +if [ "${runtime}" = "tflite" ]; then + BAZEL_BUILD_TFLITE="--define=runtime=tflite" +fi; +BAZEL_BUILD_FLAGS="${BAZEL_BUILD_TFLITE} ${BAZEL_OPT_FLAGS} ${BAZEL_EXTRA_FLAGS}" + BAZEL_ENV_FLAGS="TF_NEED_CUDA=0" SYSTEM_TARGET=host diff --git a/taskcluster/linux-amd64-tflite-opt.yml b/taskcluster/linux-amd64-tflite-opt.yml new file mode 100644 index 00000000..22901461 --- /dev/null +++ b/taskcluster/linux-amd64-tflite-opt.yml @@ -0,0 +1,24 @@ +build: + template_file: linux-opt-base.tyml + routes: + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.tflite" + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.${event.head.sha}.tflite" + - "index.project.deepspeech.deepspeech.native_client.tflite.${event.head.sha}" + - "notify.irc-channel.${notifications.irc}.on-exception" + - "notify.irc-channel.${notifications.irc}.on-failed" + system_setup: + > + ${nodejs.packages_trusty.prep_8} && ${nodejs.packages_trusty.apt_pinning} + && apt-get -qq update && apt-get -qq -y install nodejs python-yaml && + apt-get -qq -y install ${python.packages_trusty.apt} && ${swig.packages.install_script} + system_config: + > + ${swig.patch_nodejs.linux} + tensorflow: "https://index.taskcluster.net/v1/task/project.deepspeech.tensorflow.pip.r1.13.174b4760eb1cba50482ed7d890e654060d360e4b.cpu/artifacts/public/home.tar.xz" + scripts: + build: "taskcluster/host-build.sh tflite" + package: "taskcluster/package.sh" + nc_asset_name: "native_client.amd64.tflite.linux.tar.xz" + metadata: + name: "DeepSpeech Linux AMD64 TFLite" + description: "Building DeepSpeech for Linux/AMD64, TFLite, optimized version" diff --git a/taskcluster/package.sh b/taskcluster/package.sh index 9828a5e5..2acc737a 100755 --- a/taskcluster/package.sh +++ b/taskcluster/package.sh @@ -10,6 +10,8 @@ cp ${DS_ROOT_TASK}/DeepSpeech/tf/bazel*.log ${TASKCLUSTER_ARTIFACTS}/ package_native_client "native_client.tar.xz" +package_libdeepspeech_as_zip "libdeepspeech.zip" + if [ -d ${DS_ROOT_TASK}/DeepSpeech/ds/wheels ]; then cp ${DS_ROOT_TASK}/DeepSpeech/ds/wheels/* ${TASKCLUSTER_ARTIFACTS}/ cp ${DS_ROOT_TASK}/DeepSpeech/ds/native_client/javascript/deepspeech-*.tgz ${TASKCLUSTER_ARTIFACTS}/ diff --git a/taskcluster/tc-tests-utils.sh b/taskcluster/tc-tests-utils.sh index 0aa222ef..70fdf0ca 100755 --- a/taskcluster/tc-tests-utils.sh +++ b/taskcluster/tc-tests-utils.sh @@ -1066,7 +1066,7 @@ do_deepspeech_python_build() mkdir -p wheels SETUP_FLAGS="" - if [ "${rename_to_gpu}" ]; then + if [ "${rename_to_gpu}" = "--cuda" ]; then SETUP_FLAGS="--project_name deepspeech-gpu" fi @@ -1199,7 +1199,7 @@ do_deepspeech_nodejs_build() clean node-wrapper done; - if [ "${rename_to_gpu}" ]; then + if [ "${rename_to_gpu}" = "--cuda" ]; then make -C native_client/javascript clean npm-pack PROJECT_NAME=deepspeech-gpu else make -C native_client/javascript clean npm-pack @@ -1235,7 +1235,7 @@ do_deepspeech_npm_package() curl -L https://queue.taskcluster.net/v1/task/${dep}/artifacts/public/wrapper.tar.gz | tar -C native_client/javascript -xzvf - done; - if [ "${rename_to_gpu}" ]; then + if [ "${rename_to_gpu}" = "--cuda" ]; then make -C native_client/javascript clean npm-pack PROJECT_NAME=deepspeech-gpu else make -C native_client/javascript clean npm-pack @@ -1347,6 +1347,26 @@ package_native_client_ndk() | pixz -9 > "${artifacts_dir}/${artifact_name}" } +package_libdeepspeech_as_zip() +{ + tensorflow_dir=${DS_TFDIR} + artifacts_dir=${TASKCLUSTER_ARTIFACTS} + artifact_name=$1 + + if [ ! -d ${tensorflow_dir} -o ! -d ${artifacts_dir} ]; then + echo "Missing directory. Please check:" + echo "tensorflow_dir=${tensorflow_dir}" + echo "artifacts_dir=${artifacts_dir}" + exit 1 + fi; + + if [ -z "${artifact_name}" ]; then + echo "Please specify artifact name." + fi; + + zip -r9 --junk-paths "${artifacts_dir}/${artifact_name}" ${tensorflow_dir}/bazel-bin/native_client/libdeepspeech.so +} + android_sdk_accept_licenses() { pushd "${ANDROID_SDK_HOME}" diff --git a/taskcluster/win-amd64-tflite-opt.yml b/taskcluster/win-amd64-tflite-opt.yml new file mode 100644 index 00000000..8b77791e --- /dev/null +++ b/taskcluster/win-amd64-tflite-opt.yml @@ -0,0 +1,17 @@ +build: + template_file: win-opt-base.tyml + routes: + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.win-tflite" + - "index.project.deepspeech.deepspeech.native_client.${event.head.branchortag}.${event.head.sha}.win-tflite" + - "index.project.deepspeech.deepspeech.native_client.win-tflite.${event.head.sha}" + - "notify.irc-channel.${notifications.irc}.on-exception" + - "notify.irc-channel.${notifications.irc}.on-failed" + tensorflow: "https://index.taskcluster.net/v1/task/project.deepspeech.tensorflow.pip.r1.13.174b4760eb1cba50482ed7d890e654060d360e4b.win/artifacts/public/home.tar.xz" + scripts: + build: "taskcluster/win-build.sh tflite" + package: "taskcluster/win-package.sh" + nc_asset_name: "native_client.amd64.tflite.win.tar.xz" + maxRunTime: 14400 + metadata: + name: "DeepSpeech Windows AMD64 TFLite" + description: "Building DeepSpeech for Windows AMD64, TFLite, optimized version" diff --git a/taskcluster/win-build.sh b/taskcluster/win-build.sh index 7d89a0e5..464b91c8 100755 --- a/taskcluster/win-build.sh +++ b/taskcluster/win-build.sh @@ -3,6 +3,7 @@ set -xe cuda=$1 +runtime=$1 source $(dirname "$0")/tc-tests-utils.sh @@ -19,7 +20,10 @@ if [ "${cuda}" = "--cuda" ]; then PROJECT_NAME="DeepSpeech-GPU" else PROJECT_NAME="DeepSpeech" - BAZEL_BUILD_FLAGS="${BAZEL_OPT_FLAGS} ${BAZEL_EXTRA_FLAGS}" + if [ "${runtime}" = "tflite" ]; then + BAZEL_BUILD_TFLITE="--define=runtime=tflite" + fi; + BAZEL_BUILD_FLAGS="${BAZEL_BUILD_TFLITE} ${BAZEL_OPT_FLAGS} ${BAZEL_EXTRA_FLAGS}" BAZEL_ENV_FLAGS="TF_NEED_CUDA=0" fi diff --git a/taskcluster/win-opt-base.tyml b/taskcluster/win-opt-base.tyml index 7dfb3802..4e6bb79d 100644 --- a/taskcluster/win-opt-base.tyml +++ b/taskcluster/win-opt-base.tyml @@ -65,6 +65,7 @@ payload: cd $TASKCLUSTER_TASK_DIR && pacman --noconfirm -R bsdtar && pacman --noconfirm -S tar make && + pacman --noconfirm -S zip && (pacman --noconfirm -S patch swig && (for patch_file in $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/native_client/swig_node_v12_*.patch ; do patch -d /usr/share/swig/4.0.0/ -p2 < $patch_file; done) ) && diff --git a/taskcluster/win-package.sh b/taskcluster/win-package.sh index 546f6afd..f916a91c 100755 --- a/taskcluster/win-package.sh +++ b/taskcluster/win-package.sh @@ -2,8 +2,6 @@ set -xe -arm_flavor=$1 - source $(dirname "$0")/tc-tests-utils.sh mkdir -p ${TASKCLUSTER_ARTIFACTS} || true @@ -12,6 +10,8 @@ cp ${DS_ROOT_TASK}/DeepSpeech/tf/bazel*.log ${TASKCLUSTER_ARTIFACTS}/ package_native_client "native_client.tar.xz" +package_libdeepspeech_as_zip "libdeepspeech.zip" + cp ${DS_ROOT_TASK}/DeepSpeech/ds/native_client/dotnet/*.nupkg ${TASKCLUSTER_ARTIFACTS}/ cp ${DS_ROOT_TASK}/DeepSpeech/ds/native_client/dotnet/DeepSpeechConsole/bin/x64/Release/DeepSpeechConsole.exe ${TASKCLUSTER_ARTIFACTS}/