Skip to content

Commit

Permalink
Added more plumbing for QTI and Mediatek backends
Browse files Browse the repository at this point in the history
  • Loading branch information
mcharleb committed Aug 5, 2021
1 parent 73475dd commit 5ad1a1b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 38 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ MEDIATEK_BACKEND=

all: app

include android/qti_backend.mk
include mobile_back_tflite/tflite_backend.mk
include mobile_back_qti/qti_backend.mk


output/mlperf_mobile_docker_0_2.stamp:
Expand Down Expand Up @@ -69,15 +70,16 @@ proto_test: output/mlperf_mobile_docker_0_2.stamp
@cp output/`readlink bazel-bin`/android/cpp/proto/proto_test output/proto_test
@chmod 777 output/proto_test

main: output/mlperf_mobile_docker_0_2.stamp
main: output/mlperf_mobile_docker_0_2.stamp ${QTI_DEPS}
@echo "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 //android/cpp/binary:main
--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_0_2.stamp
Expand All @@ -91,7 +93,7 @@ libtflite: output/mlperf_mobile_docker_0_2.stamp
@chmod 777 output/binary/libtflitebackend.so


app: output/mlperf_mobile_docker_0_2.stamp ${QTI_STAMP}
app: output/mlperf_mobile_docker_0_2.stamp ${QTI_DEPS}
@echo "Building mlperf_app.apk"
@mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache
@docker run \
Expand All @@ -102,7 +104,7 @@ app: output/mlperf_mobile_docker_0_2.stamp ${QTI_STAMP}
@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_0_2.stamp ${QTI_STAMP}
app_x86_64: output/mlperf_mobile_docker_0_2.stamp
@echo "Building mlperf_app.apk"
@mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache
@docker run \
Expand Down
5 changes: 2 additions & 3 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ frameworks contributed by the broader MLPerf community.
* [Android SDK](https://developer.android.com/studio)
* Android 10.0+ (API 29) w/
[USB debugging enabled](https://developer.android.com/studio/debug/dev-options)
* SNPE prebuilt backend repository extracted to "./qti_backend"

## Getting Started

Expand Down Expand Up @@ -84,11 +83,11 @@ make app
```
or to enable the QTI backend:
```
make QTI_BRANCH=master app
make WITH_QTI=1 app
```
or to enable both the MediaTek and QTI backends:
```
make QTI_BRANCH=master MEDIATEK_BACKEND=--//java/org/mlperf/inference:with_mediatek="1" app
make WITH_QTI=1 WITH_MEDIATEK=1 app
```

# Install the app with the command:
Expand Down
12 changes: 7 additions & 5 deletions mobile_back_qti/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ config_setting(
values = {"cpu": "arm64-v8a"},
)

load("//:variables.bzl", "SNPE_VERSION")
load("//mobile_back_qti:variables.bzl", "SNPE_VERSION")

cc_library(
name = "snpe",
Expand Down Expand Up @@ -53,10 +53,12 @@ cc_library(
cc_library(
name = "qtibackend",
srcs = select({
"//conditions:default": ["//cpp/backend_mock_qti:libqtibackend.so"],
":android_arm64": [
"//cpp/backend_qti:libqtibackend.so",
],
"//conditions:default": ["//mobile_back_qti/cpp/backend_mock_qti:libqtibackend.so"],
# TODO: Add proper handling for QTI devices
":android_arm64": [ "//mobile_back_qti/cpp/backend_mock_qti:libqtibackend.so"],
# ":android_arm64": [
# "//mobile_back_qti/cpp/backend_qti:libqtibackend.so",
# ],
}),
deps = select({
"//conditions:default": [],
Expand Down
4 changes: 2 additions & 2 deletions mobile_back_qti/cpp/backend_mock_qti/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ cc_library(
srcs = ["qti_mock_c.cc"],
copts = tflite_copts(),
deps = [
"//cpp/c:headers",
"//android/cpp/c:headers",
],
alwayslink = 1,
)

tflite_jni_binary(
name = "libqtibackend.so",
linkscript = "//cpp/c:version_script.lds",
linkscript = "//android/cpp/c:version_script.lds",
deps = [":qti_mock",],
)

40 changes: 18 additions & 22 deletions android/qti_backend.mk → mobile_back_qti/qti_backend.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
##########################################################################

.PHONY: qti_backend_sync
.PHONY: snpe_version_check

ifeq (${USE_PROXY_WORKAROUND},1)
export PROXY_WORKAROUND1=\
Expand All @@ -28,38 +28,34 @@ else
endif

# Set the included backends
#QTI_BRANCH=master
QTI_BRANCH=
TFLITE_BRANCH=main
WITH_QTI=0

ifneq (${QTI_BRANCH},)
ifeq (${WITH_QTI},1)
ifneq (${SNPE_SDK},)
QTI_BACKEND=--//java/org/mlperf/inference:with_qti="1"
QTI_STAMP=qti_backend/.stamp
QTI_SYNC=qti_backend_sync
QTI_BACKEND=--//android/java/org/mlperf/inference:with_qti="1"
QTI_TARGET=//mobile_back_qti:qtibackend
# TODO: Change to backend_qti when bqckend_qti is enabled
QTI_LIB_COPY=cp output/`readlink bazel-bin`/mobile_back_qti/cpp/backend_mock_qti/libqtibackend.so output/binary/libqtibackend.so
SNPE_VERSION=$(shell basename ${SNPE_SDK})
QTI_SNPE_VERSION=$(shell grep SNPE_VERSION qti_backend/variables.bzl | cut -d\" -f2)
QTI_VOLUMES=-v ${SNPE_SDK}:/home/mlperf/mobile_app/qti_backend/${SNPE_VERSION}
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_STAMP=
QTI_SYNC=
QTI_VOLUMES=
QTI_DEPS=
QTI_TARGET=
QTI_LIB_COPY=true
endif
else
QTI_BACKEND=
QTI_STAMP=
QTI_SYNC=
QTI_VOLUMES=
QTI_DEPS=
QTI_TARGET=
QTI_LIB_COPY=true
endif

qti_backend/.stamp:
git clone -b ${QTI_BRANCH} https://github.com/mlcommons/mobile_back_qualcomm qti_backend
touch $@

qti_backend_sync: qti_backend/.stamp
[ ${SNPE_VERSION} = ${QTI_SNPE_VERSION} ] || (echo "SNPE_SDK is not ${QTI_SNPE_VERSION}" && fail)
(cd qti_backend && [ `git branch` = ${QTI_BRANCH} ]) || (echo "Checked out mobile_back_qualcomm branch is not ${QTI_BRANCH}" && fail)
cd qti_backend && git fetch && git pull
snpe_version_check:
@[ ${SNPE_VERSION} = ${QTI_SNPE_VERSION} ] || (echo "SNPE_SDK (${SNPE_VERSION}) doesn't match required version (${QTI_SNPE_VERSION})" && false)

1 change: 1 addition & 0 deletions mobile_back_qti/variables.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SNPE_VERSION = "snpe-1.48.0.2554"
2 changes: 1 addition & 1 deletion mobile_back_tflite/cpp/backend_tflite/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ tflite_jni_binary(

tflite_jni_binary(
name = "libtfliteneuronbackend.so",
exported_symbols = "//mobile_back_tflite/cpp/c:exported_symbols.lds",
exported_symbols = "//android/cpp/c:exported_symbols.lds",
linkscript = "//android/cpp/c:version_script.lds",
deps = [
":tflite_neuron_c",
Expand Down
21 changes: 21 additions & 0 deletions mobile_back_tflite/tflite_backend.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.
##########################################################################

# Set the included backends
WITH_MEDIATEK=0

ifeq (${WITH_MEDIATEK},1)
MEDIATEK_BACKEND=--//android/java/org/mlperf/inference:with_mediatek="1"
endif

0 comments on commit 5ad1a1b

Please sign in to comment.