chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
|
||||
/app/src/main/jni/jni_helper_func.h
|
||||
/app/src/main/jni/org_apache_tvm_native_c_api.cc
|
||||
/app/src/main/jni/org_apache_tvm_native_c_api.h
|
||||
/app/src/main/obj/
|
||||
dev_tools/tvmrpc.keystore
|
||||
@@ -0,0 +1,170 @@
|
||||
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
|
||||
<!--- or more contributor license agreements. See the NOTICE file -->
|
||||
<!--- distributed with this work for additional information -->
|
||||
<!--- regarding copyright ownership. The ASF licenses this file -->
|
||||
<!--- to you 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. -->
|
||||
|
||||
|
||||
# Android TVM RPC
|
||||
|
||||
This folder contains Android RPC app that allows us to launch an RPC server on a Android device and connect to it through python script and do testing on the python side as normal TVM RPC.
|
||||
|
||||
You will need JDK, [Android NDK](https://developer.android.com/ndk) and an Android device to use this.
|
||||
|
||||
## Build and Installation
|
||||
|
||||
### <a name="buildapk">Build APK</a>
|
||||
|
||||
We use [Gradle](https://gradle.org) to build. Please follow [the installation instruction](https://gradle.org/install) for your operating system.
|
||||
|
||||
Before you build the Android application, please refer to [TVM4J Installation Guide](https://github.com/apache/tvm/blob/main/jvm/README.md) and install tvm4j-core to your local maven repository. You can find tvm4j dependency declare in `app/build.gradle`. Modify it if it is necessary.
|
||||
|
||||
```
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation files('../../../jvm/core/target/tvm4j-core-0.0.1-SNAPSHOT.jar')
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
```
|
||||
|
||||
Now use Gradle to compile JNI, resolve Java dependencies and build the Android application together with tvm4j. Run following script to generate the apk file.
|
||||
|
||||
```bash
|
||||
export ANDROID_HOME=[Path to your Android SDK, e.g., ~/Android/sdk]
|
||||
cd apps/android_rpc
|
||||
gradle clean build
|
||||
```
|
||||
|
||||
In `app/build/outputs/apk` you'll find `app-release-unsigned.apk`, use `dev_tools/gen_keystore.sh` to generate a signature and use `dev_tools/sign_apk.sh` to get the signed apk file `app/build/outputs/apk/release/tvmrpc-release.apk`.
|
||||
|
||||
Upload `tvmrpc-release.apk` to your Android device and install it:
|
||||
|
||||
```bash
|
||||
$ANDROID_HOME/platform-tools/adb install app/build/outputs/apk/release/tvmrpc-release.apk
|
||||
```
|
||||
|
||||
If you see error:
|
||||
|
||||
adb: failed to install app/build/outputs/apk/release/tvmrpc-release.apk:
|
||||
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE:
|
||||
Package org.apache.tvm.tvmrpc signatures do not match the previously installed version; ignoring!]
|
||||
|
||||
Run uninstall first:
|
||||
|
||||
```bash
|
||||
$ANDROID_HOME/platform-tools/adb uninstall org.apache.tvm.tvmrpc
|
||||
```
|
||||
|
||||
### Build with OpenCL
|
||||
|
||||
Application is building with OpenCL support by default.
|
||||
[OpenCL-wrapper](../../src/runtime/opencl/opencl_wrapper) is used and will dynamically load OpenCL library on the device.
|
||||
If the device doesn't have OpenCL library on it, then you'll see in the runtime that OpenCL library cannot be opened.
|
||||
If you want to build this application without OpenCL then set `USE_OPENCL = 0`
|
||||
in [config.mk](./app/src/main/jni/make/config.mk)
|
||||
|
||||
## Cross Compile and Run on Android Devices
|
||||
|
||||
### Architecture and Android Standalone Toolchain
|
||||
|
||||
In order to cross compile a shared library (.so) for your android device, you have to know the target triple for the device. (Refer to [Cross-compilation using Clang](https://clang.llvm.org/docs/CrossCompilation.html) for more information). Run `adb shell cat /proc/cpuinfo` to list the device's CPU information.
|
||||
|
||||
Now use NDK to generate standalone toolchain for your device. For my test device, I use following command.
|
||||
|
||||
```bash
|
||||
cd /opt/android-ndk/build/tools/
|
||||
./make-standalone-toolchain.sh --platform=android-24 --use-llvm --arch=arm64 --install-dir=/opt/android-toolchain-arm64
|
||||
```
|
||||
|
||||
If everything goes well, you will find compile tools in `/opt/android-toolchain-arm64/bin`. For example, `bin/aarch64-linux-android-g++` can be used to compile C++ source codes and create shared libraries for arm64 Android devices.
|
||||
|
||||
### Cross Compile and Upload to the Android Device
|
||||
|
||||
First start an RPC tracker using
|
||||
|
||||
```python -m tvm.exec.rpc_tracker --port [PORT]```
|
||||
|
||||
and connect your Android device to this RPC tracker via the TVM RPC application. Open the app,
|
||||
set the `Address` and `Port` fields to the address and port of the RPC tracker respectively.
|
||||
The key should be set to "android" if you wish to avoid modifying the default test script.
|
||||
|
||||
After pushing "START RPC" button on the app, you can check the connect by run
|
||||
|
||||
```python -m tvm.exec.query_rpc_tracker --port [PORT]```
|
||||
|
||||
on your host machine.
|
||||
You are supposed to find a free "android" in the queue status.
|
||||
|
||||
```
|
||||
...
|
||||
|
||||
Queue Status
|
||||
-------------------------------
|
||||
key total free pending
|
||||
-------------------------------
|
||||
android 1 1 0
|
||||
-------------------------------
|
||||
```
|
||||
|
||||
|
||||
Then checkout [android\_rpc/tests/android\_rpc\_test.py](https://github.com/apache/tvm/blob/main/apps/android_rpc/tests/android_rpc_test.py) and run,
|
||||
|
||||
```bash
|
||||
# Specify the RPC tracker
|
||||
export TVM_TRACKER_HOST=0.0.0.0
|
||||
export TVM_TRACKER_PORT=[PORT]
|
||||
# Specify the standalone Android C++ compiler
|
||||
export TVM_NDK_CC=/opt/android-toolchain-arm64/bin/aarch64-linux-android-g++
|
||||
python android_rpc_test.py
|
||||
```
|
||||
|
||||
This will compile TVM IR to shared libraries (CPU, OpenCL and Vulkan) and run vector addition on your Android device. To verify compiled TVM IR shared libraries on OpenCL target set `'test_opencl = True'` and on Vulkan target set `'test_vulkan = True'` in [tests/android_rpc_test.py](https://github.com/apache/tvm/blob/main/apps/android_rpc/tests/android_rpc_test.py), by default on CPU target will execute.
|
||||
On my test device, it gives following results.
|
||||
|
||||
```bash
|
||||
Run CPU test ...
|
||||
0.000962932 secs/op
|
||||
|
||||
Run GPU(OpenCL Flavor) test ...
|
||||
0.000155807 secs/op
|
||||
|
||||
[23:29:34] /home/tvm/src/runtime/vulkan/vulkan_device_api.cc:674: Cannot initialize vulkan: [23:29:34] /home/tvm/src/runtime/vulkan/vulkan_device_api.cc:512: Check failed: __e == VK_SUCCESS Vulan Error, code=-9: VK_ERROR_INCOMPATIBLE_DRIVER
|
||||
|
||||
Stack trace returned 10 entries:
|
||||
[bt] (0) /home/user/.local/lib/python3.6/site-packages/tvm-0.4.0-py3.6-linux-x86_64.egg/tvm/libtvm.so(dmlc::StackTrace[abi:cxx11]()+0x53) [0x7f477f5399f3]
|
||||
.........
|
||||
|
||||
You can still compile vulkan module but cannot run locally
|
||||
Run GPU(Vulkan Flavor) test ...
|
||||
0.000225198 secs/op
|
||||
```
|
||||
|
||||
You can define your own TVM operators and test via this RPC app on your Android device to find the most optimized TVM schedule.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
If you build the application in Android Studio and see error similar to this one:
|
||||
```
|
||||
A problem occurred evaluating project ':app'.
|
||||
> Failed to apply plugin 'com.android.internal.version-check'.
|
||||
> Minimum supported Gradle version is 7.5. Current version is 7.4. If using the gradle wrapper, try editing the distributionUrl in /Users/echuraev/Workspace/OctoML/tvm_android_test/apps/android_deploy/gradle/wrapper/gradle-wrapper.properties to gradle-7.5-all.zip
|
||||
```
|
||||
Run project syncing `File -> Sync Project with Gradle Files`. It should sync the
|
||||
project and create gradle-wrapper files.
|
||||
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,103 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you 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.
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
task generateJniHeaders(type: Exec, description: 'Generate JNI Headers') {
|
||||
def headerPath = "${project.projectDir}/src/main/jni"
|
||||
def classPath = "${project.projectDir}/../../../jvm/core/target/*"
|
||||
def filePath = "${project.projectDir}/../../../jvm/core/src/main/java/org/apache/tvm/LibInfo.java"
|
||||
commandLine "javac", "-h", headerPath, "-classpath", classPath, filePath
|
||||
doLast {
|
||||
file("${headerPath}/org_apache_tvm_LibInfo.h").renameTo(file("${headerPath}/org_apache_tvm_native_c_api.h"))
|
||||
}
|
||||
}
|
||||
|
||||
task copyFiles(type: Copy, description: 'Copy Sources for ndk-build') {
|
||||
dependsOn "generateJniHeaders"
|
||||
def ndkFilesPath = "${project.projectDir}/../../../jvm/native/src/main/native"
|
||||
def srcPath = "${project.projectDir}/src/main/jni/"
|
||||
|
||||
from "${ndkFilesPath}/org_apache_tvm_native_c_api.cc", "${ndkFilesPath}/jni_helper_func.h"
|
||||
into srcPath
|
||||
}
|
||||
|
||||
task deleteLibs(type: Delete, description: "Delete Compiled Libraries") {
|
||||
dependsOn "copyFiles"
|
||||
def libsPath = "${project.projectDir}/src/main/libs"
|
||||
delete libsPath
|
||||
}
|
||||
|
||||
task buildJni(type: Exec, description: 'Build JNI libs') {
|
||||
dependsOn "deleteLibs"
|
||||
def buildPath = "${project.projectDir}/src/main/jni"
|
||||
commandLine "ndk-build", "--directory", buildPath
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
compileTask -> compileTask.dependsOn buildJni
|
||||
}
|
||||
|
||||
// gradle.projectsEvaluated {
|
||||
// tasks.withType(JavaCompile) {
|
||||
// options.compilerArgs << "-Xlint:deprecation"
|
||||
// }
|
||||
// }
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
defaultConfig {
|
||||
applicationId "org.apache.tvm.tvmrpc"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
jni.srcDirs = []
|
||||
jniLibs.srcDirs = ['src/main/libs']
|
||||
}
|
||||
}
|
||||
|
||||
lint {
|
||||
disable 'Instantiatable' // MainActivity and RPCActivity must extend android.app.Activity
|
||||
disable 'MissingClass' // .RPCWatchdogService was not found in the project or the libraries
|
||||
disable 'IconDipSize' // The image ic_launcher.png varies significantly in its density-independent size
|
||||
}
|
||||
namespace 'org.apache.tvm.tvmrpc'
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation files('../../../jvm/core/target/tvm4j-core-0.0.1-SNAPSHOT.jar')
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<uses-native-library
|
||||
android:name="libOpenCL.so"
|
||||
android:required="false"/>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:screenOrientation="unspecified"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".RPCWatchdogService"
|
||||
android:process=":RPCWatchdogServiceProcess"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
<activity
|
||||
android:name=".RPCActivity"
|
||||
android:process=":RPCProcess"
|
||||
android:label="@string/rpc_name"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:exported="false"
|
||||
android:screenOrientation="unspecified">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
package org.apache.tvm.tvmrpc;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
// wait time before automatic restart of RPC Activity
|
||||
public static final int HANDLER_RESTART_DELAY = 5000;
|
||||
|
||||
private void showDialog(String title, String msg) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(msg);
|
||||
builder.setCancelable(true);
|
||||
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
public Intent updateRPCPrefs() {
|
||||
System.err.println("updating preferences...");
|
||||
EditText edProxyAddress = findViewById(R.id.input_address);
|
||||
EditText edProxyPort = findViewById(R.id.input_port);
|
||||
EditText edAppKey = findViewById(R.id.input_key);
|
||||
SwitchCompat inputSwitch = findViewById(R.id.switch_persistent);
|
||||
|
||||
final String proxyHost = edProxyAddress.getText().toString();
|
||||
final int proxyPort = Integer.parseInt(edProxyPort.getText().toString());
|
||||
final String key = edAppKey.getText().toString();
|
||||
final boolean isChecked = inputSwitch.isChecked();
|
||||
|
||||
SharedPreferences pref =
|
||||
getApplicationContext().getSharedPreferences("RPCProxyPreference", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = pref.edit();
|
||||
editor.putString("input_address", proxyHost);
|
||||
editor.putString("input_port", edProxyPort.getText().toString());
|
||||
editor.putString("input_key", key);
|
||||
editor.putBoolean("input_switch", isChecked);
|
||||
editor.commit();
|
||||
|
||||
Intent intent = new Intent(this, RPCActivity.class);
|
||||
intent.putExtra("host", proxyHost);
|
||||
intent.putExtra("port", proxyPort);
|
||||
intent.putExtra("key", key);
|
||||
return intent;
|
||||
}
|
||||
|
||||
private void setupRelaunch() {
|
||||
final Context context = this;
|
||||
final SwitchCompat switchPersistent = findViewById(R.id.switch_persistent);
|
||||
final Runnable rPCStarter = new Runnable() {
|
||||
public void run() {
|
||||
if (switchPersistent.isChecked()) {
|
||||
System.err.println("relaunching RPC activity...");
|
||||
Intent intent = ((MainActivity) context).updateRPCPrefs();
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.postDelayed(rPCStarter, HANDLER_RESTART_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
final Context context = this;
|
||||
|
||||
SwitchCompat switchPersistent = findViewById(R.id.switch_persistent);
|
||||
switchPersistent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
System.err.println("automatic RPC restart enabled...");
|
||||
updateRPCPrefs();
|
||||
setupRelaunch();
|
||||
} else {
|
||||
System.err.println("automatic RPC restart disabled...");
|
||||
updateRPCPrefs();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
enableInputView(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
System.err.println("MainActivity onResume...");
|
||||
enableInputView(true);
|
||||
setupRelaunch();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void enableInputView(boolean enable) {
|
||||
EditText edProxyAddress = findViewById(R.id.input_address);
|
||||
EditText edProxyPort = findViewById(R.id.input_port);
|
||||
EditText edAppKey = findViewById(R.id.input_key);
|
||||
SwitchCompat input_switch = findViewById(R.id.switch_persistent);
|
||||
edProxyAddress.setEnabled(enable);
|
||||
edProxyPort.setEnabled(enable);
|
||||
edAppKey.setEnabled(enable);
|
||||
|
||||
if (enable) {
|
||||
SharedPreferences pref =
|
||||
getApplicationContext().getSharedPreferences("RPCProxyPreference", Context.MODE_PRIVATE);
|
||||
String inputAddress = pref.getString("input_address", null);
|
||||
if (null != inputAddress)
|
||||
edProxyAddress.setText(inputAddress);
|
||||
String inputPort = pref.getString("input_port", null);
|
||||
if (null != inputPort)
|
||||
edProxyPort.setText(inputPort);
|
||||
String inputKey = pref.getString("input_key", null);
|
||||
if (null != inputKey)
|
||||
edAppKey.setText(inputKey);
|
||||
boolean isChecked = pref.getBoolean("input_switch", false);
|
||||
input_switch.setChecked(isChecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
package org.apache.tvm.tvmrpc;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class RPCActivity extends AppCompatActivity {
|
||||
private RPCProcessor tvmServerWorker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_rpc);
|
||||
|
||||
Button stopRPC = findViewById(R.id.button_stop_rpc);
|
||||
stopRPC.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
System.err.println(tvmServerWorker == null);
|
||||
if (tvmServerWorker != null) {
|
||||
// currently will raise a socket closed exception
|
||||
tvmServerWorker.disconnect();
|
||||
}
|
||||
finish();
|
||||
// prevent Android from recycling the process
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
System.err.println("rpc activity onCreate...");
|
||||
Intent intent = getIntent();
|
||||
String host = intent.getStringExtra("host");
|
||||
int port = intent.getIntExtra("port", 9090);
|
||||
String key = intent.getStringExtra("key");
|
||||
|
||||
tvmServerWorker = new RPCProcessor(this);
|
||||
tvmServerWorker.setDaemon(true);
|
||||
tvmServerWorker.start();
|
||||
tvmServerWorker.connect(host, port, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
System.err.println("rpc activity onDestroy");
|
||||
tvmServerWorker.disconnect();
|
||||
super.onDestroy();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
package org.apache.tvm.tvmrpc;
|
||||
|
||||
import android.app.Activity;
|
||||
import org.apache.tvm.rpc.RPCWatchdog;
|
||||
|
||||
/**
|
||||
* Watchdog for Android RPC.
|
||||
*/
|
||||
public class RPCAndroidWatchdog extends RPCWatchdog {
|
||||
public Activity rpc_activity = null;
|
||||
public RPCAndroidWatchdog(Activity activity) {
|
||||
super();
|
||||
rpc_activity = activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to non-destructively terminate the running thread on Android
|
||||
*/
|
||||
@Override
|
||||
protected void terminate() {
|
||||
rpc_activity.finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
package org.apache.tvm.tvmrpc;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import java.net.Socket;
|
||||
import org.apache.tvm.rpc.ConnectTrackerServerProcessor;
|
||||
|
||||
/**
|
||||
* Connect to RPC proxy and deal with requests.
|
||||
*/
|
||||
class RPCProcessor extends Thread {
|
||||
private String host;
|
||||
private int port;
|
||||
private String key;
|
||||
private boolean running = false;
|
||||
private long startTime;
|
||||
private ConnectTrackerServerProcessor currProcessor;
|
||||
private boolean first = true;
|
||||
private Activity rpc_activity = null;
|
||||
|
||||
public RPCProcessor(Activity activity) {
|
||||
super();
|
||||
rpc_activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
RPCAndroidWatchdog watchdog = new RPCAndroidWatchdog(rpc_activity);
|
||||
watchdog.start();
|
||||
while (true) {
|
||||
synchronized (this) {
|
||||
currProcessor = null;
|
||||
while (!running) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
currProcessor = new ConnectTrackerServerProcessor(host, port, key, watchdog);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
// kill if creating a new processor failed
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
if (currProcessor != null)
|
||||
currProcessor.run();
|
||||
watchdog.finishTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the proxy server.
|
||||
*/
|
||||
synchronized void disconnect() {
|
||||
if (running) {
|
||||
running = false;
|
||||
if (currProcessor != null) {
|
||||
currProcessor.terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start rpc processor and connect to the proxy server.
|
||||
* @param host proxy server host.
|
||||
* @param port proxy server port.
|
||||
* @param key proxy server key.
|
||||
*/
|
||||
synchronized void connect(String host, int port, String key) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.key = key;
|
||||
running = true;
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
MY_PATH := $(LOCAL_PATH)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_PATH := $(MY_PATH)
|
||||
ROOT_PATH := $(MY_PATH)/../../../../../..
|
||||
|
||||
ifndef config
|
||||
ifneq ("$(wildcard ./config.mk)","")
|
||||
config ?= config.mk
|
||||
else
|
||||
config ?= make/config.mk
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(config)
|
||||
|
||||
LOCAL_SRC_FILES := org_apache_tvm_native_c_api.cc
|
||||
LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib/ -llog
|
||||
|
||||
LOCAL_C_INCLUDES := $(ROOT_PATH)/include \
|
||||
$(ROOT_PATH)/3rdparty/tvm-ffi/include \
|
||||
$(ROOT_PATH)/3rdparty/tvm-ffi/3rdparty/dlpack/include \
|
||||
$(ROOT_PATH)/3rdparty/OpenCL-Headers
|
||||
|
||||
LOCAL_MODULE = tvm4j_runtime_packed
|
||||
|
||||
LOCAL_CPP_FEATURES += exceptions
|
||||
LOCAL_LDLIBS += -latomic
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
||||
ifdef ADD_C_INCLUDES
|
||||
LOCAL_C_INCLUDES += $(ADD_C_INCLUDES)
|
||||
endif
|
||||
|
||||
ifdef ADD_LDLIBS
|
||||
LOCAL_LDLIBS += $(ADD_LDLIBS)
|
||||
endif
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
@@ -0,0 +1,50 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
ifndef config
|
||||
ifneq ("$(wildcard ./config.mk)","")
|
||||
config ?= config.mk
|
||||
else
|
||||
config ?= make/config.mk
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(config)
|
||||
|
||||
# We target every architecture except armeabi here, for two reasons:
|
||||
# 1) armeabi is deprecated in NDK r16 and removed in r17
|
||||
# 2) vulkan is not supported in armeabi
|
||||
APP_ABI ?= armeabi-v7a arm64-v8a x86 x86_64 mips
|
||||
APP_STL := c++_shared
|
||||
|
||||
APP_CPPFLAGS += -DTVM4J_ANDROID=1 -std=c++17 -Oz -frtti
|
||||
ifeq ($(USE_OPENCL), 1)
|
||||
APP_CPPFLAGS += -DTVM_OPENCL_RUNTIME=1
|
||||
endif
|
||||
|
||||
ifeq ($(USE_VULKAN), 1)
|
||||
APP_CPPFLAGS += -DTVM_VULKAN_RUNTIME=1
|
||||
APP_LDFLAGS += -lvulkan
|
||||
endif
|
||||
|
||||
ifeq ($(USE_SORT), 1)
|
||||
APP_CPPFLAGS += -DUSE_SORT=1
|
||||
endif
|
||||
|
||||
ifeq ($(USE_RANDOM), 1)
|
||||
APP_CPPFLAGS += -DUSE_RANDOM=1
|
||||
endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file tvm_runtime.h
|
||||
* \brief Pack all tvm runtime source files
|
||||
*/
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
/* Enable custom logging - this will cause TVM to use a custom implementation
|
||||
* of tvm::runtime::detail::LogMessage. We use this to pass TVM log messages to
|
||||
* Android logcat.
|
||||
*/
|
||||
#define TVM_LOG_CUSTOMIZE 1
|
||||
#define TVM_FFI_USE_LIBBACKTRACE 0
|
||||
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/backtrace.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/container.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/dtype.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/error.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/extra/library_module.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/extra/library_module_dynamic_lib.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/extra/library_module_system_lib.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/extra/module.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/function.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/object.cc"
|
||||
#include "../3rdparty/tvm-ffi/src/ffi/tensor.cc"
|
||||
#include "../src/runtime/cpu_device_api.cc"
|
||||
#include "../src/runtime/device_api.cc"
|
||||
#include "../src/runtime/file_utils.cc"
|
||||
#include "../src/runtime/logging.cc"
|
||||
#include "../src/runtime/memory/memory_manager.cc"
|
||||
#include "../src/runtime/registry.cc"
|
||||
#include "../src/runtime/rpc/rpc_channel.cc"
|
||||
#include "../src/runtime/rpc/rpc_endpoint.cc"
|
||||
#include "../src/runtime/rpc/rpc_event_impl.cc"
|
||||
#include "../src/runtime/rpc/rpc_local_session.cc"
|
||||
#include "../src/runtime/rpc/rpc_module.cc"
|
||||
#include "../src/runtime/rpc/rpc_server_env.cc"
|
||||
#include "../src/runtime/rpc/rpc_session.cc"
|
||||
#include "../src/runtime/rpc/rpc_socket_impl.cc"
|
||||
#include "../src/runtime/tensor.cc"
|
||||
#include "../src/runtime/thread_pool.cc"
|
||||
#include "../src/runtime/threading_backend.cc"
|
||||
#include "../src/runtime/timer.cc"
|
||||
#include "../src/runtime/workspace_pool.cc"
|
||||
|
||||
#ifdef TVM_OPENCL_RUNTIME
|
||||
#include "../src/runtime/opencl/opencl_device_api.cc"
|
||||
#include "../src/runtime/opencl/opencl_module.cc"
|
||||
#include "../src/runtime/opencl/opencl_wrapper/opencl_wrapper.cc"
|
||||
#include "../src/runtime/source_utils.cc"
|
||||
#endif
|
||||
|
||||
#ifdef TVM_VULKAN_RUNTIME
|
||||
#include "../src/runtime/vulkan/vulkan_amdrgp.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_buffer.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_common.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_device.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_device_api.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_instance.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_module.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_stream.cc"
|
||||
#include "../src/runtime/vulkan/vulkan_wrapped_func.cc"
|
||||
#endif
|
||||
|
||||
#ifdef USE_SORT
|
||||
#include "../src/runtime/extra/contrib/sort/sort.cc"
|
||||
#endif
|
||||
|
||||
#ifdef USE_RANDOM
|
||||
#include "../src/runtime/extra/contrib/random/random.cc"
|
||||
#endif
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
namespace tvm {
|
||||
namespace runtime {
|
||||
namespace detail {
|
||||
// Override logging mechanism
|
||||
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
|
||||
std::string m = file + ":" + std::to_string(lineno) + ": " + message;
|
||||
__android_log_write(ANDROID_LOG_FATAL, "TVM_RUNTIME", m.c_str());
|
||||
throw tvm::ffi::Error("InternalError", message, TVMFFIBacktrace(file.c_str(), lineno, "", 0));
|
||||
}
|
||||
void LogMessageImpl(const std::string& file, int lineno, int level, const std::string& message) {
|
||||
std::string m = file + ":" + std::to_string(lineno) + ": " + message;
|
||||
__android_log_write(ANDROID_LOG_DEBUG + level, "TVM_RUNTIME", m.c_str());
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace runtime
|
||||
} // namespace tvm
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.apache.tvm.tvmrpc.MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.apache.tvm.tvmrpc.RPCActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_rpc"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/activity_main">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_address"/>
|
||||
<EditText
|
||||
android:id="@+id/input_address"
|
||||
android:hint="@string/input_address"
|
||||
android:autofillHints="@string/label_address_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="phone"
|
||||
android:background="@android:drawable/editbox_background"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_port"/>
|
||||
<EditText
|
||||
android:id="@+id/input_port"
|
||||
android:hint="@string/input_port"
|
||||
android:autofillHints="@string/label_port_hint"
|
||||
android:minWidth="100dip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="phone"
|
||||
android:background="@android:drawable/editbox_background"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_key"/>
|
||||
<EditText
|
||||
android:id="@+id/input_key"
|
||||
android:hint="@string/input_key"
|
||||
android:autofillHints="@string/label_key_hint"
|
||||
android:inputType="text"
|
||||
android:minWidth="100dip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_persistent"/>
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switch_persistent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:switchMinWidth="55dp"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingRight="10dip"
|
||||
android:checked="false"
|
||||
android:textOff="@string/switch_off"
|
||||
android:textOn="@string/switch_on" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version='1.0'?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/activity_rpc">
|
||||
<Button
|
||||
android:id="@+id/button_stop_rpc"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/stop_rpc" />
|
||||
</LinearLayout>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#06d467</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version='1.0'?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<string name="app_name">TVM RPC</string>
|
||||
<string name="rpc_name">RPC</string>
|
||||
|
||||
<string name="input_address">Enter the tracker server address</string>
|
||||
<string name="input_port">Enter the tracker server port</string>
|
||||
<string name="input_key">Enter the app connection key</string>
|
||||
|
||||
<string name="label_address">Address</string>
|
||||
<string name="label_port">Port</string>
|
||||
<string name="label_key">Key</string>
|
||||
<string name="label_persistent">Enable RPC</string>
|
||||
|
||||
<string name="label_address_hint">192.168.1.1</string>
|
||||
<string name="label_port_hint">9190</string>
|
||||
<string name="label_key_hint">android</string>
|
||||
|
||||
|
||||
<string name="switch_on">Enabled</string>
|
||||
<string name="switch_off">Disabled</string>
|
||||
|
||||
<string name="stop_rpc">Stop RPC</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version='1.0'?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,50 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you 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.
|
||||
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url 'https://maven.google.com'
|
||||
}
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.4.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url 'https://maven.google.com'
|
||||
}
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
CURR_DIR=$(cd `dirname $0`; pwd)
|
||||
keytool -genkey -keystore $CURR_DIR/tvmrpc.keystore -alias tvmrpc -keyalg RSA -validity 10000
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
CURR_DIR=$(cd `dirname $0`; pwd)
|
||||
APK_DIR=$CURR_DIR/../app/build/outputs/apk/release
|
||||
UNSIGNED_APK=$APK_DIR/app-release-unsigned.apk
|
||||
SIGNED_APK=$APK_DIR/tvmrpc-release.apk
|
||||
jarsigner -verbose -keystore $CURR_DIR/tvmrpc.keystore -signedjar $SIGNED_APK $UNSIGNED_APK 'tvmrpc'
|
||||
echo $SIGNED_APK
|
||||
@@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
@@ -0,0 +1,18 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you 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.
|
||||
|
||||
include ':app'
|
||||
@@ -0,0 +1,86 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
# ruff: noqa: F821
|
||||
"""Testcode for Android RPC.
|
||||
|
||||
To use it, start an RPC tracker with "python -m tvm.exec.rpc_tracker".
|
||||
Use the tracker's address and port when configuring the RPC app.
|
||||
Use "android" as the key if you wish to avoid modifying this script.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
import tvm
|
||||
from tvm import rpc, te
|
||||
from tvm.support import ndk, utils
|
||||
|
||||
# Set to be address of tvm proxy.
|
||||
tracker_host = os.environ["TVM_TRACKER_HOST"]
|
||||
tracker_port = int(os.environ["TVM_TRACKER_PORT"])
|
||||
key = "android"
|
||||
|
||||
# Change target configuration.
|
||||
# Run `adb shell cat /proc/cpuinfo` to find the arch.
|
||||
arch = "arm64"
|
||||
target = {"kind": "llvm", "mtriple": f"{arch}-linux-android"}
|
||||
|
||||
# whether enable to execute test on OpenCL target
|
||||
test_opencl = False
|
||||
# whether enable to execute test on Vulkan target
|
||||
test_vulkan = False
|
||||
|
||||
|
||||
def test_rpc_module():
|
||||
# graph
|
||||
n = tvm.runtime.convert(1024)
|
||||
A = te.placeholder((n,), name="A")
|
||||
B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
|
||||
a_np = np.random.uniform(size=1024).astype(A.dtype)
|
||||
temp = utils.tempdir()
|
||||
|
||||
# Establish remote connection with target hardware
|
||||
tracker = rpc.connect_tracker(tracker_host, tracker_port)
|
||||
remote = tracker.request(key, priority=0, session_timeout=60)
|
||||
|
||||
mod = tvm.IRModule.from_expr(te.create_prim_func([A, B]).with_attr("global_symbol", "myadd"))
|
||||
sch = tvm.s_tir.Schedule(mod)
|
||||
(x,) = sch.get_loops(block=sch.get_sblock("B"))
|
||||
xo, xi = sch.split(i, [None, 32])
|
||||
sch.bind(xo, "blockIdx.x")
|
||||
sch.bind(xi, "threadIdx.x")
|
||||
|
||||
if test_opencl:
|
||||
f = tvm.compile(sch.mod, target=tvm.target.Target("opencl", host=target))
|
||||
path_dso_cl = temp.relpath("dev_lib_cl.so")
|
||||
f.export_library(path_dso_cl, fcompile=ndk.create_shared)
|
||||
|
||||
print("Run GPU(OpenCL Flavor) test ...")
|
||||
dev = remote.cl(0)
|
||||
remote.upload(path_dso_cl)
|
||||
f1 = remote.load_module("dev_lib_cl.so")
|
||||
a = tvm.runtime.tensor(a_np, dev)
|
||||
b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
|
||||
time_f = f1.time_evaluator(f1.entry_name, dev, number=10)
|
||||
cost = time_f(a, b).mean
|
||||
print(f"{cost:g} secs/op\n")
|
||||
np.testing.assert_equal(b.numpy(), a.numpy() + 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_rpc_module()
|
||||
Reference in New Issue
Block a user