diff --git a/.github/cloudbuild/flutter-android.yaml b/.github/cloudbuild/flutter-android.yaml index 3bdbed244..4b02bf3df 100644 --- a/.github/cloudbuild/flutter-android.yaml +++ b/.github/cloudbuild/flutter-android.yaml @@ -69,8 +69,7 @@ steps: args: - -xc - | - cd flutter || exit $? - make ci/android/test_apk || exit $? + make ci/flutter/android/test_apk || exit $? mkdir -p /workspace/output/artifacts || exit $? cp /workspace/flutter/build/app/outputs/flutter-apk/app-release.apk /workspace/output/artifacts/mlperf_app_release.apk || exit $? diff --git a/.github/workflows/format-buildifier.yml b/.github/workflows/format-and-lint.yml similarity index 92% rename from .github/workflows/format-buildifier.yml rename to .github/workflows/format-and-lint.yml index c49963392..3d8f112a5 100644 --- a/.github/workflows/format-buildifier.yml +++ b/.github/workflows/format-and-lint.yml @@ -46,17 +46,17 @@ jobs: uses: subosito/flutter-action@v1 with: channel: 'stable' + flutter-version: '2.5.3' - name: Install Protoc uses: arduino/setup-protoc@v1 with: version: '3.x' - name: Create ephemeral files run: | - cd flutter && dart pub global activate protoc_plugin && export PATH="$PATH:$HOME/.pub-cache/bin" && - make prepare-flutter && - dart format lib/backend/backends_list.gen.dart lib/protos lib/localizations + make flutter/prepare-flutter && + dart format flutter/lib/backend/backends_list.gen.dart flutter/lib/protos flutter/lib/localizations - name: Run Dart format check run: dart format --output=none --set-exit-if-changed flutter - name: Run Dart linter diff --git a/Makefile b/Makefile index 80175b61f..b62090719 100644 --- a/Makefile +++ b/Makefile @@ -14,146 +14,28 @@ ########################################################################## -.PHONY: docker_image app bazel-version rundocker clean - -all: app +all: android/app +include tools/common.mk include tools/formatter/format.mk # TFLite is the default backend include mobile_back_tflite/tflite_backend.mk -ifeq (${WITH_QTI},1) - $(info WITH_QTI=1) - include mobile_back_qti/make/qti_backend.mk - include mobile_back_qti/make/qti_backend_targets.mk -endif +include mobile_back_qti/make/qti_backend.mk +include mobile_back_qti/make/qti_backend_targets.mk ifeq (${WITH_SAMSUNG},1) $(info WITH_SAMSUNG=1) - SAMSUNG_BACKEND=--//android/java/org/mlperf/inference:with_samsung="1" + SAMSUNG_BACKEND_BAZEL_FLAG=--//android/java/org/mlperf/inference:with_samsung="1" endif -ifeq (${WITH_PIXEL},1) - $(info WITH_PIXEL=1) - include mobile_back_pixel/pixel_backend.mk -endif - -output/mlperf_mobile_docker_1_0.stamp: android/docker/mlperf_mobile/Dockerfile - mkdir -p output/docker - docker image build -t mlcommons/mlperf_mobile:1.0 android/docker/mlperf_mobile - touch $@ - -docker_image: output/mlperf_mobile_docker_1_0.stamp - -COMMON_DOCKER_FLAGS1= \ - -e USER=mlperf \ - ${PROXY_WORKAROUND1} \ - -v $(CURDIR):/home/mlperf/mobile_app \ - -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ - ${QTI_VOLUMES} \ - -w /home/mlperf/mobile_app \ - -u `id -u`:`id -g` \ - mlcommons/mlperf_mobile:1.0 bazel-3.7.2 - -COMMON_DOCKER_FLAGS2= \ - ${PROXY_WORKAROUND2} \ - --output_user_root=/home/mlperf/cache/bazel build --verbose_failures \ - -c opt --cxxopt='--std=c++14' --host_cxxopt='--std=c++14' \ - --host_cxxopt='-Wno-deprecated-declarations' --host_cxxopt='-Wno-class-memaccess' \ - --cxxopt='-Wno-deprecated-declarations' --cxxopt='-Wno-unknown-attributes' - -COMMON_DOCKER_FLAGS= \ - ${COMMON_DOCKER_FLAGS1} \ - ${COMMON_DOCKER_FLAGS2} - - -NATIVE_DOCKER_FLAGS= \ - ${COMMON_DOCKER_FLAGS1} --bazelrc=/dev/null \ - ${COMMON_DOCKER_FLAGS2} - -proto_test: output/mlperf_mobile_docker_1_0.stamp - # Building proto_test - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${NATIVE_DOCKER_FLAGS} --experimental_repo_remote_exec \ - //android/cpp/proto:proto_test - cp output/`readlink bazel-bin`/android/cpp/proto/proto_test output/proto_test - chmod 777 output/proto_test - -main: output/mlperf_mobile_docker_1_0.stamp ${QTI_DEPS} - # Building main - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${COMMON_DOCKER_FLAGS} \ - --config android_arm64 //mobile_back_tflite:tflitebackend ${QTI_TARGET} //android/cpp/binary:main - rm -rf output/binary && mkdir -p output/binary - cp output/`readlink bazel-bin`/android/cpp/binary/main output/binary/main - cp output/`readlink bazel-bin`/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so output/binary/libtflitebackend.so - ${QTI_LIB_COPY} - chmod 777 output/binary/main output/binary/libtflitebackend.so - -libtflite: output/mlperf_mobile_docker_1_0.stamp - # Building libtflite - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${COMMON_DOCKER_FLAGS} \ - --config android_arm64 //mobile_back_tflite:tflitebackend - rm -rf output/binary && mkdir -p output/binary - cp output/`readlink bazel-bin`/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so output/binary/libtflitebackend.so - chmod 777 output/binary/libtflitebackend.so - - -app: output/mlperf_mobile_docker_1_0.stamp ${QTI_DEPS} - # Building mlperf_app.apk - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${COMMON_DOCKER_FLAGS} \ - ${QTI_BACKEND} ${SAMSUNG_BACKEND} ${MEDIATEK_BACKEND} ${PIXEL_BACKEND} \ - --fat_apk_cpu=arm64-v8a \ - //android/java/org/mlperf/inference:mlperf_app - cp output/`readlink bazel-bin`/android/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app.apk - chmod 777 output/mlperf_app.apk - -app_x86_64: output/mlperf_mobile_docker_1_0.stamp - # Building mlperf_app_x86_64.apk - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${COMMON_DOCKER_FLAGS} \ - ${QTI_BACKEND} ${SAMSUNG_BACKEND} ${MEDIATEK_BACKEND} ${PIXEL_BACKEND} \ - --fat_apk_cpu=x86_64 \ - //android/java/org/mlperf/inference:mlperf_app - cp output/`readlink bazel-bin`/android/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app_x86_64.apk - chmod 777 output/mlperf_app.apk - -test_app: output/mlperf_mobile_docker_1_0.stamp - # Building mlperf_test_app.apk - mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache - docker run \ - ${COMMON_DOCKER_FLAGS} \ - ${QTI_BACKEND} ${SAMSUNG_BACKEND} ${MEDIATEK_BACKEND} ${PIXEL_BACKEND} \ - --fat_apk_cpu=x86_64,arm64-v8a \ - //androidTest:mlperf_test_app - cp output/`readlink bazel-bin`/android/androidTest/mlperf_test_app.apk output/mlperf_test_app.apk - chmod 777 output/mlperf_test_app.apk - -rundocker: output/mlperf_mobile_docker_1_0.stamp - docker run -it \ - -e USER=mlperf \ - -v $(CURDIR):/home/mlperf/mobile_app \ - -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ - -w /home/mlperf/mobile_app \ - -u `id -u`:`id -g` \ - mlcommons/mlperf_mobile:1.0 +include mobile_back_pixel/pixel_backend.mk -rundocker_root: output/mlperf_mobile_docker_1_0.stamp - docker run -it \ - -e USER=mlperf \ - -v $(CURDIR):/home/mlperf/mobile_app \ - -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ - -w /home/mlperf/mobile_app \ - mlcommons/mlperf_mobile:1.0 +include android/android.mk +include flutter/flutter.mk +.PHONY: clean clean: ([ -d output/home/mlperf/cache ] && chmod -R +w output/home/mlperf/cache) || true rm -rf output diff --git a/README.md b/README.md index 10f93579a..b49054bbe 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ frameworks contributed by the broader MLPerf community. * mobile_back_pixel - Google Pixel backend for Android * mobile_back_tflite - Combined TFLite / MediaTek backends for Android * datasets - Contains scripts to prepare test and calibration data used for accuracy evaluation and model quantization. +* tools - contains miscellaneous tools (e.g., formatting commands) ## Related Repositories: diff --git a/android/README.md b/android/README.md index 18e51232f..23b8c32ea 100644 --- a/android/README.md +++ b/android/README.md @@ -80,15 +80,15 @@ adb install -r bazel-bin/android/java/org/mlperf/inference/mlperf_app.apk On the other hand, you can use a docker image to build the app: ``` -make app +make android/app ``` or to enable the QTI backend: ``` -make WITH_QTI=1 app +make WITH_QTI=1 android/app ``` or to enable multiple backends: ``` -make WITH_QTI=1 WITH_MEDIATEK=1 app +make WITH_QTI=1 WITH_MEDIATEK=1 android/app ``` Note: Follow the instruction of the backend vendor (in `mobile_back_*` folders at root level) to build for that backend. Some backends may contain proprietary code. In that case, please contact MLCommons to get help. @@ -100,7 +100,7 @@ adb install -r build/mlperf_app.apk If you want to build an instrumented test APK you should add target `//androidTest:mlperf_test_app`, i.e. : ```bash -make test_app +make android/test_app adb install -r build/mlperf_test_app.apk ``` diff --git a/android/android.mk b/android/android.mk new file mode 100644 index 000000000..d81421cc2 --- /dev/null +++ b/android/android.mk @@ -0,0 +1,147 @@ +# Copyright 2020-2021 The MLPerf Authors. 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. +########################################################################## + +.PHONY: android/builder-image +android/builder-image: output/android_docker.stamp + +output/android_docker.stamp: android/docker/mlperf_mobile/Dockerfile + mkdir -p output/docker + docker image build -t mlcommons/mlperf_mobile_android_builder android/docker/mlperf_mobile + touch $@ + +ANDROID_COMMON_DOCKER_FLAGS1= \ + -it \ + -e USER=mlperf \ + ${PROXY_WORKAROUND1} \ + -v $(CURDIR):/home/mlperf/mobile_app \ + -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ + ${QTI_VOLUMES} \ + -w /home/mlperf/mobile_app \ + -u `id -u`:`id -g` \ + mlcommons/mlperf_mobile_android_builder bazel-3.7.2 + +ANDROID_COMMON_DOCKER_FLAGS2= \ + ${PROXY_WORKAROUND2} \ + --output_user_root=/home/mlperf/cache/bazel build --verbose_failures \ + -c opt --cxxopt='--std=c++14' --host_cxxopt='--std=c++14' \ + --host_cxxopt='-Wno-deprecated-declarations' --host_cxxopt='-Wno-class-memaccess' \ + --cxxopt='-Wno-deprecated-declarations' --cxxopt='-Wno-unknown-attributes' + +ANDROID_COMMON_DOCKER_FLAGS= \ + ${ANDROID_COMMON_DOCKER_FLAGS1} \ + ${ANDROID_COMMON_DOCKER_FLAGS2} + + +ANDROID_NATIVE_DOCKER_FLAGS= \ + ${ANDROID_COMMON_DOCKER_FLAGS1} --bazelrc=/dev/null \ + ${ANDROID_COMMON_DOCKER_FLAGS2} + +.PHONY: android/proto_test +android/proto_test: android/builder-image + # Building proto_test + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_NATIVE_DOCKER_FLAGS} --experimental_repo_remote_exec \ + //android/cpp/proto:proto_test + cp output/`readlink bazel-bin`/android/cpp/proto/proto_test output/proto_test + chmod 777 output/proto_test + +.PHONY: android/main +android/main: android/builder-image + # Building main + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ + --config android_arm64 //mobile_back_tflite:tflitebackend ${QTI_TARGET} //android/cpp/binary:main + rm -rf output/binary && mkdir -p output/binary + cp output/`readlink bazel-bin`/android/cpp/binary/main output/binary/main + cp output/`readlink bazel-bin`/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so output/binary/libtflitebackend.so + ${QTI_LIB_COPY} + chmod 777 output/binary/main output/binary/libtflitebackend.so + +.PHONY: android/libtflite +android/libtflite: android/builder-image + # Building libtflite + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ + --config android_arm64 //mobile_back_tflite:tflitebackend + rm -rf output/binary && mkdir -p output/binary + cp output/`readlink bazel-bin`/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so output/binary/libtflitebackend.so + chmod 777 output/binary/libtflitebackend.so + +.PHONY: android/app +android/app: android/builder-image + # Building mlperf_app.apk + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ + ${QTI_BACKEND_BAZEL_FLAG} \ + ${SAMSUNG_BACKEND_BAZEL_FLAG} \ + ${MEDIATEK_BACKEND_BAZEL_FLAG} \ + ${PIXEL_BACKEND_BAZEL_FLAG} \ + --fat_apk_cpu=arm64-v8a \ + //android/java/org/mlperf/inference:mlperf_app + cp output/`readlink bazel-bin`/android/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app.apk + chmod 777 output/mlperf_app.apk + +.PHONY: android/app_x86_64 +android/app_x86_64: android/builder-image + # Building mlperf_app_x86_64.apk + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ + ${QTI_BACKEND_BAZEL_FLAG} \ + ${SAMSUNG_BACKEND_BAZEL_FLAG} \ + ${MEDIATEK_BACKEND_BAZEL_FLAG} \ + ${PIXEL_BACKEND_BAZEL_FLAG} \ + --fat_apk_cpu=x86_64 \ + //android/java/org/mlperf/inference:mlperf_app + cp output/`readlink bazel-bin`/android/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app_x86_64.apk + chmod 777 output/mlperf_app.apk + +.PHONY: android/test_app +android/test_app: android/builder-image + # Building mlperf_test_app.apk + mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache + docker run \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ + ${QTI_BACKEND_BAZEL_FLAG} \ + ${SAMSUNG_BACKEND_BAZEL_FLAG} \ + ${MEDIATEK_BACKEND_BAZEL_FLAG} \ + ${PIXEL_BACKEND_BAZEL_FLAG} \ + --fat_apk_cpu=x86_64,arm64-v8a \ + //androidTest:mlperf_test_app + cp output/`readlink bazel-bin`/android/androidTest/mlperf_test_app.apk output/mlperf_test_app.apk + chmod 777 output/mlperf_test_app.apk + +.PHONY: android/rundocker +android/rundocker: android/builder-image + docker run -it \ + -e USER=mlperf \ + -v $(CURDIR):/home/mlperf/mobile_app \ + -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ + -w /home/mlperf/mobile_app \ + -u `id -u`:`id -g` \ + mlcommons/mlperf_mobile_android_builder + +.PHONY: android/rundocker_root +android/rundocker_root: android/builder-image + docker run -it \ + -e USER=mlperf \ + -v $(CURDIR):/home/mlperf/mobile_app \ + -v $(CURDIR)/output/home/mlperf/cache:/home/mlperf/cache \ + -w /home/mlperf/mobile_app \ + mlcommons/mlperf_mobile_android_builder diff --git a/android/docker/mlperf_mobile/Dockerfile b/android/docker/mlperf_mobile/Dockerfile index 902bfe92a..6eb68adbd 100644 --- a/android/docker/mlperf_mobile/Dockerfile +++ b/android/docker/mlperf_mobile/Dockerfile @@ -1,4 +1,4 @@ -# Docker image name: mlcommons/mlperf_mobile:1.0 +# Docker image name: mlcommons/mlperf_mobile_android_builder FROM ubuntu:bionic LABEL maintainer="quic_mcharleb@quicinc.com" diff --git a/android/docs/development/building.md b/android/docs/development/building.md index 965a87e29..fca1e9941 100644 --- a/android/docs/development/building.md +++ b/android/docs/development/building.md @@ -35,7 +35,7 @@ git clone https://github.com/mlcommons/mobile_app export SNPE_SDK=/opt/snpe-1.48.0.2554 cd mobile_app cp -r samsung_backend -make TFLITE_BRANCH=main QTI_BRANCH=master MEDIATEK_BACKEND=--//java/org/mlperf/inference:with_mediatek="1" SAMSUNG_BACKEND=--//java/org/mlperf/inference:with_samsung="1" app +make TFLITE_BRANCH=main QTI_BRANCH=master MEDIATEK_BACKEND_BAZEL_FLAG=--//java/org/mlperf/inference:with_mediatek="1" SAMSUNG_BACKEND_BAZEL_FLAG=--//java/org/mlperf/inference:with_samsung="1" app ``` **To build a specific branch for each backend (e.g. v1_0_2):** @@ -46,7 +46,7 @@ git clone -b v1_0_2 https://github.com/mlcommons/mobile_app export SNPE_SDK=/opt/snpe-1.48.0.2554 cd mobile_app cp -r samsung_backend -make TFLITE_BRANCH=v1_0_2 QTI_BRANCH=v1_0_2 MEDIATEK_BACKEND=--//java/org/mlperf/inference:with_mediatek="1" SAMSUNG_BACKEND=--//java/org/mlperf/inference:with_samsung="1" app +make TFLITE_BRANCH=v1_0_2 QTI_BRANCH=v1_0_2 MEDIATEK_BACKEND_BAZEL_FLAG=--//java/org/mlperf/inference:with_mediatek="1" SAMSUNG_BACKEND_BAZEL_FLAG=--//java/org/mlperf/inference:with_samsung="1" app ``` ### Building without make and docker diff --git a/android/formatters/docker_run.sh b/android/formatters/docker_run.sh index d735c46ef..6a58f0645 100755 --- a/android/formatters/docker_run.sh +++ b/android/formatters/docker_run.sh @@ -20,5 +20,5 @@ docker run -it \ -v `pwd`:/home/mlperf/mobile_app \ -w /home/mlperf/mobile_app \ -u `id -u`:`id -g` \ - mlcommons/mlperf_mobile:1.0 $* + mlcommons/mlperf_mobile_android_builder $* diff --git a/datasets/Makefile b/datasets/Makefile index 42d0d5479..d615321c9 100644 --- a/datasets/Makefile +++ b/datasets/Makefile @@ -61,8 +61,8 @@ ${BUILDDIR}/output/state/ade20k.stamp: ${BUILDDIR}/output/state/ade20k_unzip.sta docker run \ -e PYTHONPATH=/workspace/output/ade20k/models-2.3.0/research/slim:/workspace/output/ade20k/models-2.3.0/research/deeplab:/workspace/output/ade20k/models-2.3.0/research \ -v $(BUILDDIR):/workspace/ \ - -u ${USERID}:${GROUPID} \ - mlperf_mobile:1.1 \ + -u ${USERID}:${GROUPID} \ + mlperf_mobile:1.1 \ python3 /workspace/util/ade20k/resize_512_ade20k.py /workspace/output/ade20k/ADEChallengeData2016/ \ /workspace/output/mlperf_datasets/ade20k/ touch $@ @@ -102,8 +102,8 @@ ${BUILDDIR}/output/state/ade20k_calibration.stamp: ${BUILDDIR}/output/state/ade2 mkdir -p ${A_DEST_DIR} mkdir -p ${BUILDDIR}/output/state for f in $(shell cat ${BUILDDIR}/util/ade20k/ade20k_calibration_files.txt) ; do \ - cp ${A_SRC_DIR}/$${f} ${A_DEST_DIR}; \ - done + cp ${A_SRC_DIR}/$${f} ${A_DEST_DIR}; \ + done touch $@ # Coco @@ -145,8 +145,8 @@ ${BUILDDIR}/output/state/coco_calibration.stamp: ${BUILDDIR}/output/state/coco_v mkdir -p ${C_DEST_DIR} mkdir -p ${BUILDDIR}/output/state for f in $(shell cat ${BUILDDIR}/util/coco/coco_calibration_files.txt) ; do \ - cp ${C_SRC_DIR}/COCO_val2014_$${f} ${C_DEST_DIR}/$${f}; \ - done + cp ${C_SRC_DIR}/COCO_val2014_$${f} ${C_DEST_DIR}/$${f}; \ + done touch $@ # imagenet @@ -171,8 +171,8 @@ ${BUILDDIR}/output/state/imagenet.stamp: \ ${BUILDDIR}/output/state/imagenet_calibration.stamp: ${BUILDDIR}/output/state/imagenet.stamp mkdir -p ${BUILDDIR}/output/calibration_set/imagenet/images for f in `cat ${BUILDDIR}/downloads/imagenet/cal_image_list_option_1.txt` ; do \ - cp ${BUILDDIR}/output/mlperf_datasets/imagenet/img/$${f} ${BUILDDIR}/output/calibration_set/imagenet/images; \ - done + cp ${BUILDDIR}/output/mlperf_datasets/imagenet/img/$${f} ${BUILDDIR}/output/calibration_set/imagenet/images; \ + done touch $@ # squad diff --git a/flutter/Makefile b/flutter/Makefile index d39aef1b5..0b1c5068b 100644 --- a/flutter/Makefile +++ b/flutter/Makefile @@ -13,245 +13,9 @@ # limitations under the License. ########################################################################## -.PHONY: all -ifeq (${OS},Windows_NT) -all: windows -else -all: ios -endif - -.PHONY: ios -ios: cpp-ios prepare-flutter update-splash-screen - -BAZEL_LINKS_DIR=bazel- -_bazel_links_arg=--symlink_prefix ${BAZEL_LINKS_DIR} --experimental_no_product_name_out_symlink - -.PHONY: cpp-ios -cpp-ios: - @# NOTE: add `--copt -g` for debug info (but the resulting library would be 0.5 GiB) - bazel ${BAZEL_OUTPUT_ROOT_ARG} build --config=ios_fat64 -c opt //flutter/cpp/flutter:ios_backend_fw_static - - rm -rf ${_xcode_fw} - cp -a ${_bazel_ios_fw} ${_xcode_fw} - -_bazel_ios_fw := ../bazel-bin/flutter/cpp/flutter/ios_backend_fw_static_archive-root/ios_backend_fw_static.framework -_xcode_fw := ios/Flutter/ios_backend_fw_static.framework - -# To add a new backend, add backends/example-windows target (e.g. backends/intel-windows) -.PHONY: windows -windows: backend-bridge-windows backends/tflite-windows prepare-flutter - -debug_flags_windows=-c dbg --copt /Od --copt /Z7 --linkopt -debug - -.PHONY: android -android: backend-bridge-android backends/tflite-android prepare-flutter - -.PHONY: android/apk -android/apk: android - flutter clean - @# take results from build/app/outputs/flutter-apk/app-release.apk - flutter build apk - -.PHONY: ci/android/test_apk -ci/android/test_apk: android/apk - @# take results from build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk - cd android && ./gradlew app:assembleAndroidTest - @# take results from build/app/outputs/apk/debug/app-debug.apk - cd android && ./gradlew app:assembleDebug -Ptarget=integration_test/first_test.dart - -.PHONY: docker/android/apk -docker/android/apk: android/docker/image - @# if the build fails with java.io.IOException: Input/output error - @# remove file android/gradle/wrapper/gradle-wrapper.jar - MSYS2_ARG_CONV_EXCL="*" docker run --rm -it --user `id -u`:`id -g` -v $(CURDIR)/..:/mnt/project mlcommons/mlperf_mobile_flutter bash -c "cd /mnt/project/flutter && make prepare-flutter && make android/apk" - -.PHONY: android/docker/image -android/docker/image: build/docker/mlperf_mobile_flutter.stamp - -build/docker/mlperf_mobile_flutter.stamp: android/docker/Dockerfile - docker image build -t mlcommons/mlperf_mobile_flutter android/docker - mkdir -p build/docker - touch $@ - -.PHONY: windows/docker/image -windows/docker/image: - docker build -t mlperf_mobile_flutter:windows-1.0 windows/docker - -.PHONY: windows/docker/create-container -windows/docker/create-container: - docker rm -f mobile_app_flutter_windows_container - mkdir -p output - echo >output/container-script.bat - @# "-it" here is required to make the container killable by Ctrl+C signal. - @# A lot of memory is required by bazel. - @# With default settings only 1 bazel job can run at a time, which, obviously, greatly slows down the build. - @# 4G typically runs 6-7 jobs. 8G is enough for bazel to run 16+ jobs. - @# Also a lot of memory is required by Flutter. When using 2G Flutter fails with out of memory error, so at least 4G is needed. - MSYS2_ARG_CONV_EXCL="*" docker run -it --name mobile_app_flutter_windows_container \ - --detach --memory 8G --cpus $$(( `nproc` - 1 )) \ - --volume $(CURDIR):C:/mobile_app_flutter \ - --workdir C:/mobile_app_flutter \ - mlperf_mobile_flutter:windows-1.0 \ - ".\\output\\container-script.bat output/container-script.bat "make BAZEL_LINKS_DIR=C:/bazel-links/ backend-bridge-windows backends/tflite-windows" - docker start -ai mobile_app_flutter_windows_container +# This is needed for iOS CI +# We'll remove this makefile when we merge the PR and update iOS CI job -.PHONY: windows/docker/flutter-release -windows/docker/flutter-release: - mkdir -p output/windows-build - echo >output/container-script.bat "\ - make windows/copy-flutter-files-for-docker \ - && cd C:/mobile_app_flutter-local \ - && make prepare-flutter windows/flutter-release \ - && cp -r build/windows/runner/Release C:/mobile_app_flutter/output/windows-build \ - " - docker start -ai mobile_app_flutter_windows_container - -# In Docker Windows containers it's impossible to create a link -# from a mounted volume/folder to any folder of the container itself. -# Flutter wants to create links, -# and place them here: windows/flutter/ephemeral/.plugin_symlinks -# so the build doesn't work. -# -# This make target expects that all DLLs are already present. -.PHONY: windows/copy-flutter-files-for-docker -windows/copy-flutter-files-for-docker: - @# for some reason, make can't delete the folder with symlinks: - @# meither rm nor rmdir (both from msys2) doesn't do anything to the .plugin_symlinks folder or its contents, - @# so we call native Windows command line here. - if [ -d "windows/flutter/ephemeral/.plugin_symlinks" ]; then MSYS2_ARG_CONV_EXCL="*" cmd /S /C "rmdir /S /Q windows\\flutter\\ephemeral\\.plugin_symlinks"; fi - rm -rf C:/mobile_app_flutter-local - mkdir -p C:/mobile_app_flutter-local - cp -r --target-directory C:/mobile_app_flutter-local \ - assets \ - cpp \ - integration_test \ - lib \ - test_driver \ - tool \ - windows \ - Makefile \ - pubspec.yaml \ - pubspec.lock - mkdir -p C:/mobile_app_flutter-local/build - cp -r --target-directory C:/mobile_app_flutter-local/build \ - build/win-dlls - -# _windows_container_redist_dlls_dir is specific to our docker image. -# When building locally, path to MSVC DLLs may be different. -# Particularly, MS VS installer typycally installs Community/Pro/Enterprise version instead of "BuildTools" -# Also version numbers may potentially be different. -_windows_container_redist_dlls_dir="C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT" -.PHONY: windows/flutter-release -windows/flutter-release: - flutter build windows - cp -t build/windows/runner/Release \ - ${_windows_container_redist_dlls_dir}/msvcp140.dll \ - ${_windows_container_redist_dlls_dir}/vcruntime140.dll \ - ${_windows_container_redist_dlls_dir}/vcruntime140_1.dll \ - ${_windows_container_redist_dlls_dir}/msvcp140_codecvt_ids.dll - -.PHONY: backend-bridge-windows -backend-bridge-windows: - bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=windows -c opt //flutter/cpp/flutter:backend_bridge.dll - cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/backend_bridge.dll - mkdir -p build/win-dlls/ - rm -f build/win-dlls/backend_bridge.dll - cd .. && cp ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/backend_bridge.dll flutter/build/win-dlls/backend_bridge.dll - -.PHONY: backend-bridge-android -backend-bridge-android: - bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=android_arm64 -c opt //flutter/cpp/flutter:libbackendbridge.so - cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/libbackendbridge.so - mkdir -p android/app/src/main/jniLibs/arm64-v8a - rm -f android/flutter/app/src/main/jniLibs/arm64-v8a/libbackendbridge.so - cd .. && cp ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/libbackendbridge.so flutter/android/app/src/main/jniLibs/arm64-v8a/libbackendbridge.so - -# Use the following block as a template to add a new Windows backend -#.PHONY: backends/example-windows -#backends/example-windows: -# bazel build ${_bazel_links_arg} --config=windows -c opt //mobile_back_example:examplebackenddll -# cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.dll -# mkdir -p build/win-dlls/backends -# rm -f build/win-dlls/backends/libexamplebackend.dll -# cd .. && cp ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.dll flutter/build/win-dlls/backends/libexamplebackend.dll - -.PHONY: backends/tflite-windows -backends/tflite-windows: - bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=windows -c opt //mobile_back_tflite:tflitebackenddll - cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.dll - mkdir -p build/win-dlls/backends - rm -f build/win-dlls/backends/libtflitebackend.dll - cd .. && cp ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.dll flutter/build/win-dlls/backends/libtflitebackend.dll - -# Use the following block as a template to add a new Android backend -#.PHONY: backends/example-android -#backends/example-android: -# bazel build ${_bazel_links_arg} --config=android_arm64 -c opt //mobile_back_example:examplebackend -# cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.so -# mkdir -p android/app/src/main/jniLibs/arm64-v8a -# rm -f android/app/src/main/jniLibs/arm64-v8a/libexamplebackend.so -# cd .. && cp ${BAZEL_LINKS_DIR}bin/mobile_back_examplet/cpp/backend_example/libexamplebackend.so flutter/android/app/src/main/jniLibs/arm64-v8a/libexamplebackend.so - -.PHONY: backends/tflite-android -backends/tflite-android: - bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=android_arm64 -c opt //mobile_back_tflite:tflitebackend - cd .. && chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so - mkdir -p android/app/src/main/jniLibs/arm64-v8a - rm -f android/app/src/main/jniLibs/arm64-v8a/libtflitebackend.so - cd .. && cp ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so flutter/android/app/src/main/jniLibs/arm64-v8a/libtflitebackend.so - -# To add a new vendor backend, copy and uncomment this block and replace "EXAMPLE" and "example" with the vendor name (e.g. INTEL and intel) -# See tflite backend below as an example -#ifeq (${ENABLE_BACKEND_EXAMPLE},0) -#backend_replace_example= -#else -#backend_replace_example=\'libexamplebackend\', -#endif - -ifeq (${ENABLE_BACKEND_TFLITE},0) -backend_replace_tflite= -else -backend_replace_tflite=\'libtflitebackend\', -endif - -# To add a new backend, add a new line to the sed command for your backend replacing "example" with the vendor name. For instance, for Intel it would be: -# -e "s/INTEL_TAG/${backend_replace_intel}/" \ -.PHONY: set-supported-backends -set-supported-backends: - cat lib/backend/backends_list.in | sed \ - -e "s/EXAMPLE_TAG/${backend_replace_example}/" \ - -e "s/TFLITE_TAG/${backend_replace_tflite}/" \ - > lib/backend/backends_list.gen.dart - -.PHONY: protobuf -protobuf: - dart pub get - rm -rf lib/protos - mkdir -p lib/protos - protoc --proto_path ../android/cpp/proto \ - --dart_out lib/protos \ - ../android/cpp/proto/*.proto - -.PHONY: update-splash-screen -update-splash-screen: - tool/update-splash-screen - -.PHONY: generate-localizations -generate-localizations: - flutter gen-l10n \ - --arb-dir=lib/resources \ - --output-dir=lib/localizations \ - --template-arb-file=app_en.arb \ - --output-localization-file=app_localizations.dart \ - --no-synthetic-package - -.PHONY: prepare-flutter -prepare-flutter: set-supported-backends protobuf generate-localizations +.PHONY: all +all: + cd .. && make flutter diff --git a/flutter/README.md b/flutter/README.md index bd28cea74..e3197d069 100644 --- a/flutter/README.md +++ b/flutter/README.md @@ -1,19 +1,10 @@ -# mobile_app_flutter +# flutter -This repository contains sources of MLPerf benchmark application. - -[comment]: # (Don't remove spaces at the end of lines, they force line breaks) -Currently we only support iOS. -Support for Windows is in progress. -You can build and launch the app on Windows, -but the backend and UI don't have all of the required optimizations, -so you will likely see a lot of performance and UX issues. +This folder contains sources of Flutter version of the MLPerfBench application. ## Documentation * [Short overview of the repo structure](./documentation/repo-overview.md) -* [Building for iOS](./documentation/ios.md) -* [Building for Windows](./documentation/windows.md) -* [Building for Android](./documentation/android.md) +* [Building for app on different platforms](./documentation/build-and-run.md) * [Using custom benchmark configuration](./documentation/custom-tasks.md) * [Adding support for your custom backend](./documentation/adding-custom-backend.md) diff --git a/flutter/documentation/build-and-run.md b/flutter/documentation/build-and-run.md new file mode 100644 index 000000000..7e40593e0 --- /dev/null +++ b/flutter/documentation/build-and-run.md @@ -0,0 +1,137 @@ + +This file describes how to build and run the Flutter app for different platforms. + +# Contents + +* [Overview](#overview) +* [Common info](#common-info) +* [Android](#android) +* [iOS](#ios) +* [Windows](#windows) +* [Running tests](#running-tests) + +# Overview + +[comment]: # (Don't remove spaces at the end of lines, they force line breaks) + +All make targets referenced here are defined for the root of the repository. +Flutter/Dart commands, however, are only valid when you are in the `/flutter` directory of the repo. + +The Flutter app uses 2 different build systems: +Bazel for backends (and for glue code between the app and backends) +and the Flutter itself. +Build commands are mostly managed my `make`. + +If you want to build the app, you first need to build native libs, +then prepare files that Flutter needs, +and then run the build command for Flutter. + +# Common info + +The root makefile defines a convenient `flutter` make target, that prepares native libs +and all miscellaneous files for Flutter but doesn't build actual application. +After you run `make flutter`, you can use any Flutter tools to build the app with parameters you need (release, debug, test, etc.). + +The easiest way to just run the app is to run flutter via console: +```bash +flutter run +``` + +If you want to run or debug the Flutter app for any platform using graphical user interface, +you can use [VS Code with Flutter extension](https://docs.flutter.dev/get-started/editor?tab=vscode). + +If you want to test something without spending a lot of time on the benchmark, +you can use flag `--dart-define=fast-mode=true` to speed up the benchmark. +You should not evaluate performance when using this flag. + +# Android + +[comment]: # (Don't remove spaces at the end of lines, they force line breaks) +[comment]: # (TODO add info about building in Docker after we add commands for it) +[comment]: # (TODO add information about using Android emulators) + +On Linux command `make flutter` builds native libs automatically. +See [Android environment setup guide](./env-setup-android.md#setting-up-the-environment-on-ubuntu). + +On macOS `make flutter` will try to build native libs for iOS. Run `make flutter/android` to build android libs on macOS. +Unfortunately, there is no complete environment setup guide for now. +See [macOS guide](./env-setup-ios.md#setting-up-the-environment) for general setup and [Ubuntu guide](./env-setup-android.md#setting-up-the-environment-on-ubuntu) for android-specific parts. + +On Windows building libs for Android is not available. +You can copy `.so` files from some Linux or macOS system, then run `make flutter/prepare-flutter`, and then run Flutter commands locally. +For example, it's relatively convenient to use WSL to build native libs. +See [Windows environment setup guide](./env-setup-windows.md#setting-up-the-environment) to set up your system to run Flutter. + +Run `make flutter/android/apk` to build APK. + +# iOS + +[comment]: # (Don't remove spaces at the end of lines, they force line breaks) + +Building for iOS is available only on macOS. + +See [iOS environment setup guide](./env-setup-ios.md#setting-up-the-environment). + +If you want to run the app on a real device, you have to change settings in XCode: +1. Open `/flutter/ios/Runner.xcworkspace` +2. Open `Runner` settings → `Signings & Capabilities`. +You probably need the Debug mode tab, but you can also change values in other tabs if you need. +3. Make sure checkbox `Automatically manage signing` is checked. +4. Set `Team` to your personal team. +5. Set `Bundle identifier` to some globally unique value (for example, you can add your name to it). + +If you want to run the app in iPhone Simulator, make sure that the Simulator is running. +To launch Simulator for iPhone 12 Pro you can use the following command: `xcrun simctl bootstatus "iPhone 12 Pro" -b`. +You can find available devices using `xcrun simctl list`. + +You may want to use XCode GUI to launch the app, if you are using a Simulator, because for some reason logs from native code are incomplete in console. +Also Flutter doesn't support running the app on a remote device, without wired connection, but you can still use XCode GUI for this. +Remember that XCode is used for the final build of the app, but it doesn't update any Flutter-related info. +If you change Flutter sources or configs and then press the `Run` button in XCode, you will build outdated version of the app. +Run any of the following commands to update Flutter files in XCode project: +* `flutter run` (make sure that you select iOS device during build) +* `flutter build ios` +* `flutter build ipa` + +Run `flutter build ipa` to create redistributable archive. +Note that you will need to sign the app using external tools, which are not described here. + +# Windows + +Building for Windows is available only on Windows. + +See [Windows environment setup guide](./env-setup-windows.md#setting-up-the-environment). + +On Windows it's pretty easy to use Visual Studio debugger for native libs. +1. Build native libs with debug symbols. +Add `${debug_flags_windows}` to bazel build command in the corresponding make target and rerun `make flutter`. +2. Use `flutter run -d windows` or `flutter build windows --debug` +to update Visual Studio project after any changes in Flutter files or config. +3. Open VS solution file `/flutter/build/windows/mobile_app_flutter2.sln`, +right-click on `mobile_app_flutter2` project and click on `Set as Startup Project`. +4. Launch the app in debug mode from Visual Studio. + +Visual Studio projects generated by Flutter don't have any backend files, +but you can drag and drop files from `cpp` folders to open them in Visual Studio and set breakpoints. + +Run `flutter build windows` to build release folder with the app. +The release folder will be located in `flutter/build/windows/runner/Release/`. +To create redistributable copy the following files into the application directory: +``` +msvcp140.dll +vcruntime140.dll +vcruntime140_1.dll +msvcp140_codecvt_ids.dll +``` +You can create `.zip` archive with the `Release` folder to redistribute the app. + +# Running tests + +You can run integration test on your device. +Use the following command to start the test: +`flutter drive --driver=test_driver/integration_test.dart --target=integration_test/first_test.dart` + +Remember that running integration test changes Flutter configuration. +If you run this command and then try to launch the app from XCode or Visual Studio, +you will launch the test instead of the app. +Use `flutter run` or `flutter build` commands to switch to launching the app without tests. diff --git a/flutter/documentation/custom-tasks.md b/flutter/documentation/custom-tasks.md index 16631cafa..15291307a 100644 --- a/flutter/documentation/custom-tasks.md +++ b/flutter/documentation/custom-tasks.md @@ -57,6 +57,7 @@ Instead of copying your file using `Files`, you can use Share button in your ext This method doesn't have restrictions on file extension. # Using external resources on an Android + On Android the resource folder is located at `/Android/data/org.mlcommons.android.mlperfbench/files`. On Android 11, the folder `/Android/data/` is inaccessible using the default File Manager app. It stills accessible through 3rd party File Manager apps, though. diff --git a/flutter/documentation/android.md b/flutter/documentation/env-setup-android.md similarity index 79% rename from flutter/documentation/android.md rename to flutter/documentation/env-setup-android.md index 06702fdb4..2476d197d 100644 --- a/flutter/documentation/android.md +++ b/flutter/documentation/env-setup-android.md @@ -1,15 +1,9 @@ -This file describes how to build the Flutter app for Android. - -Android native files can be built on linux and Mac OS. -You will get an error if you try to build android bazel targets on Windows. - -When you have all required native .so libraries, the Flutter app itself can be built on Windows without any issues. +This file describes how to setup the environment for Android builds on Ubuntu. # Contents * [Setting up the environment on Ubuntu](#setting-up-the-environment-on-ubuntu) -* [Build and run](#build-and-run) # Setting up the environment on Ubuntu @@ -78,12 +72,4 @@ When you have all required native .so libraries, the Flutter app itself can be b * Add Dart pub bin folder to PATH: `export PATH=$PATH:~/.pub-cache/bin` If you use bash: `echo export PATH=\$PATH:~/.pub-cache/bin >>~/.bashrc` -# Build and run - -* build native libraries: go to `flutter` directory and run `make android` - * The app is compatible with all android backends for the old Android app - but we don't have make targets to automatically inject them into the Flutter app yet -* build and launch the app: `flutter run` - -If you want to get release APK go to `flutter` directory and run `flutter build apk` (still note that only default backend will be included). -Like with `flutter run`, you need to build native libraries prior to this. +[comment]: # (TODO add info about installing formatting tools) diff --git a/flutter/documentation/ios.md b/flutter/documentation/env-setup-ios.md similarity index 53% rename from flutter/documentation/ios.md rename to flutter/documentation/env-setup-ios.md index b988c23be..1904fa228 100644 --- a/flutter/documentation/ios.md +++ b/flutter/documentation/env-setup-ios.md @@ -1,13 +1,11 @@ -This file describes how to build the app for iOS. +This file describes environment setup for iOS builds on macOS. # Contents * [Setting up the environment](#setting-up-the-environment) -* [Build and run](#build-and-run) +* [Tested anvironment](#tested-anvironment) * [Changing application icon](#changing-application-icon) -* [Running instrumented test](#running-instrumented-test) -* [Formatting the code](#formatting-the-code) # Setting up the environment @@ -30,6 +28,8 @@ echo export PATH="$PATH:$HOME/.pub-cache/bin" >>~/.zshrc ``` * Go to `ios` directory and install pods: `pod install` +# Tested anvironment + The app was built and tested successfully in this environment: ``` @@ -58,23 +58,10 @@ Python 3.9.7 Note: the current version may crash with EXC_RESOURCE if built with XCode 13.0 (see issue [#303](https://github.com/mlcommons/mobile_app_flutter/issues/303)) -# Build and run - -[comment]: # (Don't remove spaces at the end of lines, they force line breaks) -* build backend library: `make` -* build and launch the app: `flutter run` - * If you want to run the app on a real device, you have to change settings in XCode. -Open `Runner` settings → `Signings & Capabilities`. -Make sure checkbox "Automatically manage signing" is checked. -Set `Team` to your personal team. -Set `Bundle identifier` to some value, that is unique for you (for example, you can add your name to it). - * If you want to run the app in the simulator, make sure that the simulator is running. -You can launch the simulator with the following command: `open -a Simulator` -Or you can choose desired model of an iPhone in XCode and launch the app from XCode. -Simulator will be opened automatically by XCode. - # Changing application icon +[comment]: # (TODO move this somewhere?) + After building application, if you would like to set new application icon use following actions: * Go to `pubspec.yaml` file in root folder @@ -83,40 +70,12 @@ After building application, if you would like to set new application icon use fo Please note that iOS icons should not have any transparency. See more guidelines [here](https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/). -# Running instrumented test - -* Run simulator `open -a Simulator` or connect physical device -* Define device Id `flutter devices`: -```bash -2 connected devices: - -iPhone 12 Pro Max (mobile) • XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator) -Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.128 -``` -* Run test: -```bash -flutter drive \ - --driver=test_driver/integration_test.dart \ - --target=integration_test/first_test.dart \ - -d "iPhone 12 Pro Max" -``` -or -```bash -flutter drive \ - --driver=test_driver/integration_test.dart \ - --target=integration_test/first_test.dart \ - -d XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -``` +# Formatting -# Formatting the code +[comment]: # (TODO add info about installing other tools) In order to automatically format your files you must have `clang-format` and `buildifier` in addition to build dependencies. -* clang-format can be installed via `brew install clang-format`, -* buildifier can be installed via `brew install buildifier` - -Run `make format` to fix the formatting. -This will fix C++, bazel and Dart files. -Alternatively you can use make targets `format-clang`, `format-bazel`, `format-dart` -to format only certain kinds of files. +* `brew install clang-format`, +* `brew install buildifier` diff --git a/flutter/documentation/windows.md b/flutter/documentation/env-setup-windows.md similarity index 82% rename from flutter/documentation/windows.md rename to flutter/documentation/env-setup-windows.md index 9d2f334cc..f0b499646 100644 --- a/flutter/documentation/windows.md +++ b/flutter/documentation/env-setup-windows.md @@ -4,8 +4,7 @@ This file describes how to build the app for Windows. # Contents * [Setting up the environment](#setting-up-the-environment) -* [Build and run](#build-and-run) -* [Formatting the code](#formatting-the-code) +* [Formatting](#formatting) # Setting up the environment @@ -58,16 +57,9 @@ $env:TEMP=$env:USERPROFILE+'\AppData\Local\Temp' $env:TMP=$env:USERPROFILE+'\AppData\Local\Temp' ``` -# Build and run +# Formatting -* Build default backend: `make` -This can take a long time if you are building it from scratch. -After you have built the backend one time you will have bazel cache, -and later builds should be pretty fast, unless you change global build configuration -(for example, switching between debug and release mode). -* Build and launch: `flutter run` - -# Formatting the code +[comment]: # (TODO add info about installing other tools) In order to automatically format your files you must have `clang-format` and `buildifier` in addition to build dependencies. @@ -76,8 +68,3 @@ you must have `clang-format` and `buildifier` in addition to build dependencies. or it can be manually downloaded from the very bottom of the [LLVM Snapshot Builds page](https://llvm.org/builds/) and manually placed somewhere in your PATH. * buildifier can be installed via `choco install buildifier -y` - -Run `make format` to fix the formatting. -This will fix C++, bazel and Dart files. -Alternatively you can use make targets `format-clang`, `format-bazel`, `format-dart` -to format only certain kinds of files. diff --git a/flutter/documentation/updating-cpp-code.md b/flutter/documentation/updating-cpp-code.md deleted file mode 100644 index e3d209c26..000000000 --- a/flutter/documentation/updating-cpp-code.md +++ /dev/null @@ -1,23 +0,0 @@ - -This file describes how to easily update contents of the [cpp](/cpp) folder. - -# Content - -* [Updating C++ code](#updating-C-code) - -# Updating C++ code - -When there are some changes in default tflite backend -in the [reference repo](https://github.com/mlcommons/mobile_app_open) -(=repo of the Android app), -these changes should be pulled into this repo. - -There is a branch -`[upstream/android-cpp](https://github.com/mlcommons/mobile_app_flutter/tree/upstream/android-cpp)`. -This branch contains unchanged source code from the reneferce repo. - -To sync with the Android app, copy its source from the reference repo -into `upstream/android-cpp` branch, -then create a new branch from current main branch state -and merge `upstream/android-cpp` into your new branch, -and fix everything that became broken after the merge. diff --git a/flutter/flutter.mk b/flutter/flutter.mk new file mode 100644 index 000000000..5cb8e9a64 --- /dev/null +++ b/flutter/flutter.mk @@ -0,0 +1,261 @@ +# Copyright 2020-2021 The MLPerf Authors. 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. +########################################################################## + +.PHONY: flutter +ifeq (${OS},Windows_NT) +flutter: flutter/windows +else +ifeq ($(shell uname -s),Darwin) +flutter: flutter/ios +else +flutter: flutter/android +endif +endif + +.PHONY: flutter/ios +flutter/ios: flutter/cpp-ios flutter/prepare-flutter flutter/update-splash-screen + +BAZEL_LINKS_DIR=bazel- +_bazel_links_arg=--symlink_prefix ${BAZEL_LINKS_DIR} --experimental_no_product_name_out_symlink + +.PHONY: flutter/cpp-ios +flutter/cpp-ios: + @# NOTE: add `--copt -g` for debug info (but the resulting library would be 0.5 GiB) + bazel ${BAZEL_OUTPUT_ROOT_ARG} build --config=ios_fat64 -c opt //flutter/cpp/flutter:ios_backend_fw_static + + rm -rf ${_xcode_fw} + cp -a ${_bazel_ios_fw} ${_xcode_fw} + +_bazel_ios_fw := bazel-bin/flutter/cpp/flutter/ios_backend_fw_static_archive-root/ios_backend_fw_static.framework +_xcode_fw := flutter/ios/Flutter/ios_backend_fw_static.framework + +# To add a new backend, add flutter/backends/example-windows target (e.g. flutter/backends/intel-windows) +.PHONY: flutter/windows +flutter/windows: flutter/backend-bridge-windows flutter/backends/tflite-windows flutter/prepare-flutter + +debug_flags_windows=-c dbg --copt /Od --copt /Z7 --linkopt -debug + +.PHONY: flutter/android +flutter/android: flutter/backend-bridge-android flutter/backends/tflite-android flutter/prepare-flutter + +.PHONY: flutter/android/apk +flutter/android/apk: flutter/android + cd flutter && flutter clean + @# take results from flutter/build/app/outputs/flutter-apk/app-release.apk + cd flutter && flutter build apk + +.PHONY: ci/flutter/android/test_apk +ci/flutter/android/test_apk: flutter/android/apk + @# take results from flutter/build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk + cd flutter/android && ./gradlew app:assembleAndroidTest + @# take results from flutter/build/app/outputs/apk/debug/app-debug.apk + cd flutter/android && ./gradlew app:assembleDebug -Ptarget=integration_test/first_test.dart + +.PHONY: flutter/docker/android/apk +flutter/docker/android/apk: flutter/android/docker/image + @# if the build fails with java.io.IOException: Input/output error + @# remove file flutter/android/gradle/wrapper/gradle-wrapper.jar + MSYS2_ARG_CONV_EXCL="*" docker run --rm -it --user `id -u`:`id -g` -v $(CURDIR):/mnt/project mlcommons/mlperf_mobile_flutter bash -c "cd /mnt/project && make flutter/android/apk" + +.PHONY: flutter/android/docker/image +flutter/android/docker/image: flutter/build/docker/mlperf_mobile_flutter.stamp + +flutter/build/docker/mlperf_mobile_flutter.stamp: flutter/android/docker/Dockerfile + docker image build -t mlcommons/mlperf_mobile_flutter android/docker + mkdir -p build/docker + touch $@ + +.PHONY: flutter/windows/docker/image +flutter/windows/docker/image: + docker build -t mlperf_mobile_flutter:windows-1.0 windows/docker + +.PHONY: flutter/windows/docker/create-container +flutter/windows/docker/create-container: + docker rm -f mobile_app_flutter_windows_container + mkdir -p output + echo >output/container-script.bat + @# "-it" here is required to make the container killable by Ctrl+C signal. + @# A lot of memory is required by bazel. + @# With default settings only 1 bazel job can run at a time, which, obviously, greatly slows down the build. + @# 4G typically runs 6-7 jobs. 8G is enough for bazel to run 16+ jobs. + @# Also a lot of memory is required by Flutter. When using 2G Flutter fails with out of memory error, so at least 4G is needed. + MSYS2_ARG_CONV_EXCL="*" docker run -it --name mobile_app_flutter_windows_container \ + --detach --memory 8G --cpus $$(( `nproc` - 1 )) \ + --volume $(CURDIR):C:/mnt/project \ + --workdir C:/mnt/project \ + mlperf_mobile_flutter:windows-1.0 \ + ".\\output\\container-script.bat output/container-script.bat "make BAZEL_LINKS_DIR=C:/bazel-links/ flutter/backend-bridge-windows flutter/backends/tflite-windows" + docker start -ai mobile_app_flutter_windows_container + +.PHONY: flutter/windows/docker/flutter-release +flutter/windows/docker/flutter-release: + mkdir -p output/windows-build + echo >output/container-script.bat "\ + make flutter/windows/copy-flutter-files-for-docker \ + && cd C:/project-local \ + && make flutter/prepare-flutter flutter/windows/flutter-release \ + && cp -r build/windows/runner/Release C:/mnt/project/output/windows-build \ + " + docker start -ai mobile_app_flutter_windows_container + +# In Docker Windows containers it's impossible to create a link +# from a mounted volume/folder to any folder of the container itself. +# Flutter wants to create links, +# and place them here: flutter/windows/flutter/ephemeral/.plugin_symlinks +# so the build doesn't work. +# +# This make target expects that all DLLs are already present. +.PHONY: flutter/windows/copy-flutter-files-for-docker +flutter/windows/copy-flutter-files-for-docker: + @# for some reason, make can't delete the folder with symlinks: + @# meither rm nor rmdir (both from msys2) doesn't do anything to the .plugin_symlinks folder or its contents, + @# so we call native Windows command line here. + if [ -d "flutter/windows/flutter/ephemeral/.plugin_symlinks" ]; then MSYS2_ARG_CONV_EXCL="*" cmd /S /C "rmdir /S /Q flutter\\windows\\flutter\\ephemeral\\.plugin_symlinks"; fi + rm -rf C:/project-local + mkdir -p C:/project-local + cp -r --target-directory C:/project-local \ + flutter/assets \ + flutter/cpp \ + flutter/integration_test \ + flutter/lib \ + flutter/test_driver \ + flutter/tool \ + flutter/windows \ + flutter/Makefile \ + flutter/pubspec.yaml \ + flutter/pubspec.lock + mkdir -p C:/project-local/build + cp -r --target-directory C:/project-local/build \ + build/win-dlls + +# _windows_container_redist_dlls_dir is specific to our docker image. +# When building locally, path to MSVC DLLs may be different. +# Particularly, MS VS installer typycally installs Community/Pro/Enterprise version instead of "BuildTools" +# Also version numbers may potentially be different. +_windows_container_redist_dlls_dir="C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT" +.PHONY: flutter/windows/flutter-release +flutter/windows/flutter-release: + flutter build windows + cp -t build/windows/runner/Release \ + ${_windows_container_redist_dlls_dir}/msvcp140.dll \ + ${_windows_container_redist_dlls_dir}/vcruntime140.dll \ + ${_windows_container_redist_dlls_dir}/vcruntime140_1.dll \ + ${_windows_container_redist_dlls_dir}/msvcp140_codecvt_ids.dll + +.PHONY: flutter/backend-bridge-windows +flutter/backend-bridge-windows: + bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=windows -c opt //flutter/cpp/flutter:backend_bridge.dll + chmod +w ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/backend_bridge.dll + mkdir -p flutter/build/win-dlls/ + rm -f flutter/build/win-dlls/backend_bridge.dll + cp ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/backend_bridge.dll flutter/build/win-dlls/backend_bridge.dll + +.PHONY: flutter/backend-bridge-android +flutter/backend-bridge-android: + bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=android_arm64 -c opt //flutter/cpp/flutter:libbackendbridge.so + chmod +w ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/libbackendbridge.so + mkdir -p flutter/android/app/src/main/jniLibs/arm64-v8a + rm -f flutter/android/app/src/main/jniLibs/arm64-v8a/libbackendbridge.so + cp ${BAZEL_LINKS_DIR}bin/flutter/cpp/flutter/libbackendbridge.so flutter/android/app/src/main/jniLibs/arm64-v8a/libbackendbridge.so + +# Use the following block as a template to add a new Windows backend +#.PHONY: backends/example-windows +#backends/example-windows: +# bazel build ${_bazel_links_arg} --config=windows -c opt //mobile_back_example:examplebackenddll +# chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.dll +# mkdir -p flutter/build/win-dlls/backends +# rm -f flutter/build/win-dlls/backends/libexamplebackend.dll +# cp ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.dll flutter/build/win-dlls/backends/libexamplebackend.dll + +.PHONY: flutter/backends/tflite-windows +flutter/backends/tflite-windows: + bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=windows -c opt //mobile_back_tflite:tflitebackenddll + chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.dll + mkdir -p flutter/build/win-dlls/backends + rm -f flutter/build/win-dlls/backends/libtflitebackend.dll + cp ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.dll flutter/build/win-dlls/backends/libtflitebackend.dll + +# Use the following block as a template to add a new Android backend +#.PHONY: backends/example-android +#backends/example-android: +# bazel build ${_bazel_links_arg} --config=android_arm64 -c opt //mobile_back_example:examplebackend +# chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_example/cpp/backend_example/libexamplebackend.so +# mkdir -p flutter/android/app/src/main/jniLibs/arm64-v8a +# rm -f flutter/android/app/src/main/jniLibs/arm64-v8a/libexamplebackend.so +# cp ${BAZEL_LINKS_DIR}bin/mobile_back_examplet/cpp/backend_example/libexamplebackend.so flutter/android/app/src/main/jniLibs/arm64-v8a/libexamplebackend.so + +.PHONY: flutter/backends/tflite-android +flutter/backends/tflite-android: + bazel build ${BAZEL_CACHE_ARG} ${_bazel_links_arg} --config=android_arm64 -c opt //mobile_back_tflite:tflitebackend + chmod +w ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so + mkdir -p flutter/android/app/src/main/jniLibs/arm64-v8a + rm -f flutter/android/app/src/main/jniLibs/arm64-v8a/libtflitebackend.so + cp ${BAZEL_LINKS_DIR}bin/mobile_back_tflite/cpp/backend_tflite/libtflitebackend.so flutter/android/app/src/main/jniLibs/arm64-v8a/libtflitebackend.so + +# To add a new vendor backend, copy and uncomment this block and replace "EXAMPLE" and "example" with the vendor name (e.g. INTEL and intel) +# See tflite backend below as an example +#ifeq (${ENABLE_BACKEND_EXAMPLE},0) +#backend_replace_example= +#else +#backend_replace_example=\'libexamplebackend\', +#endif + +ifeq (${ENABLE_BACKEND_TFLITE},0) +backend_replace_tflite= +else +backend_replace_tflite=\'libtflitebackend\', +endif + +# To add a new backend, add a new line to the sed command for your backend replacing "example" with the vendor name. For instance, for Intel it would be: +# -e "s/INTEL_TAG/${backend_replace_intel}/" +.PHONY: flutter/set-supported-backends +flutter/set-supported-backends: + cat flutter/lib/backend/backends_list.in | sed \ + -e "s/EXAMPLE_TAG/${backend_replace_example}/" \ + -e "s/TFLITE_TAG/${backend_replace_tflite}/" \ + > flutter/lib/backend/backends_list.gen.dart + +.PHONY: flutter/protobuf +flutter/protobuf: + cd flutter && ${_start_args} dart pub get + rm -rf flutter/lib/protos + mkdir -p flutter/lib/protos + protoc --proto_path android/cpp/proto \ + --dart_out flutter/lib/protos \ + android/cpp/proto/*.proto + +.PHONY: flutter/update-splash-screen +flutter/update-splash-screen: + cd flutter && tool/update-splash-screen + +.PHONY: flutter/generate-localizations +flutter/generate-localizations: + flutter gen-l10n \ + --arb-dir=flutter/lib/resources \ + --output-dir=flutter/lib/localizations \ + --template-arb-file=app_en.arb \ + --output-localization-file=app_localizations.dart \ + --no-synthetic-package + +.PHONY: flutter/prepare-flutter +flutter/prepare-flutter: flutter/set-supported-backends flutter/protobuf flutter/generate-localizations diff --git a/flutter/lib/ui/confirm_dialog.dart b/flutter/lib/ui/confirm_dialog.dart index c24526a75..99f2a435c 100644 --- a/flutter/lib/ui/confirm_dialog.dart +++ b/flutter/lib/ui/confirm_dialog.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart' hide Icons; + import 'package:mlcommons_ios_app/localizations/app_localizations.dart'; enum ConfirmDialogAction { ok, cancel } diff --git a/flutter/lib/ui/settings_screen.dart b/flutter/lib/ui/settings_screen.dart index 7ddb778f1..a766bc4c6 100644 --- a/flutter/lib/ui/settings_screen.dart +++ b/flutter/lib/ui/settings_screen.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart' hide Icons; import 'package:flutter/material.dart'; -import 'package:mlcommons_ios_app/ui/confirm_dialog.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -9,6 +8,7 @@ import 'package:mlcommons_ios_app/benchmark/benchmark.dart'; import 'package:mlcommons_ios_app/localizations/app_localizations.dart'; import 'package:mlcommons_ios_app/store.dart'; import 'package:mlcommons_ios_app/ui/benchmarks_configuration_screen.dart'; +import 'package:mlcommons_ios_app/ui/confirm_dialog.dart'; import 'package:mlcommons_ios_app/ui/snack_bar.dart'; class SettingsScreen extends StatefulWidget { diff --git a/mobile_back_pixel/pixel_backend.mk b/mobile_back_pixel/pixel_backend.mk index 0cfeeb75b..4af6c50af 100644 --- a/mobile_back_pixel/pixel_backend.mk +++ b/mobile_back_pixel/pixel_backend.mk @@ -13,9 +13,7 @@ # limitations under the License. ########################################################################## -# Set the included backends -WITH_PIXEL=0 - ifeq (${WITH_PIXEL},1) - PIXEL_BACKEND=--//android/java/org/mlperf/inference:with_pixel="1" + $(info WITH_PIXEL=1) + PIXEL_BACKEND_BAZEL_FLAG=--//android/java/org/mlperf/inference:with_pixel="1" endif diff --git a/mobile_back_qti/README.md b/mobile_back_qti/README.md index 9c3d85c92..ba1e0411d 100644 --- a/mobile_back_qti/README.md +++ b/mobile_back_qti/README.md @@ -53,7 +53,7 @@ Clone mlperf_app_open and build with the following build commands. ``` git clone https://github.com/mlcommons/mobile_app_open cd mobile_app_open -make WITH_QTI=1 app +make WITH_QTI=1 android/app ``` This will build the QTI backend into the MLPerf app. diff --git a/mobile_back_qti/make/qti_backend.mk b/mobile_back_qti/make/qti_backend.mk index 658b6a277..c992411ea 100644 --- a/mobile_back_qti/make/qti_backend.mk +++ b/mobile_back_qti/make/qti_backend.mk @@ -13,48 +13,18 @@ # limitations under the License. ########################################################################## -.PHONY: snpe_version_check - -ifeq (${USE_PROXY_WORKAROUND},1) - export PROXY_WORKAROUND1=\ - -v /etc/ssl/certs:/etc/ssl/certs \ - -v /usr/share/ca-certificates:/usr/share/ca-certificates \ - -v /usr/share/ca-certificates-java:/usr/share/ca-certificates-java - - export PROXY_WORKAROUND2=--host_jvm_args -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -else - export PROXY_WORKAROUND1= - export PROXY_WORKAROUND2= -endif - -# Set the included backends -WITH_QTI=0 - ifeq (${WITH_QTI},1) - ifneq (${SNPE_SDK},) - QTI_BACKEND=--//android/java/org/mlperf/inference:with_qti="1" - QTI_TARGET=//mobile_back_qti:qtibackend - QTI_LIB_COPY=cp output/`readlink bazel-bin`/mobile_back_qti/cpp/backend_qti/libqtibackend.so output/binary/libqtibackend.so - SNPE_VERSION=$(shell basename ${SNPE_SDK}) - QTI_SNPE_VERSION=$(shell grep SNPE_VERSION mobile_back_qti/variables.bzl | cut -d\" -f2) - QTI_VOLUMES=-v ${SNPE_SDK}:/home/mlperf/mobile_app/mobile_back_qti/${SNPE_VERSION} - QTI_DEPS=snpe_version_check - else - echo "ERROR: SNPE_SDK not set" - QTI_BACKEND=--ERROR_SNPE_SDK_NOT_SET - QTI_VOLUMES= - QTI_DEPS= - QTI_TARGET= - QTI_LIB_COPY=true + $(info WITH_QTI=1) + ifeq (${SNPE_SDK},) + $(error SNPE_SDK env is undefined) + endif + QTI_BACKEND_BAZEL_FLAG=--//android/java/org/mlperf/inference:with_qti="1" + QTI_TARGET=//mobile_back_qti:qtibackend + QTI_LIB_COPY=cp output/`readlink bazel-bin`/mobile_back_qti/cpp/backend_qti/libqtibackend.so output/binary/libqtibackend.so + SNPE_VERSION=$(shell basename ${SNPE_SDK}) + QTI_SNPE_VERSION=$(shell grep SNPE_VERSION mobile_back_qti/variables.bzl | cut -d\" -f2) + QTI_VOLUMES=-v ${SNPE_SDK}:/home/mlperf/mobile_app/mobile_back_qti/${SNPE_VERSION} + ifneq (${SNPE_VERSION},${QTI_SNPE_VERSION}) + $(error SNPE_SDK (${SNPE_VERSION}) doesn't match version specified in bazel config: (${QTI_SNPE_VERSION})) endif -else - QTI_BACKEND= - QTI_VOLUMES= - QTI_DEPS= - QTI_TARGET= - QTI_LIB_COPY=true endif - -snpe_version_check: - @[ ${SNPE_VERSION} = ${QTI_SNPE_VERSION} ] || (echo "SNPE_SDK (${SNPE_VERSION}) doesn't match required version (${QTI_SNPE_VERSION})" && false) - diff --git a/mobile_back_qti/make/qti_backend_targets.mk b/mobile_back_qti/make/qti_backend_targets.mk index a58d3deea..ee92f6260 100644 --- a/mobile_back_qti/make/qti_backend_targets.mk +++ b/mobile_back_qti/make/qti_backend_targets.mk @@ -13,15 +13,16 @@ # limitations under the License. ########################################################################## -libqtibackend: docker_image +.PHONY: libqtibackend +libqtibackend: android/builder-image # Building libqtibackend mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache mkdir -p output/mobile_back_qti docker run \ - ${COMMON_DOCKER_FLAGS} \ + ${ANDROID_COMMON_DOCKER_FLAGS} \ --config android_arm64 //mobile_back_qti:qtibackend cp output/`readlink bazel-bin`/mobile_back_qti/cpp/backend_qti/libqtibackend.so output/mobile_back_qti/libtqtibackend.so - + # You need libasan5 installed to run allocator_test (sudo apt install libasan5) qti_allocator_test: output/mobile_back_qti/test/allocator_test output/mobile_back_qti/test/allocator_test: docker_image @@ -29,7 +30,7 @@ output/mobile_back_qti/test/allocator_test: docker_image mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache mkdir -p output/mobile_back_qti/test docker run \ - ${NATIVE_DOCKER_FLAGS} --experimental_repo_remote_exec \ + ${ANDROID_NATIVE_DOCKER_FLAGS} --experimental_repo_remote_exec \ --config=asan \ //mobile_back_qti/cpp/backend_qti:allocator_test cp output/`readlink bazel-out`/k8-opt/bin/mobile_back_qti/cpp/backend_qti/allocator_test $@ diff --git a/mobile_back_tflite/Makefile b/mobile_back_tflite/Makefile index 7dfe47820..260049f7c 100644 --- a/mobile_back_tflite/Makefile +++ b/mobile_back_tflite/Makefile @@ -32,17 +32,7 @@ cpp/backend_tflite/tflite_settings.h \ cpp/backend_tflite/utils.h \ cpp/backend_tflite/BUILD -ifeq (${USE_PROXY_WORKAROUND},1) - export PROXY_WORKAROUND1=\ - -v /etc/ssl/certs:/etc/ssl/certs \ - -v /usr/share/ca-certificates:/usr/share/ca-certificates \ - -v /usr/share/ca-certificates-java:/usr/share/ca-certificates-java - - export PROXY_WORKAROUND2=--host_jvm_args -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -else - export PROXY_WORKAROUND1= - export PROXY_WORKAROUND2= -endif +include tools/common.mk all: ${BUILDDIR}/lib_x86_64/libtflitebackend.so ${BUILDDIR}/lib_arm64/libtflitebackend.so diff --git a/mobile_back_tflite/tflite_backend.mk b/mobile_back_tflite/tflite_backend.mk index 46d8fa120..c32e17e73 100644 --- a/mobile_back_tflite/tflite_backend.mk +++ b/mobile_back_tflite/tflite_backend.mk @@ -13,9 +13,7 @@ # limitations under the License. ########################################################################## -# Set the included backends -WITH_MEDIATEK=0 - ifeq (${WITH_MEDIATEK},1) - MEDIATEK_BACKEND=--//android/java/org/mlperf/inference:with_mediatek="1" + $(info WITH_MEDIATEK=1) + MEDIATEK_BACKEND_BAZEL_FLAG=--//android/java/org/mlperf/inference:with_mediatek="1" endif diff --git a/tools/common.mk b/tools/common.mk new file mode 100644 index 000000000..00e5f9a33 --- /dev/null +++ b/tools/common.mk @@ -0,0 +1,30 @@ +# Copyright 2021 The MLPerf Authors. 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. +########################################################################## + +ifeq (${USE_PROXY_WORKAROUND},1) + export PROXY_WORKAROUND1=\ + -v /etc/ssl/certs:/etc/ssl/certs \ + -v /usr/share/ca-certificates:/usr/share/ca-certificates \ + -v /usr/share/ca-certificates-java:/usr/share/ca-certificates-java + + export PROXY_WORKAROUND2=--host_jvm_args -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts +endif + +ifeq (${OS},Windows_NT) +# On Windows some commands don't run correctly in the default make shell +_start_args=powershell -Command +else +_start_args= +endif diff --git a/tools/formatter/format.mk b/tools/formatter/format.mk index 9e6b32865..73ab3dcfd 100644 --- a/tools/formatter/format.mk +++ b/tools/formatter/format.mk @@ -1,11 +1,4 @@ -ifeq (${OS},Windows_NT) -# On Windows some commands don't run correctly in the default make shell -_start_args=powershell -Command -else -_start_args= -endif - .PHONY: format ifeq (${OS},Windows_NT) # format/java is not supported on Windows @@ -29,7 +22,7 @@ format/java: .PHONY: format/dart format/dart: cd flutter && ${_start_args} dart run import_sorter:main - cd flutter && ${_start_args} dart format lib integration_test test_driver + dart format flutter/lib flutter/integration_test flutter/test_driver .PHONY: format/line-endings format/line-endings: @@ -44,7 +37,7 @@ lint/bazel: .PHONY: lint/dart lint/dart: - cd flutter && make prepare-flutter + make flutter/prepare-flutter dart analyze flutter .PHONY: lint/prohibited-extensions @@ -86,9 +79,9 @@ output/docker_mlperf_formatter.stamp: tools/formatter/Dockerfile .PHONY: docker/format docker/format: output/docker_mlperf_formatter.stamp docker run -it --rm \ - -v ~/.pub-cache:/home/mlperf/.pub-cache \ - -v ~/.config/flutter:/home/mlperf/.config/flutter \ - -v $(CURDIR):/home/mlperf/mobile_app_open \ - -w /home/mlperf/mobile_app_open \ - -u `id -u`:`id -g` \ - mlperf/formatter bash -c "make format" + -v ~/.pub-cache:/home/mlperf/.pub-cache \ + -v ~/.config/flutter:/home/mlperf/.config/flutter \ + -v $(CURDIR):/home/mlperf/mobile_app_open \ + -w /home/mlperf/mobile_app_open \ + -u `id -u`:`id -g` \ + mlperf/formatter bash -c "make format"