Delete `tools/android/run_module_app`. (#15909)
This code looks stale. Is anyone using it? (It does look useful, but I
think more developers are using CLI profiling tools like Tracy and
simpleperf instead of app profiling tools like AGI)
Android (and iOS) application sample code would still be useful in some
form (e.g. https://github.com/not-jenni/iree-android-tflite-demo). I
don't think that `tools/android/run_module_app/build_apk.sh` is
something that users should be referencing (too different from standard
application development/packaging), so keeping this code around just
adds extra complexity if developers aren't using it.
Fixes https://github.com/openxla/iree/issues/12318
diff --git a/docs/website/docs/developers/performance/profiling-gpu-vulkan.md b/docs/website/docs/developers/performance/profiling-gpu-vulkan.md
index 788dda5..748187e 100644
--- a/docs/website/docs/developers/performance/profiling-gpu-vulkan.md
+++ b/docs/website/docs/developers/performance/profiling-gpu-vulkan.md
@@ -49,74 +49,7 @@
There are multiple GPU vendors for the Android platforms, each offering their
own tools. [Android GPU Inspector](https://gpuinspector.dev/)
(AGI) provides a cross-vendor solution. See the
-[documentation](https://gpuinspector.dev/docs/) for more details.
-
-### Build Android app to run IREE
-
-In order to perform capture and analysis with AGI, you will need a full Android
-app. In IREE we have a simple Android native app wrapper to help package
-IREE core libraries together with a specific VM bytecode invocation into an
-Android app. The wrapper and its documentation are placed at
-[`tools/android/run_module_app/`](https://github.com/openxla/iree/tree/main/tools/android/run_module_app).
-
-For example, to package a module compiled from the following
-`stablehlo-dot.mlir` as an Android app:
-
-```mlir
-func @dot(%lhs: tensor<2x4xf32>, %rhs: tensor<4x2xf32>) -> tensor<2x2xf32> {
- %0 = "stablehlo.dot"(%lhs, %rhs) : (tensor<2x4xf32>, tensor<4x2xf32>) -> tensor<2x2xf32>
- return %0 : tensor<2x2xf32>
-}
-```
-
-```shell
-# First compile into a VM bytecode module
-$ /path/to/iree/build/tools/iree-compile -- \
- --iree-input-type=stablehlo \
- --iree-hal-target-backends=vulkan-spirv \
- /path/to/stablehlo-dot.mlir \
- -o /tmp/stablehlo-dot.vmfb
-
-# Then package the Android app
-$ /path/to/iree/source/tools/android/run_module_app/build_apk.sh \
- ./build-apk \
- --device vulkan \
- --module /tmp/stablehlo-dot.vmfb \
- --function dot \
- --input=...
-```
-
-Where `/path/to/input/file` is a file containing inputs to `dot`, for example:
-
-``` text
-2x4xf32=[[1.0 2.0 3.0 4.0][5.0 6.0 7.0 8.0]]
-4x2xf32=[[9.0 10.0][11.0 12.0][13.0 14.0][15.0 16.0]]
-```
-
-The above will build an `iree-run-module.apk` under the `./build-apk/`
-directory, which you can then install via `adb install`.
-
-`build_apk.sh` needs the Android SDK and NDK internally, an easy way to manage
-them is by installing [Android Studio](https://developer.android.com/studio).
-After installation, you will need to set up a few environment variables, which
-are printed at the beginning of `build_apk.sh` invocation.
-
-### Capture and analyze with AGI
-
-You can follow AGI's
-[Getting Started](https://gpuinspector.dev/docs/getting-started) page to learn
-how to use it. In general the steps are:
-
-* Install the latest AGI from <https://github.com/google/agi/releases> and launch.
-* Fill in the "Application" field by searching the app. The line should read
- like `android.intent.action.MAIN:dev.iree.run_module/android.app.NativeActivity`.
-* Select start at beginning and choose a proper duration.
-* Configure system profile to include all GPU counters.
-* Start capture.
-
-Generated traces are in the [perfetto](https://perfetto.dev/) format. They can
-be viewed directly within AGI and also online in a browser at
-<https://ui.perfetto.dev/>, without needing an Android device.
+[documentation](https://developer.android.com/agi) for more details.
## Desktop GPUs
diff --git a/tools/android/CMakeLists.txt b/tools/android/CMakeLists.txt
deleted file mode 100644
index 1033e14..0000000
--- a/tools/android/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-iree_add_all_subdirs()
diff --git a/tools/android/run_module_app/AndroidManifest.xml.template b/tools/android/run_module_app/AndroidManifest.xml.template
deleted file mode 100644
index f39458f..0000000
--- a/tools/android/run_module_app/AndroidManifest.xml.template
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2020 The IREE Authors
-
- Licensed under the Apache License v2.0 with LLVM Exceptions.
- See https://llvm.org/LICENSE.txt for license information.
- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- android:versionCode="1"
- android:versionName="1.0"
- package="dev.iree.run_module">
- <!-- Vulkan 1.1 is introduced in Android 9 (API level 28) so we can support
- that as a minimum. -->
- <uses-sdk android:minSdkVersion="28"
- android:targetSdkVersion="${IREE_ANDROID_API_LEVEL}" />
-
- <application android:label="@string/app_name"
- android:debuggable="true"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
- <!-- The convenience NativeActivity allows us to purely use native code
- and the NDK for the app. -->
- <activity android:name="android.app.NativeActivity"
- android:label="@string/app_name"
- android:configChanges="orientation|keyboardHidden">
- <!-- Specify the shared library to load for NativeActivity. -->
- <meta-data android:name="android.app.lib_name"
- android:value="iree_run_module_app" />
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tools/android/run_module_app/CMakeLists.txt b/tools/android/run_module_app/CMakeLists.txt
deleted file mode 100644
index 4d36e80..0000000
--- a/tools/android/run_module_app/CMakeLists.txt
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-if(NOT ANDROID)
- return()
-endif()
-
-set(NATIVE_APP_GLUE_DIR "${ANDROID_NDK}/sources/android/native_app_glue")
-
-iree_cc_library(
- NAME
- android_native_app_glue
- SRCS
- "${NATIVE_APP_GLUE_DIR}/android_native_app_glue.c"
-)
-
-# Export ANativeActivity_onCreate().
-# See https://github.com/android-ndk/ndk/issues/381.
-set(CMAKE_SHARED_LINKER_FLAGS
- "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
-
-iree_cc_library(
- NAME
- iree_run_module_app
- SRCS
- src/main.cc
- INCLUDES
- ${NATIVE_APP_GLUE_DIR}
- DEPS
- ::android_native_app_glue
- iree::base
- iree::modules::hal
- iree::tooling::device_util
- iree::tooling::vm_util
- iree::vm
- LINKOPTS
- "-landroid"
- "-llog"
- SHARED
-)
diff --git a/tools/android/run_module_app/README.md b/tools/android/run_module_app/README.md
deleted file mode 100644
index 6b7dfaa..0000000
--- a/tools/android/run_module_app/README.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# Android App to Run an IREE Bytecode Module
-
-This directory contains configuration to create an Android application that
-executes a single IREE module as a native activity.
-
-Note that this app is **purely** for benchmarking/profiling IREE itself.
-This is not the expected integration path for a real Android application,
-for which we expect to provide proper Java API and build support.
-
-## Native Activity
-
-The app uses Android [`NativeActivity`][native-activity] to bridge IREE core
-libraries together with the Android system. Native activity allows one to
-implement an Android Activity purely in C/C++. There are
-[tutorials][native-activity-tutorial] and [examples][native-activity-example]
-one can follow to learn about Native Activity.
-
-## Android Studio
-
-This app does not contain Gradle configurations. The reason is that we need
-to package both IREE native libraries and a specific VM module invocation
-into the app. The procedure cannot be automated much by Android Studio; rather
-one might need to copy files from different places, rename them, and wire up
-the build. It's inconvenient. For a developer tool we would like to avoid
-such friction and thus improve velocity. So a script,
-[`build_apk.sh`](./build_apk.sh), is provided to automate the process.
-
-But the script itself requires an Android SDK/NDK installation structure that
-matches Android Studio. So it's easier to just install Android Studio to
-manage Android SDK/NDK. The script will use proper tools in Android SDK/NDK
-to build and package the final APK file.
-
-## Build the APK
-
-In general, we need to
-
-1. Build the `iree_run_module_app` shared library following normal C++ build
- process.
-1. Package the shared library together with an IREE VM FlatBuffer, its entry
- function, input buffers, and the HAL driver into an Android app, following
- a certain directory hierarchy. Specifically,
- 1. Generate `AndroidManifest.xml` from the
- [template](./AndroidManifest.xml.template) by providing the proper target
- Android API level.
- 1. Copy the VM FlatBuffer as `assets/module.vmfb`, write the entry function
- input buffers, and HAL driver into `assets/entry_function.txt`,
- `assets/inputs.txt`, and `assets/device.txt`, respectively.
- 1. Copy the shared library under `lib/<android-abi>/`.
- 1. Compile resources under [`res/`](./res) directory into an Android DEX
- file.
- 1. Package all of the above into an APK file.
- 1. Properly align and sign the APK file.
-
-## Run on Android
-
-When started on Android, the app will read the contents in `assets` to get the
-VM FlatBuffer and invocation information and run it.
-
-[native-activity]: https://developer.android.com/reference/android/app/NativeActivity
-[native-activity-example]: https://github.com/android/ndk-samples/tree/main/native-activity
-[native-activity-tutorial]: https://medium.com/androiddevelopers/getting-started-with-c-and-android-native-activities-2213b402ffff
diff --git a/tools/android/run_module_app/build_apk.sh b/tools/android/run_module_app/build_apk.sh
deleted file mode 100644
index b7ef3ed..0000000
--- a/tools/android/run_module_app/build_apk.sh
+++ /dev/null
@@ -1,272 +0,0 @@
-#!/bin/bash
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-set -e
-
-#########################
-# Script input parameters
-#########################
-
-echo "=== A script for building iree-run-module apk ==="
-echo "This script wraps iree-run-module together with a"
-echo "specific IREE VM module and invocation information."
-echo ""
-echo "At a minimum, it expects the following env vars:"
-echo "* ANDROID_SDK_ROOT"
-echo "* ANDROID_NDK_ROOT"
-echo "* ANDROID_SDK_BUILD_TOOLS_VERSION"
-echo "See the script for details and more controls."
-echo "===-------------------------------------------==="
-echo ""
-
-print_usage_and_exit() {
- echo "Usage: $0 <artifact-directory> "
- echo " --device <device>"
- echo " --module <input-module-file> "
- echo " --function <entry-function> "
- echo " --inputs_file <input-buffer-file> "
- exit 1
-}
-
-while (( "$#" )); do
- case "$1" in
- --device)
- if [[ -n "$2" ]] && [[ ${2:0:1} != "-" ]]; then
- IREE_DEVICE=$2
- shift 2
- else
- echo "Error: missing argument for $1" >&2
- print_usage_and_exit
- fi
- ;;
- --module)
- if [[ -n "$2" ]] && [[ ${2:0:1} != "-" ]]; then
- IREE_INPUT_MODULE_FILE=$(readlink -f $2)
- shift 2
- else
- echo "Error: missing argument for $1" >&2
- print_usage_and_exit
- fi
- ;;
- --function)
- if [[ -n "$2" ]] && [[ ${2:0:1} != "-" ]]; then
- IREE_ENTRY_FUNCTION=$2
- shift 2
- else
- echo "Error: missing argument for $1" >&2
- print_usage_and_exit
- fi
- ;;
- --inputs_file)
- if [[ -n "$2" ]] && [[ ${2:0:1} != "-" ]]; then
- IREE_INPUT_BUFFER_FILE=$(readlink -f $2)
- shift 2
- else
- echo "Error: missing argument for $1" >&2
- print_usage_and_exit
- fi
- ;;
- -*|--*=) # Unsupported flags
- echo "Error: Unsupported flag $1" >&2
- exit 1
- ;;
- *) # Positional arguments
- if [[ -z "${IREE_ARTIFACT_ROOT+x}" ]]; then
- IREE_ARTIFACT_ROOT=$(readlink -f $1)
- else
- echo "Error: <artifact-directory> already set to ${IREE_ARTIFACT_ROOT}" >&2
- print_usage_and_exit
- fi
- shift
- ;;
- esac
-done
-
-if [[ -z "${IREE_ARTIFACT_ROOT}" ]] || [[ -z "${IREE_INPUT_MODULE_FILE}" ]] || \
- [[ -z "${IREE_ENTRY_FUNCTION}" ]] || [[ -z "${IREE_INPUT_BUFFER_FILE}" ]] || \
- [[ -z "${IREE_DEVICE}" ]]; then
- echo "Error: missing necessary parameters" >&2
- print_usage_and_exit
-fi
-
-#################################
-# IREE Android app configurations
-#################################
-
-# The final Android APK name; default to "iree-run-module.apk".
-IREE_APK_NAME="${IREE_APK_NAME:-iree-run-module}"
-# The CMAKE build type for compiling IREE. default to Release.
-IREE_BUILD_TYPE="${IREE_BUILD_TYPE:-Release}"
-# The target Android API level; default to Android 10 (API level 29).
-IREE_ANDROID_API_LEVEL="${IREE_ANDROID_API_LEVEL:-29}"
-# The target Android platform ABI; default to arm64-v8a.
-IREE_ANDROID_ABI="${IREE_ANDROID_ABI:-arm64-v8a}"
-
-################################
-# Android SDK/NDK configurations
-################################
-
-# Android SDK root; must be provided as environment variable.
-# By default Android Studio uses
-# * $HOME/Android/Sdk for Linux.
-# * $HOME/Library/Android/sdk for macOS.
-# * $%LOCALAPPDATA%\Android\sdk for Windows.
-ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:?environment variable not set}"
-# Android NDK root; must be provided as environment variable.
-ANDROID_NDK_ROOT="${ANDROID_NDK_ROOT:?environment variable not set}"
-# Android SDK build tools version; must be provided as environment variable.
-ANDROID_SDK_BUILD_TOOLS_VERSION="${ANDROID_SDK_BUILD_TOOLS_VERSION?environment variable not set}"
-# Key store for signing apk files; default to Android debug keystore created
-# by Android Studio.
-ANDROID_KEYSTORE="${ANDROID_KEYSTORE:-${HOME}/.android/debug.keystore}"
-
-######################
-# IREE build toolchain
-######################
-
-CMAKE_BIN="${CMAKE_BIN:-$(which cmake)}"
-NINJA_BIN="${NINJA_BIN:-$(which ninja)}"
-CC_BIN="${CC_BIN:-$(which clang)}"
-CXX_BIN="${CXX_BIN:-$(which clang++)}"
-JAVAC_BIN="${JAVAC_BIN:-$(which javac)}"
-
-##################################
-# IREE source/artifact directories
-##################################
-
-# IREE project source root.
-IREE_SOURCE_ROOT="$(git rev-parse --show-toplevel)"
-# iree-run-module Android app source root.
-IREE_NATIVE_APP_SOURCE_ROOT="${IREE_SOURCE_ROOT?}/tools/android/run_module_app"
-
-# Directory for IREE native code intermediate intermediate artifacts.
-IREE_NATIVE_LIB_BUILD_DIR="${IREE_ARTIFACT_ROOT?}/iree/${IREE_BUILD_TYPE?}"
-# Directory for holding APK parts.
-IREE_APK_PARTS_DIR="${IREE_ARTIFACT_ROOT?}/parts"
-# Directory for IREE native libraries.
-IREE_NATIVE_LIB_DIR="${IREE_APK_PARTS_DIR?}/libs/lib/${IREE_ANDROID_ABI?}"
-# Directory for Android app assets.
-IREE_ASSET_DIR="${IREE_APK_PARTS_DIR?}/assets"
-# Directory for Android app R.class.
-IREE_RESOURCE_GEN_DIR="${IREE_APK_PARTS_DIR?}/rclass"
-
-#########################
-# Android build toolchain
-#########################
-
-ANDROID_SDK_BUILD_TOOLS_DIR="${ANDROID_SDK_ROOT?}/build-tools/${ANDROID_SDK_BUILD_TOOLS_VERSION?}"
-ANDROID_SDK_PLATFORMS_DIR="${ANDROID_SDK_ROOT?}/platforms/android-${IREE_ANDROID_API_LEVEL?}"
-
-AAPT_BIN="${ANDROID_SDK_BUILD_TOOLS_DIR?}/aapt"
-DX_BIN="${ANDROID_SDK_BUILD_TOOLS_DIR?}/dx"
-ZIPALIGN_BIN="${ANDROID_SDK_BUILD_TOOLS_DIR?}/zipalign"
-APKSIGNER_BIN="${ANDROID_SDK_BUILD_TOOLS_DIR?}/apksigner"
-
-AAPT_ADD="${AAPT_BIN?} add"
-# Link in the Android framework classes and disable compression for IREE
-# bytecode modules. This allows us to mmap the file directly.
-AAPT_PACK="${AAPT_BIN?} package -f -I ${ANDROID_SDK_PLATFORMS_DIR?}/android.jar -0 vmfb"
-DX="${DX_BIN?} --dex"
-ZIPALIGN="${ZIPALIGN_BIN?} -f -p 4"
-APKSIGN="${APKSIGNER_BIN?} sign"
-JAVAC="${JAVAC_BIN?} -classpath ${ANDROID_SDK_PLATFORMS_DIR?}/android.jar -sourcepath ${IREE_RESOURCE_GEN_DIR?} -d ${IREE_APK_PARTS_DIR?}"
-
-#############################
-# Build IREE native libraries
-#############################
-
-mkdir -p "${IREE_NATIVE_LIB_BUILD_DIR?}"
-
-echo ">>> Building IREE native libraries <<<"
-
-IREE_NATIVE_LIB_NAME=iree_tools_android_run_module_app_iree_run_module_app
-
-pushd "${IREE_NATIVE_LIB_BUILD_DIR?}"
-"${CMAKE_BIN?}" "${IREE_SOURCE_ROOT?}" -G Ninja \
- -DCMAKE_BUILD_TYPE="${IREE_BUILD_TYPE?}" \
- -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT?}/build/cmake/android.toolchain.cmake" \
- -DANDROID_ABI="${IREE_ANDROID_ABI?}" \
- -DANDROID_PLATFORM="android-${IREE_ANDROID_API_LEVEL?}" \
- -DIREE_HOST_C_COMPILER="${CC_BIN?}" \
- -DIREE_HOST_CXX_COMPILER="${CXX_BIN?}" \
- -DIREE_BUILD_COMPILER=OFF \
- -DIREE_BUILD_TESTS=OFF \
- -DIREE_BUILD_SAMPLES=OFF
-"${NINJA_BIN?}" "${IREE_NATIVE_LIB_NAME?}"
-popd
-
-#####################
-# Package Android app
-#####################
-
-# Clean artifacts from previous runs.
-rm -rf "${IREE_ARTIFACT_ROOT?}/${IREE_APK_NAME?}.apk" "${IREE_APK_PARTS_DIR?}"
-
-echo ">>> Generating AndroidManifest.xml <<<"
-
-# Create an AndroidManifest.xml with proper target SDK version.
-mkdir -p "${IREE_APK_PARTS_DIR?}"
-IREE_ANDROID_API_LEVEL="${IREE_ANDROID_API_LEVEL?}" envsubst \
- < "${IREE_NATIVE_APP_SOURCE_ROOT?}/AndroidManifest.xml.template" \
- > "${IREE_APK_PARTS_DIR?}/AndroidManifest.xml"
-
-echo ">>> Preparing shared libraries and vm module information <<<"
-
-# Find the compiled iree_run_module_app shared library and symlink it to a
-# known location for packaging.
-mkdir -p "${IREE_NATIVE_LIB_DIR?}"
-IREE_NATIVE_LIB=$(find ${IREE_NATIVE_LIB_BUILD_DIR?} -name "lib${IREE_NATIVE_LIB_NAME?}.so")
-# Note: the target link name must match with
-# run_module_app/AndroidManifest.xml.template.
-ln -sf "${IREE_NATIVE_LIB?}" "${IREE_NATIVE_LIB_DIR?}/libiree_run_module_app.so"
-
-# Copy the VM FlatBuffer and iree-run-module invocation related information
-# over as assets.
-mkdir -p "${IREE_ASSET_DIR?}"
-# Note: the following files must match with run_module_app/src/main.cc.
-cp "${IREE_INPUT_MODULE_FILE?}" "${IREE_ASSET_DIR?}/module.vmfb"
-cp "${IREE_INPUT_BUFFER_FILE?}" "${IREE_ASSET_DIR?}/inputs.txt"
-echo -n "${IREE_ENTRY_FUNCTION?}" > "${IREE_ASSET_DIR?}/entry_function.txt"
-echo -n "${IREE_DEVICE?}" > "${IREE_ASSET_DIR?}/device.txt"
-
-echo ">>> Compiling app resources <<<"
-
-# Generate the R.java for resources.
-mkdir -p "${IREE_RESOURCE_GEN_DIR?}"
-${AAPT_PACK?} --non-constant-id -m \
- -M "${IREE_APK_PARTS_DIR?}/AndroidManifest.xml" \
- -S "${IREE_NATIVE_APP_SOURCE_ROOT?}/res" \
- -J "${IREE_RESOURCE_GEN_DIR?}" \
- --generate-dependencies
-
-# Compile the R.java and create classes.dex out of it for Android.
-echo "Using javac: '${JAVAC_BIN?}'"
-${JAVAC?} "${IREE_RESOURCE_GEN_DIR?}"/com/iree-org/iree/run_module/*.java
-${DX?} --output="${IREE_APK_PARTS_DIR?}/classes.dex" "${IREE_APK_PARTS_DIR?}"
-
-echo ">>> Packaging apk file <<<"
-
-# Package assets and shared libraries into an apk file.
-${AAPT_PACK?} -m \
- -M "${IREE_APK_PARTS_DIR?}/AndroidManifest.xml" \
- -S "${IREE_NATIVE_APP_SOURCE_ROOT?}/res" \
- -A "${IREE_APK_PARTS_DIR?}/assets" \
- -F "${IREE_APK_PARTS_DIR?}/${IREE_APK_NAME?}.unaligned.apk" \
- --shared-lib "${IREE_APK_PARTS_DIR?}/libs"
-
-pushd "${IREE_APK_PARTS_DIR?}"
-# Also package the resources into the apk file.
-${AAPT_ADD?} "${IREE_APK_NAME?}.unaligned.apk" classes.dex
-echo ">>> Aligning apk file <<<"
-${ZIPALIGN?} "${IREE_APK_NAME?}.unaligned.apk" "${IREE_APK_NAME?}.apk"
-echo ">>> Signing apk file <<<"
-echo "NOTE: if you are using the Android Studio's debug keystore, the password is 'android'."
-${APKSIGN?} --ks "${ANDROID_KEYSTORE?}" --min-sdk-version 28 "${IREE_APK_NAME?}.apk"
-mv "${IREE_APK_NAME?}.apk" "${IREE_ARTIFACT_ROOT?}"
-popd
-
-echo ">>> Done: '${IREE_ARTIFACT_ROOT?}/${IREE_APK_NAME?}.apk' <<<"
diff --git a/tools/android/run_module_app/res/values/strings.xml b/tools/android/run_module_app/res/values/strings.xml
deleted file mode 100644
index f300778..0000000
--- a/tools/android/run_module_app/res/values/strings.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2020 The IREE Authors
-
- Licensed under the Apache License v2.0 with LLVM Exceptions.
- See https://llvm.org/LICENSE.txt for license information.
- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--->
-<resources>
- <string name="app_name">IREE Run Module</string>
-</resources>
diff --git a/tools/android/run_module_app/src/main.cc b/tools/android/run_module_app/src/main.cc
deleted file mode 100644
index e60919b..0000000
--- a/tools/android/run_module_app/src/main.cc
+++ /dev/null
@@ -1,233 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <android/log.h>
-#include <android_native_app_glue.h>
-
-#include <array>
-#include <chrono>
-#include <sstream>
-#include <string>
-#include <thread>
-#include <vector>
-
-#include "iree/base/api.h"
-#include "iree/modules/hal/module.h"
-#include "iree/tooling/device_util.h"
-#include "iree/tooling/vm_util.h"
-#include "iree/vm/api.h"
-#include "iree/vm/bytecode/module.h"
-
-namespace iree {
-namespace {
-
-const char* kAppTag = "iree-run-module";
-#define LOGI(...) \
- ((void)__android_log_print(ANDROID_LOG_INFO, kAppTag, __VA_ARGS__))
-#define LOGE(...) \
- ((void)__android_log_print(ANDROID_LOG_ERROR, kAppTag, __VA_ARGS__))
-
-const char kModuleFileName[] = "module.vmfb";
-const char kEntryFunctionFileName[] = "entry_function.txt";
-const char kInputsFileName[] = "inputs.txt";
-const char kDeviceFileName[] = "device.txt";
-
-// A struct containing information regarding one IREE VM module invocation.
-struct IreeModuleInvocation {
- std::string module;
- std::string entry_function;
- std::string inputs;
- std::string device;
-};
-
-// A class for loading IREE module invocation information from Android apk asset
-// files.
-class ModuleLoader {
- public:
- explicit ModuleLoader(android_app* app) : app_context_(app) {}
- ~ModuleLoader() = default;
-
- Status LoadModuleInvocation(IreeModuleInvocation* out_invocation) {
- IreeModuleInvocation invocation = {};
- IREE_RETURN_IF_ERROR(ReadFileAsset(kModuleFileName, &invocation.module));
- IREE_RETURN_IF_ERROR(
- ReadFileAsset(kEntryFunctionFileName, &invocation.entry_function));
- IREE_RETURN_IF_ERROR(ReadFileAsset(kInputsFileName, &invocation.inputs));
- IREE_RETURN_IF_ERROR(ReadFileAsset(kDeviceFileName, &invocation.device));
- *out_invocation = std::move(invocation);
- return OkStatus();
- }
-
- private:
- // Reads the given asset file and returns its contents.
- Status ReadFileAsset(const char* file_name, std::string* out_contents) {
- out_contents->clear();
-
- AAssetManager* asset_manager = app_context_->activity->assetManager;
- AAsset* asset =
- AAssetManager_open(asset_manager, file_name, AASSET_MODE_BUFFER);
- if (!asset) {
- return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
- "failed to open file '%s' in assets",
- kModuleFileName);
- }
-
- size_t size_in_bytes = AAsset_getLength(asset);
- std::string contents;
- contents.resize(size_in_bytes);
-
- AAsset_read(asset, const_cast<char*>(contents.data()), size_in_bytes);
- AAsset_close(asset);
-
- *out_contents = std::move(contents);
- return OkStatus();
- }
-
- android_app* app_context_;
-};
-
-Status RunModule(const IreeModuleInvocation& invocation) {
- iree_vm_instance_t* instance = nullptr;
- IREE_RETURN_IF_ERROR(
- iree_vm_instance_create(IREE_VM_TYPE_CAPACITY_DEFAULT,
- iree_allocator_system(), &instance),
- "creating instance");
- IREE_RETURN_IF_ERROR(iree_hal_module_register_all_types(instance),
- "registering HAL types");
-
- iree_vm_module_t* input_module = nullptr;
- IREE_RETURN_IF_ERROR(iree_vm_bytecode_module_create(
- instance,
- iree_make_const_byte_span((void*)invocation.module.data(),
- invocation.module.size()),
- iree_allocator_null(), iree_allocator_system(), &input_module));
-
- iree_hal_device_t* device = nullptr;
- IREE_RETURN_IF_ERROR(iree_hal_create_device(
- iree_hal_available_driver_registry(),
- iree_make_string_view(invocation.device.data(), invocation.device.size()),
- iree_allocator_system(), &device));
- iree_vm_module_t* hal_module = nullptr;
- IREE_RETURN_IF_ERROR(
- iree_hal_module_create(instance, device, IREE_HAL_MODULE_FLAG_NONE,
- iree_allocator_system(), &hal_module));
-
- iree_vm_context_t* context = nullptr;
- // Order matters. The input module will likely be dependent on the hal module.
- std::array<iree_vm_module_t*, 2> modules = {hal_module, input_module};
- IREE_RETURN_IF_ERROR(iree_vm_context_create_with_modules(
- instance, IREE_VM_CONTEXT_FLAG_NONE, modules.size(),
- modules.data(), iree_allocator_system(), &context),
- "creating context");
-
- const std::string& function_name = invocation.entry_function;
- iree_vm_function_t function;
- IREE_RETURN_IF_ERROR(
- iree_vm_module_lookup_function_by_name(
- input_module, IREE_VM_FUNCTION_LINKAGE_EXPORT,
- iree_string_view_t{function_name.data(), function_name.size()},
- &function),
- "looking up function '%s'", function_name.c_str());
-
- std::vector<iree_string_view_t> input_views;
- iree_string_view_t inputs_view =
- iree_make_string_view(invocation.inputs.data(), invocation.inputs.size());
- while (!iree_string_view_is_empty(inputs_view)) {
- iree_string_view_t input_view = iree_string_view_empty();
- iree_string_view_split(inputs_view, '\n', &input_view, &inputs_view);
- input_views.push_back(input_view);
- }
- vm::ref<iree_vm_list_t> inputs;
- IREE_RETURN_IF_ERROR(iree_tooling_parse_to_variant_list(
- device, iree_hal_device_allocator(device), input_views.data(),
- input_views.size(), iree_allocator_system(), &inputs));
-
- vm::ref<iree_vm_list_t> outputs;
- IREE_RETURN_IF_ERROR(iree_vm_list_create(iree_vm_make_undefined_type_def(),
- 16, iree_allocator_system(),
- &outputs));
-
- LOGI("Execute @%s", function_name.c_str());
- IREE_RETURN_IF_ERROR(
- iree_vm_invoke(context, function, IREE_VM_INVOCATION_FLAG_NONE,
- /*policy=*/nullptr, inputs.get(), outputs.get(),
- iree_allocator_system()),
- "invoking function '%s'", function_name.c_str());
-
- iree_string_builder_t result_str;
- iree_string_builder_initialize(iree_allocator_system(), &result_str);
- IREE_RETURN_IF_ERROR(iree_tooling_append_variant_list_lines(
- IREE_SV("result"), outputs.get(),
- /*max_element_count=*/1024, &result_str),
- "printing results");
- LOGI("Execution Result:");
- LOGI("%.*s", (int)iree_string_builder_size(&result_str),
- iree_string_builder_buffer(&result_str));
- iree_string_builder_deinitialize(&result_str);
-
- inputs.reset();
- outputs.reset();
- iree_vm_module_release(hal_module);
- iree_vm_module_release(input_module);
- iree_hal_device_release(device);
- iree_vm_context_release(context);
- iree_vm_instance_release(instance);
- return OkStatus();
-}
-
-void RunModuleAppMain(android_app* app) {
- // Sleep for 2 seconds to allow tools like AGI to perform the necessary
- // initialization.
- // TODO(antiagainst): This can be improved by rendering some UI button to
- // trigger the workload.
- std::this_thread::sleep_for(std::chrono::seconds(2));
-
- ModuleLoader loader(app);
- IreeModuleInvocation invocation;
- auto status = loader.LoadModuleInvocation(&invocation);
- if (status.ok()) {
- LOGI("entry function: '%s'", invocation.entry_function.c_str());
- LOGI("inputs:\n%s", invocation.inputs.c_str());
- LOGI("device: '%s'", invocation.device.c_str());
- status = RunModule(invocation);
- if (!status.ok()) LOGE("%s", status.ToString().c_str());
- } else {
- LOGE("failed to load module invocation: %s", status.ToString().c_str());
- }
-}
-
-void HandleAndroidAppCommand(android_app* app, int32_t cmd) {
- switch (cmd) {
- case APP_CMD_INIT_WINDOW:
- RunModuleAppMain(app);
- break;
- default:
- break;
- }
-}
-
-} // namespace
-} // namespace iree
-
-#define NATIVE_EXPORT extern "C" __attribute__((visibility("default")))
-
-// The main entry point of a native application using android_native_app_glue.
-// It runs in its own thread with its own event loop.
-NATIVE_EXPORT void android_main(struct android_app* app) {
- // Set the callback to process system events.
- app->onAppCmd = iree::HandleAndroidAppCommand;
-
- int events;
- android_poll_source* source;
-
- // Main loop for processing events.
- while (app->destroyRequested == 0) {
- if (ALooper_pollAll(/*timeoutMillis=*/1, /*outFd=*/nullptr, &events,
- (void**)&source) >= 0) {
- if (source != nullptr) source->process(app, source);
- }
- }
-}