Skip to content

Commit

Permalink
Move make targets to separate files included into root makefile (mlco…
Browse files Browse the repository at this point in the history
…mmons#167)

* refactor root makefile

Signed-off-by: Danil Uzlov <[email protected]>

* rename docker flags var

Signed-off-by: Danil Uzlov <[email protected]>

* fix spaces in makefiles

Signed-off-by: Danil Uzlov <[email protected]>

* refactor qti makefile

Signed-off-by: Danil Uzlov <[email protected]>

* extract proxy args to common.mk

Signed-off-by: Danil Uzlov <[email protected]>

* extract android make targets to separate makefile

Signed-off-by: Danil Uzlov <[email protected]>

* allow to interrupt build in android docker

Signed-off-by: Danil Uzlov <[email protected]>

* refactor makefiles

Signed-off-by: Danil Uzlov <[email protected]>

* rename vendor backend flag vars

Signed-off-by: Danil Uzlov <[email protected]>

* add WITH_MEDIATEK info print

Signed-off-by: Danil Uzlov <[email protected]>

* rename make targets for flutter app

Signed-off-by: Danil Uzlov <[email protected]>

* rename flutter makefile

Signed-off-by: Danil Uzlov <[email protected]>

* integrate flutter makefile into root makefile

Signed-off-by: Danil Uzlov <[email protected]>

* remove deprecated documentation

Signed-off-by: Danil Uzlov <[email protected]>

* update flutter app documentation

Signed-off-by: Danil Uzlov <[email protected]>

* adjust windows container make targets (not tested)

Signed-off-by: Danil Uzlov <[email protected]>

* update android readme

Signed-off-by: Danil Uzlov <[email protected]>

* fix root makefile

Signed-off-by: Danil Uzlov <[email protected]>

* fix datasets makefile

Signed-off-by: Danil Uzlov <[email protected]>

* fix formatting

Signed-off-by: Danil Uzlov <[email protected]>

* add makefile for ios CI

Signed-off-by: Danil Uzlov <[email protected]>

* update flutter android ci config

Signed-off-by: Danil Uzlov <[email protected]>

* update readmes

Signed-off-by: Danil Uzlov <[email protected]>

* update flutter readme

Signed-off-by: Danil Uzlov <[email protected]>

* fix ci

Signed-off-by: Danil Uzlov <[email protected]>

* pin flutter version on CI

Signed-off-by: Danil Uzlov <[email protected]>

* return info about formatting tools in macos

Signed-off-by: Danil Uzlov <[email protected]>
  • Loading branch information
d-uzlov authored Dec 10, 2021
1 parent 88955ab commit 0e16198
Show file tree
Hide file tree
Showing 29 changed files with 662 additions and 589 deletions.
3 changes: 1 addition & 2 deletions .github/cloudbuild/flutter-android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
136 changes: 9 additions & 127 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
```

Expand Down
147 changes: 147 additions & 0 deletions android/android.mk
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion android/docker/mlperf_mobile/Dockerfile
Original file line number Diff line number Diff line change
@@ -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="[email protected]"

Expand Down
4 changes: 2 additions & 2 deletions android/docs/development/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 build artifacts from desired branch> 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):**
Expand All @@ -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 build artifacts from desired branch> 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
Expand Down
Loading

0 comments on commit 0e16198

Please sign in to comment.