Skip to content

Commit

Permalink
Refactor files to build with new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mcharleb committed Aug 4, 2021
1 parent ac5be1b commit 73475dd
Show file tree
Hide file tree
Showing 56 changed files with 499 additions and 308 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
.aswb
.idea
.vscode
android/bazel-*
android/output
android/output_logs
bazel-*
output
output_logs
*.so
* .apk
* .tflite
Expand Down
66 changes: 34 additions & 32 deletions android/Makefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,22 @@
##########################################################################


#SAMSUNG_BACKEND=--//java/org/mlperf/inference:with_samsung="1"
#SAMSUNG_BACKEND=--//android/java/org/mlperf/inference:with_samsung="1"
SAMSUNG_BACKEND=

#MEDIATEK_BACKEND=--//java/org/mlperf/inference:with_mediatek="1"
#MEDIATEK_BACKEND=--//android/java/org/mlperf/inference:with_mediatek="1"
MEDIATEK_BACKEND=

.PHONY: docker_image app bazel-version tflite_backend_sync rundocker clean
.PHONY: docker_image app bazel-version rundocker clean

all: app

include qti_backend.mk
include android/qti_backend.mk


tflite_backend/.stamp:
git clone -b ${TFLITE_BRANCH} https://github.com/mlcommons/mobile_back_tflite tflite_backend
touch $@

tflite_backend_sync: tflite_backend/.stamp
cd tflite_backend && git fetch && git pull

sync_all: tflite_backend_sync ${QTI_SYNC}

output/mlperf_mobile_docker_0_2.stamp: tflite_backend/.stamp
output/mlperf_mobile_docker_0_2.stamp:
@mkdir -p output/docker
@docker image build -t mlcommons/mlperf_mobile:0.2 tflite_backend/docker/mlperf_mobile
@docker image build -t mlcommons/mlperf_mobile:0.2 android/docker/mlperf_mobile
@touch $@

docker_image: output/mlperf_mobile_docker_0_2.stamp
Expand Down Expand Up @@ -69,60 +60,71 @@ NATIVE_DOCKER_FLAGS= \
${COMMON_DOCKER_FLAGS1} --bazelrc=/dev/null \
${COMMON_DOCKER_FLAGS2}

proto_test: docker_image tflite_backend/.stamp Makefile
proto_test: output/mlperf_mobile_docker_0_2.stamp
@echo "Building proto_test"
@mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache
@docker run \
${NATIVE_DOCKER_FLAGS} --experimental_repo_remote_exec \
//cpp/proto:proto_test
@cp output/`readlink bazel-bin`/cpp/proto/proto_test output/proto_test
//android/cpp/proto:proto_test
@cp output/`readlink bazel-bin`/android/cpp/proto/proto_test output/proto_test
@chmod 777 output/proto_test

main: docker_image tflite_backend/.stamp Makefile
main: output/mlperf_mobile_docker_0_2.stamp
@echo "Building main"
@mkdir -p output/home/mlperf/cache && chmod 777 output/home/mlperf/cache
@docker run \
${COMMON_DOCKER_FLAGS} \
--config android_arm64 //cpp/binary:tflitebackend //cpp/binary:main
--config android_arm64 //mobile_back_tflite:tflitebackend //android/cpp/binary:main
@rm -rf output/binary && mkdir -p output/binary
@cp output/`readlink bazel-bin`/cpp/binary/main output/binary/main
@cp output/`readlink bazel-out`/android-arm64-v8a-opt/bin/external/tflitebackend/cpp/backend_tflite/libtflitebackend.so output/binary/libtflitebackend.so
@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
@chmod 777 output/binary/main output/binary/libtflitebackend.so

app: docker_image tflite_backend/.stamp ${QTI_STAMP} Makefile
libtflite: output/mlperf_mobile_docker_0_2.stamp
@echo "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_0_2.stamp ${QTI_STAMP}
@echo "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} \
--fat_apk_cpu=arm64-v8a \
//java/org/mlperf/inference:mlperf_app
@cp output/`readlink bazel-bin`/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app.apk
//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: docker_image tflite_backend/.stamp ${QTI_STAMP} Makefile
app_x86_64: output/mlperf_mobile_docker_0_2.stamp ${QTI_STAMP}
@echo "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} \
--fat_apk_cpu=x86_64 \
//java/org/mlperf/inference:mlperf_app
@cp output/`readlink bazel-bin`/java/org/mlperf/inference/mlperf_app.apk output/mlperf_app_x86_64.apk
//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: docker_image tflite_backend/.stamp
test_app: 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 \
${COMMON_DOCKER_FLAGS} \
${QTI_BACKEND} ${SAMSUNG_BACKEND} ${MEDIATEK_BACKEND} \
--fat_apk_cpu=x86_64,arm64-v8a \
//androidTest:mlperf_test_app
@cp output/`readlink bazel-bin`/androidTest/mlperf_test_app.apk output/mlperf_test_app.apk
@cp output/`readlink bazel-bin`/android/androidTest/mlperf_test_app.apk output/mlperf_test_app.apk
@chmod 777 output/mlperf_test_app.apk

rundocker: docker_image
rundocker: output/mlperf_mobile_docker_0_2.stamp
@docker run -it \
-e USER=mlperf \
-v $(CURDIR):/home/mlperf/mobile_app \
Expand All @@ -131,7 +133,7 @@ rundocker: docker_image
-u `id -u`:`id -g` \
mlcommons/mlperf_mobile:0.2

rundocker_root: docker_image
rundocker_root: output/mlperf_mobile_docker_0_2.stamp
@docker run -it \
-e USER=mlperf \
-v $(CURDIR):/home/mlperf/mobile_app \
Expand Down
16 changes: 3 additions & 13 deletions android/WORKSPACE → WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ http_archive(
http_archive(
name = "org_tensorflow",
patch_args = ["-p1"],
patches = ["//third_party:tf_grappler_cost.diff"],
patches = ["//android/third_party:tf_grappler_cost.diff"],
sha256 = "1fee58466b88d276f1eb3fb9126b1cd3b261460540b5ac415ca239160e101edb",
strip_prefix = "tensorflow-2.4.0",
urls = [
Expand Down Expand Up @@ -120,25 +120,15 @@ http_archive(
urls = ["https://github.com/MediaTek-NeuroPilot/tflite-neuron-delegate/archive/56908661f2558953d8850cace4d06d049cf4efc3.tar.gz"],
)

local_repository(
name = "tflitebackend",
path = "tflite_backend",
)

local_repository(
name = "qtibackend",
path = "qti_backend",
)

new_local_repository(
name = "samsungbackend",
build_file = "samsung_backend/BUILD",
path = "samsung_backend",
path = "mobile_back_samsung",
)

http_archive(
name = "org_mlperf_inference",
build_file = "@//third_party:loadgen.BUILD",
build_file = "@//android/third_party:loadgen.BUILD",
patch_cmds = ["python loadgen/version_generator.py loadgen/version_generated.cc loadgen"],
sha256 = "900053d97d4165396c45ec13dd211ea3cb3306a6c496b0172f7093e9fc5ebc47",
strip_prefix = "inference-dd9e6bf867869fad0b9fcade0f719e1536780299",
Expand Down
8 changes: 4 additions & 4 deletions android/commonlibs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ cc_library(
}),
data = select({
"android_arm64": [
"//commonlibs:asan_arm64",
"//android/commonlibs:asan_arm64",
],
"android_x86_64": [
"//commonlibs:asan_x86_64",
"//android/commonlibs:asan_x86_64",
],
"//conditions:default": [],
}),
Expand All @@ -120,13 +120,13 @@ cc_library(
}),
data = select({
"android_arm64": [
"//commonlibs:libcpp_shared_arm64",
"//android/commonlibs:libcpp_shared_arm64",
],
"//conditions:default": [],
}),
deps = select({
":use_asan": [
"//commonlibs:asan_lib",
"//android/commonlibs:asan_lib",
],
"//conditions:default": [],
}),
Expand Down
12 changes: 6 additions & 6 deletions android/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ common_linkopts = tflite_linkopts() + select({
"-pie",
],
}) + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -44,7 +44,7 @@ cc_library(
"mlperf_driver.h",
],
copts = tflite_copts() + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -54,7 +54,7 @@ cc_library(
}),
deps = [
":utils",
"//cpp/proto:mlperf_task_cc_proto",
"//android/cpp/proto:mlperf_task_cc_proto",
"@org_mlperf_inference//:loadgen",
],
)
Expand All @@ -65,7 +65,7 @@ cc_library(
"utils.h",
],
copts = tflite_copts() + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -74,10 +74,10 @@ cc_library(
"//conditions:default": [],
}),
deps = [
"//cpp/proto:mlperf_task_cc_proto",
"//android/cpp/proto:mlperf_task_cc_proto",
"@org_mlperf_inference//:loadgen",
"@org_tensorflow//tensorflow/core:tflite_portable_logging",
"@tflitebackend//cpp/c:headers",
"//android/cpp/c:headers",
],
)

Expand Down
4 changes: 2 additions & 2 deletions android/cpp/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.

#include <vector>

#include "cpp/proto/backend_setting.pb.h"
#include "cpp/utils.h"
#include "android/cpp/proto/backend_setting.pb.h"
#include "android/cpp/utils.h"
#include "loadgen/system_under_test.h"

namespace mlperf {
Expand Down
10 changes: 5 additions & 5 deletions android/cpp/backends/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cc_library(
"external.h",
],
copts = tflite_copts() + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -39,10 +39,10 @@ cc_library(
"//conditions:default": [],
}),
deps = [
"//cpp:mlperf_driver",
"//cpp:utils",
"//cpp/datasets:allocator",
"//cpp/proto:mlperf_task_cc_proto",
"//android/cpp:mlperf_driver",
"//android/cpp:utils",
"//android/cpp/datasets:allocator",
"//android/cpp/proto:mlperf_task_cc_proto",
"@org_tensorflow//tensorflow/lite:shared_library",
],
)
6 changes: 3 additions & 3 deletions android/cpp/backends/external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ 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.
==============================================================================*/
#include "cpp/backends/external.h"
#include "android/cpp/backends/external.h"

#include <memory>
#include <string>
#include <vector>

#include "cpp/backend.h"
#include "cpp/utils.h"
#include "android/cpp/backend.h"
#include "android/cpp/utils.h"
#include "tensorflow/lite/shared_library.h"

namespace mlperf {
Expand Down
10 changes: 5 additions & 5 deletions android/cpp/backends/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ limitations under the License.
#ifndef MLPERF_BACKENDS_EXTERNAL_H_
#define MLPERF_BACKENDS_EXTERNAL_H_

#include "cpp/backend.h"
#include "cpp/c/type.h"
#include "cpp/datasets/allocator.h"
#include "cpp/proto/backend_setting.pb.h"
#include "cpp/utils.h"
#include "android/cpp/backend.h"
#include "android/cpp/c/type.h"
#include "android/cpp/datasets/allocator.h"
#include "android/cpp/proto/backend_setting.pb.h"
#include "android/cpp/utils.h"
#include "tensorflow/lite/shared_library.h"

namespace mlperf {
Expand Down
27 changes: 10 additions & 17 deletions android/cpp/binary/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ common_linkopts = tflite_linkopts() + select({
"-pie",
],
}) + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -38,7 +38,7 @@ cc_binary(
name = "main",
srcs = ["main.cc"],
copts = tflite_copts() + select({
"//commonlibs:use_asan": [
"//android/commonlibs:use_asan": [
"-fsanitize=address",
"-g",
"-O1",
Expand All @@ -48,22 +48,15 @@ cc_binary(
}),
linkopts = common_linkopts,
deps = [
"//cpp:mlperf_driver",
"//cpp:utils",
"//cpp/backends:external",
"//cpp/datasets:ade20k",
"//cpp/datasets:coco",
"//cpp/datasets:imagenet",
"//cpp/datasets:squad",
"//cpp/proto:mlperf_task_cc_proto",
"//android/cpp:mlperf_driver",
"//android/cpp:utils",
"//android/cpp/backends:external",
"//android/cpp/datasets:ade20k",
"//android/cpp/datasets:coco",
"//android/cpp/datasets:imagenet",
"//android/cpp/datasets:squad",
"//android/cpp/proto:mlperf_task_cc_proto",
"@com_google_absl//absl/strings",
"@org_tensorflow//tensorflow/lite/tools:command_line_flags",
],
)

cc_library(
name = "tflitebackend",
deps = [
"@tflitebackend",
],
)
Loading

0 comments on commit 73475dd

Please sign in to comment.