diff --git a/ci/adb_push_and_run.sh b/ci/adb_push_and_run.sh new file mode 100755 index 0000000..a4a0c12 --- /dev/null +++ b/ci/adb_push_and_run.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +# echo "${@:2}" +adb push $1 /data/local/tmp/`basename $1` && adb shell "data/local/tmp/`basename $1` ${@:2}" diff --git a/android_aar/.gitignore b/ci/android_aar/.gitignore similarity index 100% rename from android_aar/.gitignore rename to ci/android_aar/.gitignore diff --git a/android_aar/README.md b/ci/android_aar/README.md similarity index 100% rename from android_aar/README.md rename to ci/android_aar/README.md diff --git a/android_aar/build.gradle b/ci/android_aar/build.gradle similarity index 100% rename from android_aar/build.gradle rename to ci/android_aar/build.gradle diff --git a/android_aar/dnnlibrary/.gitignore b/ci/android_aar/dnnlibrary/.gitignore similarity index 100% rename from android_aar/dnnlibrary/.gitignore rename to ci/android_aar/dnnlibrary/.gitignore diff --git a/android_aar/dnnlibrary/build.gradle b/ci/android_aar/dnnlibrary/build.gradle similarity index 100% rename from android_aar/dnnlibrary/build.gradle rename to ci/android_aar/dnnlibrary/build.gradle diff --git a/android_aar/dnnlibrary/proguard-rules.pro b/ci/android_aar/dnnlibrary/proguard-rules.pro similarity index 100% rename from android_aar/dnnlibrary/proguard-rules.pro rename to ci/android_aar/dnnlibrary/proguard-rules.pro diff --git a/android_aar/dnnlibrary/src/main/AndroidManifest.xml b/ci/android_aar/dnnlibrary/src/main/AndroidManifest.xml similarity index 100% rename from android_aar/dnnlibrary/src/main/AndroidManifest.xml rename to ci/android_aar/dnnlibrary/src/main/AndroidManifest.xml diff --git a/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/Model.java b/ci/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/Model.java similarity index 100% rename from android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/Model.java rename to ci/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/Model.java diff --git a/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/ModelBuilder.java b/ci/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/ModelBuilder.java similarity index 100% rename from android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/ModelBuilder.java rename to ci/android_aar/dnnlibrary/src/main/java/me/daquexian/dnnlibrary/ModelBuilder.java diff --git a/android_aar/gradle.properties b/ci/android_aar/gradle.properties similarity index 100% rename from android_aar/gradle.properties rename to ci/android_aar/gradle.properties diff --git a/android_aar/gradle/wrapper/gradle-wrapper.jar b/ci/android_aar/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from android_aar/gradle/wrapper/gradle-wrapper.jar rename to ci/android_aar/gradle/wrapper/gradle-wrapper.jar diff --git a/android_aar/gradle/wrapper/gradle-wrapper.properties b/ci/android_aar/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from android_aar/gradle/wrapper/gradle-wrapper.properties rename to ci/android_aar/gradle/wrapper/gradle-wrapper.properties diff --git a/android_aar/gradlew b/ci/android_aar/gradlew similarity index 100% rename from android_aar/gradlew rename to ci/android_aar/gradlew diff --git a/android_aar/gradlew.bat b/ci/android_aar/gradlew.bat similarity index 100% rename from android_aar/gradlew.bat rename to ci/android_aar/gradlew.bat diff --git a/android_aar/settings.gradle b/ci/android_aar/settings.gradle similarity index 100% rename from android_aar/settings.gradle rename to ci/android_aar/settings.gradle diff --git a/appimage/onnx2daq.desktop b/ci/appimage/onnx2daq.desktop similarity index 100% rename from appimage/onnx2daq.desktop rename to ci/appimage/onnx2daq.desktop diff --git a/appimage/onnx2daq.png b/ci/appimage/onnx2daq.png similarity index 100% rename from appimage/onnx2daq.png rename to ci/appimage/onnx2daq.png diff --git a/ci/build_aar.sh b/ci/build_aar.sh new file mode 100755 index 0000000..7604734 --- /dev/null +++ b/ci/build_aar.sh @@ -0,0 +1,54 @@ +#! /usr/bin/env bash + +set -e + +nproc=$(ci/get_cores.sh) +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "The system is Mac OS X, alias sed to gsed" + export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" + echo "Output of sed -v:" + sed --version +fi + +MY_ANDROID_HOME="${ANDROID_HOME:-$HOME/Android/Sdk}" +MY_ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$MY_ANDROID_HOME/ndk-bundle}" +JNI_BUILD_DIR=build_jni_tmp +rm -rf ${JNI_BUILD_DIR} && mkdir ${JNI_BUILD_DIR} && pushd ${JNI_BUILD_DIR} +cmake -DCMAKE_SYSTEM_NAME=Android -DCMAKE_TOOLCHAIN_FILE=${MY_ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake -DANDROID_CPP_FEATURES=exceptions -DANDROID_PLATFORM=android-21 -DANDROID_ABI=arm64-v8a -DBNN_BUILD_JNI=ON -DBNN_BUILD_TEST=OFF -DBNN_BUILD_BENCHMARK=OFF .. +cmake --build . -- -j$nproc +popd +mkdir -p ci/android_aar/dabnn/src/main/jniLibs/arm64-v8a +cp ${JNI_BUILD_DIR}/dabnn/jni/libdabnn-jni.so ci/android_aar/dabnn/src/main/jniLibs/arm64-v8a/ + +# Increase version code and update version name + +echo "Build source branch: $BUILD_SOURCEBRANCH" + +if (($# == 0)); then + if [[ $BUILD_SOURCEBRANCH == refs/tags/v* ]]; then + ver=`echo $BUILD_SOURCEBRANCH | cut -c 12-` + else + echo "HEAD is not tagged as a version, skip deploy aar" + exit 0 + fi +elif (( $# == 1 )); then + ver=$1 +fi +echo "ver=$ver" + +sed -i -E "s/versionName .+/versionName \"v$ver\"/" ci/android_aar/dabnn/build.gradle +sed -i -E "s/publishVersion = .+/publishVersion = \'$ver\'/" ci/android_aar/dabnn/build.gradle + +cat ci/android_aar/dabnn/build.gradle + +pushd ci/android_aar +ANDROID_HOME=$MY_ANDROID_HOME ./gradlew clean build + +# Publishing is only for myself +if [[ -z $BINTRAY_KEY ]]; then + echo "BINTRAY_KEY is not set, skip bintray upload" +else + echo "Publishing.." + ANDROID_HOME=$MY_ANDROID_HOME ./gradlew bintrayUpload -PbintrayUser=daquexian566 -PbintrayKey=$BINTRAY_KEY -PdryRun=false +fi +popd diff --git a/ci/build_appimage.sh b/ci/build_appimage.sh new file mode 100755 index 0000000..45c7a5e --- /dev/null +++ b/ci/build_appimage.sh @@ -0,0 +1,8 @@ +wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage +wget https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-x86_64.AppImage + +chmod +x linuxdeploy-*.AppImage +mkdir -p ci/appimage/appdir/usr/bin +cp build_onnx2bnn/tools/onnx2bnn/onnx2bnn ci/appimage/appdir/usr/bin/ +./linuxdeploy-x86_64.AppImage --appdir ci/appimage/appdir -d ci/appimage/onnx2bnn.desktop -i ci/appimage/onnx2bnn.png --output appimage +mv `ls onnx2bnn-*.AppImage` onnx2bnn.AppImage diff --git a/ci/build_dnnlibrary.sh b/ci/build_dnnlibrary.sh new file mode 100755 index 0000000..cc65a33 --- /dev/null +++ b/ci/build_dnnlibrary.sh @@ -0,0 +1,10 @@ +#! /usr/bin/env bash +set -e + +echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'ndk-bundle' +nproc=$(ci/get_cores.sh) + +mkdir build_dabnn && cd build_dabnn +cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release .. +cmake --build . -- -j$nproc +cd - diff --git a/ci/build_onnx2daq.sh b/ci/build_onnx2daq.sh new file mode 100755 index 0000000..03bc2a5 --- /dev/null +++ b/ci/build_onnx2daq.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env bash +set -e + +nproc=$(ci/get_cores.sh) + +mkdir build_onnx2bnn && cd build_onnx2bnn +cmake .. +cmake --build . -- -j$nproc +cd - diff --git a/ci/dnnlibrary_build_and_test.yml b/ci/dnnlibrary_build_and_test.yml new file mode 100644 index 0000000..94c9373 --- /dev/null +++ b/ci/dnnlibrary_build_and_test.yml @@ -0,0 +1,47 @@ +trigger: + branches: + include: + - master + tags: + include: + - v* + paths: + include: + - '*' + exclude: + - README.md + - docs/* +pr: + branches: + include: + - '*' + paths: + include: + - '*' + exclude: + - README.md + - docs/* + +pool: + vmImage: 'macOS-10.14' +steps: +- checkout: self + submodules: true +- bash: brew install watch gnu-sed + displayName: Install watch and gnu-sed +- bash: ci/build_dabnn.sh + displayName: Build +- bash: ci/start_android_emulator.sh + displayName: Start Android Emulator +- bash: ci/adb_push_and_run.sh build_dabnn/tests/bconv_test + displayName: Binary Conv Test +- bash: ci/adb_push_and_run.sh build_dabnn/tests/bgemm_test + displayName: Binary Gemm Test +- bash: ci/download_models.sh + displayName: Download Models +- bash: ci/adb_push_and_run.sh build_dabnn/tests/net_test + displayName: Model Test +- bash: ci/build_aar.sh + env: + BINTRAY_KEY: $(bintrayKey) + displayName: Build and Publish AAR package diff --git a/ci/download_models.sh b/ci/download_models.sh new file mode 100755 index 0000000..bce81e7 --- /dev/null +++ b/ci/download_models.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash + +wget "https://drive.google.com/uc?export=download&id=1FYqF5BvYO2kl13bn28sheKtgverkbbQN" -O model_imagenet.dab +adb push model_imagenet.dab /data/local/tmp +wget "https://drive.google.com/uc?export=download&id=1frtRL1O0zhtJvPFbhE8COFl1-WWHIaOW" -O model_imagenet_stem.dab +adb push model_imagenet_stem.dab /data/local/tmp/ diff --git a/ci/get_cores.sh b/ci/get_cores.sh new file mode 100755 index 0000000..32d5de1 --- /dev/null +++ b/ci/get_cores.sh @@ -0,0 +1,5 @@ +if [[ "$OSTYPE" == "drawin*" ]]; then + echo $(sysctl -n hw.physicalcpu) +else + echo $(nproc) +fi diff --git a/ci/onnx2daq_build.yml b/ci/onnx2daq_build.yml new file mode 100644 index 0000000..c38a2ff --- /dev/null +++ b/ci/onnx2daq_build.yml @@ -0,0 +1,79 @@ +trigger: + branches: + include: + - master + tags: + include: + - v* + paths: + include: + - '*' + exclude: + - README.md + - docs/* + # not trigger onnx2bnn build when only dabnn is edited + - dabnn/* +pr: + branches: + include: + - '*' + paths: + include: + - '*' + exclude: + - README.md + - docs/* + # not trigger onnx2bnn build when only dabnn is edited + - dabnn/* + +jobs: +- job: LinuxAppImage + pool: + vmImage: 'ubuntu-16.04' + steps: + - checkout: self + submodules: true + - script: sudo apt install -y protobuf-compiler libprotobuf-dev + displayName: Install protobuf + - bash: ci/build_onnx2bnn.sh + displayName: Build + - bash: ci/build_appimage.sh + displayName: Build AppImage + - task: CopyFiles@2 + inputs: + contents: 'onnx2bnn.AppImage' + targetFolder: $(Build.ArtifactStagingDirectory) + - template: template_onnx2bnn_publish_artifacts.yml + - template: template_onnx2bnn_github_release.yml +- job: Windows + pool: + vmImage: 'vs2017-win2016' + steps: + - checkout: self + submodules: true + - template: template_onnx2bnn_build_python_all_version.yml + - task: CopyFiles@2 + inputs: + sourceFolder: '.setuptools-cmake-build\tools\onnx2bnn\Release\' + contents: 'onnx2bnn.exe' + targetFolder: $(Build.ArtifactStagingDirectory) + - template: template_onnx2bnn_publish_artifacts.yml + - template: template_onnx2bnn_github_release.yml + - template: template_onnx2bnn_upload_to_pypi.yml +- job: macOS + pool: + vmImage: 'macOS-10.14' + steps: + - checkout: self + submodules: true + - template: template_onnx2bnn_build_python_all_version.yml + - script: 'cp .setuptools-cmake-build/tools/onnx2bnn/onnx2bnn .setuptools-cmake-build/tools/onnx2bnn/onnx2bnn-macos' + displayName: 'Rename onnx2bnn' + - task: CopyFiles@2 + inputs: + sourceFolder: '.setuptools-cmake-build/tools/onnx2bnn' + contents: 'onnx2bnn-macos' + targetFolder: $(Build.ArtifactStagingDirectory) + - template: template_onnx2bnn_publish_artifacts.yml + - template: template_onnx2bnn_github_release.yml + - template: template_onnx2bnn_upload_to_pypi.yml diff --git a/ci/start_android_emulator.sh b/ci/start_android_emulator.sh new file mode 100755 index 0000000..3a905b1 --- /dev/null +++ b/ci/start_android_emulator.sh @@ -0,0 +1,24 @@ +#! /usr/bin/env bash +set -e + +export TERM=xterm + +echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-25;google_apis;arm64-v8a' + +echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n android_emulator -k 'system-images;android-25;google_apis;arm64-v8a' --force + +echo "Starting emulator" + +# Start emulator in background +nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -no-snapshot -no-audio & + +# start server in advance, so that the result of watch will only change when device gets online +$ANDROID_HOME/platform-tools/adb start-server + +watch -g -n 1 '$ANDROID_HOME/platform-tools/adb devices | grep -c device$' + +echo "Emulator is online" + +$ANDROID_HOME/platform-tools/adb devices + +echo "Emulator started" diff --git a/ci/template_onnx2daq_build_python.yml b/ci/template_onnx2daq_build_python.yml new file mode 100644 index 0000000..2c3487e --- /dev/null +++ b/ci/template_onnx2daq_build_python.yml @@ -0,0 +1,6 @@ +steps: +- script: python -m pip install --user --upgrade setuptools wheel twine + displayName: Install setuptools, wheel and twine +- script: python setup.py bdist_wheel + workingDirectory: tools/onnx2bnn/python/ + displayName: Build onnx2bnn python package diff --git a/ci/template_onnx2daq_build_python_all_version.yml b/ci/template_onnx2daq_build_python_all_version.yml new file mode 100644 index 0000000..74e5380 --- /dev/null +++ b/ci/template_onnx2daq_build_python_all_version.yml @@ -0,0 +1,20 @@ +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '3.7' + addToPath: true + architecture: 'x64' +- template: template_onnx2bnn_build_python.yml +- task: UsePythonVersion@0 + inputs: + versionSpec: '3.6' + addToPath: true + architecture: 'x64' +- template: template_onnx2bnn_build_python.yml +- task: UsePythonVersion@0 + inputs: + versionSpec: '3.5' + addToPath: true + architecture: 'x64' +- template: template_onnx2bnn_build_python.yml + diff --git a/ci/template_onnx2daq_github_release.yml b/ci/template_onnx2daq_github_release.yml new file mode 100644 index 0000000..0e067e7 --- /dev/null +++ b/ci/template_onnx2daq_github_release.yml @@ -0,0 +1,12 @@ +steps: +- task: GitHubRelease@0 + condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')) + inputs: + gitHubConnection: 'dabnn release' + repositoryName: '$(Build.Repository.Name)' + action: 'edit' + tag: '$(Build.SourceBranchName)' + target: '$(Build.SourceVersion)' + assets: '$(Build.ArtifactStagingDirectory)/*' + assetUploadMode: 'replace' + diff --git a/ci/template_onnx2daq_publish_artifacts.yml b/ci/template_onnx2daq_publish_artifacts.yml new file mode 100644 index 0000000..f013ada --- /dev/null +++ b/ci/template_onnx2daq_publish_artifacts.yml @@ -0,0 +1,6 @@ +steps: +- task: PublishBuildArtifacts@1 + inputs: + pathtoPublish: $(Build.ArtifactStagingDirectory) + artifactName: onnx2bnn + diff --git a/ci/template_onnx2daq_upload_to_pypi.yml b/ci/template_onnx2daq_upload_to_pypi.yml new file mode 100644 index 0000000..df57b90 --- /dev/null +++ b/ci/template_onnx2daq_upload_to_pypi.yml @@ -0,0 +1,9 @@ +steps: +- script: python -m twine upload dist/* --verbose + condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')) + displayName: Upload wheel to PyPI + workingDirectory: tools/onnx2bnn/python/ + env: + TWINE_USERNAME: $(twineUsername) + TWINE_PASSWORD: $(twinePassword) +