From 99f45b1e80ef200566773276001eeb1a6d0dba42 Mon Sep 17 00:00:00 2001 From: Siyuan Feng Date: Sat, 25 Jan 2025 23:46:58 +0800 Subject: [PATCH] [Refactor] Phase out legacy example apps This commit removes legacy example apps from the repository, including: - android_camera - android_deploy - bundle_deploy - dso_plugin_module - extension - howto_deploy - lldb - pt_tvmdsoop - rocm_rpc - sgx - tf_tvmdsoop --- .github/workflows/main.yml | 11 - apps/android_camera/.gitignore | 15 - apps/android_camera/README.md | 120 --- apps/android_camera/app/build.gradle | 110 --- .../app/src/main/AndroidManifest.xml | 52 -- .../Camera2BasicFragment.java | 615 ------------- .../androidcamerademo/MainActivity.java | 89 -- .../app/src/main/jni/Android.mk | 61 -- .../app/src/main/jni/Application.mk | 46 - .../app/src/main/jni/make/config.mk | 54 -- .../app/src/main/jni/tvm_runtime.h | 97 -- .../src/main/res/drawable/item_selector.xml | 23 - .../app/src/main/res/layout/activity_main.xml | 23 - .../res/layout/fragment_camera2_basic.xml | 85 -- .../app/src/main/res/layout/listview_row.xml | 28 - .../app/src/main/res/values/colors.xml | 20 - .../app/src/main/res/values/strings.xml | 18 - .../app/src/main/res/values/styles.xml | 31 - .../app/src/main/res/xml/provider_paths.xml | 20 - .../app/src/main/rs/yuv420888.rs | 49 - apps/android_camera/build.gradle | 50 - apps/android_camera/dev_tools/gen_keystore.sh | 20 - apps/android_camera/dev_tools/sign_apk.sh | 24 - apps/android_camera/gradle.properties | 20 - apps/android_camera/models/prepare_model.py | 140 --- apps/android_camera/models/requirements.txt | 5 - apps/android_camera/settings.gradle | 18 - apps/android_deploy/.gitignore | 9 - apps/android_deploy/README.md | 133 --- apps/android_deploy/app/.gitignore | 1 - apps/android_deploy/app/build.gradle | 105 --- .../android_deploy/app/download-models.gradle | 98 -- .../app/src/main/AndroidManifest.xml | 58 -- .../apache/tvm/android/demo/MainActivity.java | 635 ------------- .../app/src/main/jni/Android.mk | 58 -- .../app/src/main/jni/Application.mk | 33 - .../app/src/main/jni/make/config.mk | 43 - .../app/src/main/jni/tvm_runtime.h | 54 -- .../app/src/main/res/layout/activity_main.xml | 46 - .../app/src/main/res/layout/content_main.xml | 67 -- .../app/src/main/res/values/colors.xml | 26 - .../app/src/main/res/values/strings.xml | 25 - .../app/src/main/res/values/styles.xml | 37 - .../app/src/main/res/xml/provider_paths.xml | 24 - apps/android_deploy/build.gradle | 51 -- apps/android_deploy/dev_tools/gen_keystore.sh | 19 - apps/android_deploy/dev_tools/sign_apk.sh | 23 - apps/android_deploy/gradle.properties | 20 - apps/android_deploy/settings.gradle | 18 - apps/bundle_deploy/Makefile | 177 ---- apps/bundle_deploy/README.md | 67 -- apps/bundle_deploy/backtrace.c | 57 -- apps/bundle_deploy/backtrace.h | 30 - apps/bundle_deploy/build_model.py | 167 ---- apps/bundle_deploy/bundle.c | 131 --- apps/bundle_deploy/bundle.cc | 64 -- apps/bundle_deploy/bundle.h | 36 - apps/bundle_deploy/bundle_static.c | 132 --- apps/bundle_deploy/demo.cc | 175 ---- apps/bundle_deploy/demo_static.c | 112 --- apps/bundle_deploy/runtime.cc | 40 - apps/bundle_deploy/test.cc | 170 ---- apps/bundle_deploy/test_static.c | 124 --- apps/dso_plugin_module/.gitignore | 1 - apps/dso_plugin_module/Makefile | 34 - apps/dso_plugin_module/README.md | 41 - apps/dso_plugin_module/plugin_module.cc | 68 -- apps/dso_plugin_module/test_plugin_module.py | 49 - apps/extension/.gitignore | 1 - apps/extension/Makefile | 36 - apps/extension/README.md | 25 - apps/extension/python/tvm_ext/__init__.py | 79 -- apps/extension/src/tvm_ext.cc | 180 ---- apps/extension/tests/test_ext.py | 121 --- apps/howto_deploy/Makefile | 54 -- apps/howto_deploy/README.md | 29 - apps/howto_deploy/cpp_deploy.cc | 124 --- apps/howto_deploy/prepare_test_libs.py | 64 -- apps/howto_deploy/python_deploy.py | 49 - apps/howto_deploy/run_example.sh | 32 - apps/howto_deploy/tvm_runtime_pack.cc | 89 -- apps/lldb/dot.lldbinit.in | 21 - apps/lldb/tvm.py | 189 ---- apps/pt_tvmdsoop/CMakeLists.txt | 34 - .../prepare_and_test_pt_tvm_class.sh | 45 - apps/pt_tvmdsoop/tests/test_as_torch.py | 260 ------ apps/pt_tvmdsoop/tests/test_boolean_tensor.py | 129 --- apps/pt_tvmdsoop/tests/test_optimize_torch.py | 161 ---- .../tests/test_torch_compile_cpu.py | 68 -- .../tests/test_torch_compile_gpu.py | 63 -- .../tests/test_torch_graph_module.py | 129 --- apps/pt_tvmdsoop/tests/test_torch_script.py | 116 --- .../pt_tvmdsoop/tests/test_torch_vm_module.py | 122 --- .../tests/test_trace_tvm_module.py | 58 -- apps/rocm_rpc/Makefile | 39 - apps/rocm_rpc/README.md | 58 -- apps/rocm_rpc/rocm_runtime_pack.cc | 34 - apps/rocm_rpc/start_rpc_server.sh | 22 - apps/sgx/.cargo/config | 5 - apps/sgx/.gitignore | 1 - apps/sgx/.rustfmt.toml | 1 - apps/sgx/Cargo.lock | 853 ------------------ apps/sgx/Cargo.toml | 28 - apps/sgx/README.md | 24 - apps/sgx/build.rs | 82 -- apps/sgx/read_results.py | 30 - apps/sgx/src/build_model.py | 61 -- apps/sgx/src/main.rs | 51 -- apps/tf_tvmdsoop/CMakeLists.txt | 34 - .../prepare_and_test_tfop_module.sh | 34 - apps/tf_tvmdsoop/tests/test_tfop_module.py | 114 --- apps/topi_recipe/README.md | 48 - .../broadcast/test_broadcast_map.py | 134 --- .../topi_recipe/conv/depthwise_conv2d_test.py | 267 ------ apps/topi_recipe/conv/test_conv2d_hwcn_map.py | 100 -- apps/topi_recipe/conv/test_conv_int8_arm.py | 223 ----- apps/topi_recipe/conv/test_conv_int8_intel.py | 208 ----- apps/topi_recipe/gemm/android_gemm_square.py | 138 --- apps/topi_recipe/gemm/cuda_gemm_square.py | 135 --- apps/topi_recipe/gemm/gemm_int8.py | 182 ---- apps/topi_recipe/reduce/test_reduce_map.py | 93 -- apps/topi_recipe/rnn/lstm.py | 205 ----- apps/topi_recipe/rnn/matexp.py | 179 ---- tests/scripts/setup-adreno-env.sh | 1 - tests/scripts/task_python_adreno.sh | 1 - tests/scripts/task_python_integration.sh | 22 - tests/scripts/unity/task_python_relax.sh | 1 - 127 files changed, 10788 deletions(-) delete mode 100644 apps/android_camera/.gitignore delete mode 100644 apps/android_camera/README.md delete mode 100644 apps/android_camera/app/build.gradle delete mode 100644 apps/android_camera/app/src/main/AndroidManifest.xml delete mode 100644 apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/Camera2BasicFragment.java delete mode 100644 apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/MainActivity.java delete mode 100644 apps/android_camera/app/src/main/jni/Android.mk delete mode 100644 apps/android_camera/app/src/main/jni/Application.mk delete mode 100644 apps/android_camera/app/src/main/jni/make/config.mk delete mode 100644 apps/android_camera/app/src/main/jni/tvm_runtime.h delete mode 100644 apps/android_camera/app/src/main/res/drawable/item_selector.xml delete mode 100644 apps/android_camera/app/src/main/res/layout/activity_main.xml delete mode 100644 apps/android_camera/app/src/main/res/layout/fragment_camera2_basic.xml delete mode 100644 apps/android_camera/app/src/main/res/layout/listview_row.xml delete mode 100644 apps/android_camera/app/src/main/res/values/colors.xml delete mode 100644 apps/android_camera/app/src/main/res/values/strings.xml delete mode 100644 apps/android_camera/app/src/main/res/values/styles.xml delete mode 100644 apps/android_camera/app/src/main/res/xml/provider_paths.xml delete mode 100644 apps/android_camera/app/src/main/rs/yuv420888.rs delete mode 100644 apps/android_camera/build.gradle delete mode 100755 apps/android_camera/dev_tools/gen_keystore.sh delete mode 100755 apps/android_camera/dev_tools/sign_apk.sh delete mode 100644 apps/android_camera/gradle.properties delete mode 100644 apps/android_camera/models/prepare_model.py delete mode 100644 apps/android_camera/models/requirements.txt delete mode 100644 apps/android_camera/settings.gradle delete mode 100644 apps/android_deploy/.gitignore delete mode 100644 apps/android_deploy/README.md delete mode 100644 apps/android_deploy/app/.gitignore delete mode 100644 apps/android_deploy/app/build.gradle delete mode 100644 apps/android_deploy/app/download-models.gradle delete mode 100644 apps/android_deploy/app/src/main/AndroidManifest.xml delete mode 100644 apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java delete mode 100644 apps/android_deploy/app/src/main/jni/Android.mk delete mode 100644 apps/android_deploy/app/src/main/jni/Application.mk delete mode 100644 apps/android_deploy/app/src/main/jni/make/config.mk delete mode 100644 apps/android_deploy/app/src/main/jni/tvm_runtime.h delete mode 100644 apps/android_deploy/app/src/main/res/layout/activity_main.xml delete mode 100644 apps/android_deploy/app/src/main/res/layout/content_main.xml delete mode 100644 apps/android_deploy/app/src/main/res/values/colors.xml delete mode 100644 apps/android_deploy/app/src/main/res/values/strings.xml delete mode 100644 apps/android_deploy/app/src/main/res/values/styles.xml delete mode 100644 apps/android_deploy/app/src/main/res/xml/provider_paths.xml delete mode 100644 apps/android_deploy/build.gradle delete mode 100644 apps/android_deploy/dev_tools/gen_keystore.sh delete mode 100644 apps/android_deploy/dev_tools/sign_apk.sh delete mode 100644 apps/android_deploy/gradle.properties delete mode 100644 apps/android_deploy/settings.gradle delete mode 100644 apps/bundle_deploy/Makefile delete mode 100644 apps/bundle_deploy/README.md delete mode 100644 apps/bundle_deploy/backtrace.c delete mode 100644 apps/bundle_deploy/backtrace.h delete mode 100644 apps/bundle_deploy/build_model.py delete mode 100644 apps/bundle_deploy/bundle.c delete mode 100644 apps/bundle_deploy/bundle.cc delete mode 100644 apps/bundle_deploy/bundle.h delete mode 100644 apps/bundle_deploy/bundle_static.c delete mode 100644 apps/bundle_deploy/demo.cc delete mode 100644 apps/bundle_deploy/demo_static.c delete mode 100644 apps/bundle_deploy/runtime.cc delete mode 100644 apps/bundle_deploy/test.cc delete mode 100644 apps/bundle_deploy/test_static.c delete mode 100644 apps/dso_plugin_module/.gitignore delete mode 100644 apps/dso_plugin_module/Makefile delete mode 100644 apps/dso_plugin_module/README.md delete mode 100644 apps/dso_plugin_module/plugin_module.cc delete mode 100644 apps/dso_plugin_module/test_plugin_module.py delete mode 100644 apps/extension/.gitignore delete mode 100644 apps/extension/Makefile delete mode 100644 apps/extension/README.md delete mode 100644 apps/extension/python/tvm_ext/__init__.py delete mode 100644 apps/extension/src/tvm_ext.cc delete mode 100644 apps/extension/tests/test_ext.py delete mode 100644 apps/howto_deploy/Makefile delete mode 100644 apps/howto_deploy/README.md delete mode 100644 apps/howto_deploy/cpp_deploy.cc delete mode 100644 apps/howto_deploy/prepare_test_libs.py delete mode 100644 apps/howto_deploy/python_deploy.py delete mode 100755 apps/howto_deploy/run_example.sh delete mode 100644 apps/howto_deploy/tvm_runtime_pack.cc delete mode 100644 apps/lldb/dot.lldbinit.in delete mode 100644 apps/lldb/tvm.py delete mode 100644 apps/pt_tvmdsoop/CMakeLists.txt delete mode 100755 apps/pt_tvmdsoop/prepare_and_test_pt_tvm_class.sh delete mode 100644 apps/pt_tvmdsoop/tests/test_as_torch.py delete mode 100644 apps/pt_tvmdsoop/tests/test_boolean_tensor.py delete mode 100644 apps/pt_tvmdsoop/tests/test_optimize_torch.py delete mode 100644 apps/pt_tvmdsoop/tests/test_torch_compile_cpu.py delete mode 100644 apps/pt_tvmdsoop/tests/test_torch_compile_gpu.py delete mode 100644 apps/pt_tvmdsoop/tests/test_torch_graph_module.py delete mode 100644 apps/pt_tvmdsoop/tests/test_torch_script.py delete mode 100644 apps/pt_tvmdsoop/tests/test_torch_vm_module.py delete mode 100644 apps/pt_tvmdsoop/tests/test_trace_tvm_module.py delete mode 100644 apps/rocm_rpc/Makefile delete mode 100644 apps/rocm_rpc/README.md delete mode 100644 apps/rocm_rpc/rocm_runtime_pack.cc delete mode 100755 apps/rocm_rpc/start_rpc_server.sh delete mode 100644 apps/sgx/.cargo/config delete mode 100644 apps/sgx/.gitignore delete mode 120000 apps/sgx/.rustfmt.toml delete mode 100644 apps/sgx/Cargo.lock delete mode 100644 apps/sgx/Cargo.toml delete mode 100644 apps/sgx/README.md delete mode 100644 apps/sgx/build.rs delete mode 100644 apps/sgx/read_results.py delete mode 100755 apps/sgx/src/build_model.py delete mode 100644 apps/sgx/src/main.rs delete mode 100644 apps/tf_tvmdsoop/CMakeLists.txt delete mode 100644 apps/tf_tvmdsoop/prepare_and_test_tfop_module.sh delete mode 100644 apps/tf_tvmdsoop/tests/test_tfop_module.py delete mode 100644 apps/topi_recipe/README.md delete mode 100644 apps/topi_recipe/broadcast/test_broadcast_map.py delete mode 100644 apps/topi_recipe/conv/depthwise_conv2d_test.py delete mode 100644 apps/topi_recipe/conv/test_conv2d_hwcn_map.py delete mode 100644 apps/topi_recipe/conv/test_conv_int8_arm.py delete mode 100644 apps/topi_recipe/conv/test_conv_int8_intel.py delete mode 100644 apps/topi_recipe/gemm/android_gemm_square.py delete mode 100644 apps/topi_recipe/gemm/cuda_gemm_square.py delete mode 100644 apps/topi_recipe/gemm/gemm_int8.py delete mode 100644 apps/topi_recipe/reduce/test_reduce_map.py delete mode 100644 apps/topi_recipe/rnn/lstm.py delete mode 100644 apps/topi_recipe/rnn/matexp.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db2d870da9bd..9b85b4697d75 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -179,14 +179,3 @@ jobs: with: name: android_rpc-debug.apk path: ./apps/android_rpc/app/build/outputs/apk/debug/app-debug.apk - - name: Build android_deploy - working-directory: apps/android_deploy - run: | - set -eux - export PATH="${ANDROID_NDK_LATEST_HOME}:$PATH" - gradle clean build - - name: Upload android_deploy APK - uses: actions/upload-artifact@v4 - with: - name: android_deploy-debug.apk - path: ./apps/android_deploy/app/build/outputs/apk/debug/app-debug.apk diff --git a/apps/android_camera/.gitignore b/apps/android_camera/.gitignore deleted file mode 100644 index 6c2f76d2093c..000000000000 --- a/apps/android_camera/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -*.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/ -gradle/ -app/src/main/assets/models diff --git a/apps/android_camera/README.md b/apps/android_camera/README.md deleted file mode 100644 index cf84989d42ff..000000000000 --- a/apps/android_camera/README.md +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - -# Android Camera Demo Sample App - -The Android Camera Demo Sample App provides a basic implementation of an Android app that uses the tvm runtime to perform image classification in real time. - -You will need JDK, [Android NDK](https://developer.android.com/ndk) and an Android device to use this. - -## Build and Installation - -### Prepare Models - -The `models/prepare_models.py` script provides a example flow for dumping model -parameter files for use by the app. - -1. Set path to the NDK CC: `export TVM_NDK_CC=[Path to CC, e.g. /opt/android-toolchain-arm64/bin/aarch64-linux-android-g++]` -2. Switch to the script directory: `cd models` -3. Run script: `python3 prepare_model.py` - -#### Sample output -``` -mobilenet_v2 -getting model... -building... -dumping lib... -dumping graph... -dumping params... -dumping labels... -resnet18_v1 -getting model... -building... -dumping lib... -dumping graph... -dumping params... -dumping labels... -``` - -### Build APK - -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.2.0', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation 'androidx.appcompat:appcompat:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' - implementation 'com.google.android.material:material:1.5.0' - implementation files('../../../jvm/core/target/tvm4j-core-0.0.1-SNAPSHOT.jar') - testImplementation 'junit:junit:4.13.2' - - implementation "androidx.concurrent:concurrent-futures:1.0.0" - implementation "androidx.camera:camera-core:1.0.0-beta01" - implementation "androidx.camera:camera-camera2:1.0.0-beta01" - // If you want to use the CameraX View class - implementation "androidx.camera:camera-view:1.0.0-alpha08" - // If you want to use the CameraX Extensions library - implementation "androidx.camera:camera-extensions:1.0.0-alpha08" - // If you want to use the CameraX Lifecycle library - implementation "androidx.camera:camera-lifecycle:1.0.0-beta01" -} -``` - -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_camera -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/tv8mdemo-release.apk`. - -Upload `tv8mdemo-release.apk` to your Android device and install it: - -```bash -$ANDROID_HOME/platform-tools/adb install app/build/outputs/apk/release/tv8mdemo-release.apk -``` - -If you see error: - - adb: failed to install app/build/outputs/apk/release/tv8mdemo-release.apk: - Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: - Package ml.apache.tvm.android.androidcamerademo signatures do not match the previously installed version; ignoring!] - -Run uninstall first: - -```bash -$ANDROID_HOME/platform-tools/adb uninstall ml.apache.tvm.android.androidcamerademo -``` -### 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. diff --git a/apps/android_camera/app/build.gradle b/apps/android_camera/app/build.gradle deleted file mode 100644 index 8b42d3844840..000000000000 --- a/apps/android_camera/app/build.gradle +++ /dev/null @@ -1,110 +0,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. - -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 -} - -android { - compileSdkVersion 33 - defaultConfig { - applicationId "ml.apache.tvm.android.androidcamerademo" - minSdkVersion 24 - targetSdkVersion 33 - renderscriptTargetApi 18 - renderscriptSupportModeEnabled true - 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'] - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - lint { - disable 'Instantiatable' // MainActivity and RPCActivity must extend android.app.Activity - } - namespace 'org.apache.tvm.android.androidcamerademo' - -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('androidx.test.espresso:espresso-core:3.2.0', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation 'androidx.appcompat:appcompat:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' - implementation 'com.google.android.material:material:1.5.0' - implementation files('../../../jvm/core/target/tvm4j-core-0.0.1-SNAPSHOT.jar') - testImplementation 'junit:junit:4.13.2' - - implementation "androidx.concurrent:concurrent-futures:1.0.0" - implementation "androidx.camera:camera-core:1.0.0-beta01" - implementation "androidx.camera:camera-camera2:1.0.0-beta01" - // If you want to use the CameraX View class - implementation "androidx.camera:camera-view:1.0.0-alpha08" - // If you want to use the CameraX Extensions library - implementation "androidx.camera:camera-extensions:1.0.0-alpha08" - // If you want to use the CameraX Lifecycle library - implementation "androidx.camera:camera-lifecycle:1.0.0-beta01" -} diff --git a/apps/android_camera/app/src/main/AndroidManifest.xml b/apps/android_camera/app/src/main/AndroidManifest.xml deleted file mode 100644 index 9ed232f273e7..000000000000 --- a/apps/android_camera/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/Camera2BasicFragment.java b/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/Camera2BasicFragment.java deleted file mode 100644 index 3a55a62d739c..000000000000 --- a/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/Camera2BasicFragment.java +++ /dev/null @@ -1,615 +0,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. - */ - -package org.apache.tvm.android.androidcamerademo; - -import android.annotation.SuppressLint; -import android.content.res.AssetManager; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.media.Image; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.SystemClock; -import android.util.Log; -import android.util.Size; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatTextView; -import androidx.camera.core.Camera; -import androidx.camera.core.CameraSelector; -import androidx.camera.core.ImageAnalysis; -import androidx.camera.core.ImageProxy; -import androidx.camera.core.Preview; -import androidx.camera.lifecycle.ProcessCameraProvider; -import androidx.camera.view.PreviewView; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.renderscript.Allocation; -import androidx.renderscript.Element; -import androidx.renderscript.RenderScript; -import androidx.renderscript.Script; -import androidx.renderscript.Type; - -import com.google.common.util.concurrent.ListenableFuture; - -import org.apache.tvm.Function; -import org.apache.tvm.Module; -import org.apache.tvm.NDArray; -import org.apache.tvm.Device; -import org.apache.tvm.TVMType; -import org.apache.tvm.TVMValue; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.PriorityQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.Semaphore; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -public class Camera2BasicFragment extends Fragment { - private static final String TAG = Camera2BasicFragment.class.getSimpleName(); - - // TVM constants - private static final int OUTPUT_INDEX = 0; - private static final int IMG_CHANNEL = 3; - private static final boolean EXE_GPU = false; - private static final int MODEL_INPUT_SIZE = 224; - private static final String MODEL_CL_LIB_FILE = "deploy_lib_opencl.so"; - private static final String MODEL_CPU_LIB_FILE = "deploy_lib_cpu.so"; - private static final String MODEL_GRAPH_FILE = "deploy_graph.json"; - private static final String MODEL_PARAM_FILE = "deploy_param.params"; - private static final String MODEL_LABEL_FILE = "image_net_labels.json"; - private static final String MODELS = "models"; - private static String INPUT_NAME = "input_1"; - private static String[] models; - private static String mCurModel = ""; - private final float[] mCHW = new float[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE * IMG_CHANNEL]; - private final float[] mCHW2 = new float[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE * IMG_CHANNEL]; - private final Semaphore isProcessingDone = new Semaphore(1); - private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( - 3, - 3, - 1, - TimeUnit.SECONDS, - new LinkedBlockingQueue<>() - ); - // rs creation just for demo. Create rs just once in onCreate and use it again. - private RenderScript rs; - private ScriptC_yuv420888 mYuv420; - private boolean mRunClassifier = false; - - private AppCompatTextView mResultView; - private AppCompatTextView mInfoView; - private ListView mModelView; - private AssetManager assetManager; - private Module graphExecutorModule; - private JSONObject labels; - private ListenableFuture cameraProviderFuture; - private PreviewView previewView; - private ImageAnalysis imageAnalysis; - - static Camera2BasicFragment newInstance() { - return new Camera2BasicFragment(); - } - - private static Matrix getTransformationMatrix( - final int srcWidth, - final int srcHeight, - final int dstWidth, - final int dstHeight, - final int applyRotation, - final boolean maintainAspectRatio) { - final Matrix matrix = new Matrix(); - - if (applyRotation != 0) { - if (applyRotation % 90 != 0) { - Log.w(TAG, "Rotation of %d % 90 != 0 " + applyRotation); - } - - // Translate so center of image is at origin. - matrix.postTranslate(-srcWidth / 2.0f, -srcHeight / 2.0f); - - // Rotate around origin. - matrix.postRotate(applyRotation); - } - - // Account for the already applied rotation, if any, and then determine how - // much scaling is needed for each axis. - final boolean transpose = (Math.abs(applyRotation) + 90) % 180 == 0; - - final int inWidth = transpose ? srcHeight : srcWidth; - final int inHeight = transpose ? srcWidth : srcHeight; - - // Apply scaling if necessary. - if (inWidth != dstWidth || inHeight != dstHeight) { - final float scaleFactorX = dstWidth / (float) inWidth; - final float scaleFactorY = dstHeight / (float) inHeight; - - if (maintainAspectRatio) { - // Scale by minimum factor so that dst is filled completely while - // maintaining the aspect ratio. Some image may fall off the edge. - final float scaleFactor = Math.max(scaleFactorX, scaleFactorY); - matrix.postScale(scaleFactor, scaleFactor); - } else { - // Scale exactly to fill dst from src. - matrix.postScale(scaleFactorX, scaleFactorY); - } - } - - if (applyRotation != 0) { - // Translate back from origin centered reference to destination frame. - matrix.postTranslate(dstWidth / 2.0f, dstHeight / 2.0f); - } - - return matrix; - } - - private String[] getModels() { - String[] models; - try { - models = getActivity().getAssets().list(MODELS); - } catch (IOException e) { - return null; - } - return models; - } - - @SuppressLint("DefaultLocale") - private String[] inference(float[] chw) { - NDArray inputNdArray = NDArray.empty(new long[]{1, IMG_CHANNEL, MODEL_INPUT_SIZE, MODEL_INPUT_SIZE}, new TVMType("float32")); - inputNdArray.copyFrom(chw); - Function setInputFunc = graphExecutorModule.getFunction("set_input"); - setInputFunc.pushArg(INPUT_NAME).pushArg(inputNdArray).invoke(); - // release tvm local variables - inputNdArray.release(); - setInputFunc.release(); - - // get the function from the module(run it) - Function runFunc = graphExecutorModule.getFunction("run"); - runFunc.invoke(); - // release tvm local variables - runFunc.release(); - - // get the function from the module(get output data) - NDArray outputNdArray = NDArray.empty(new long[]{1, 1000}, new TVMType("float32")); - Function getOutputFunc = graphExecutorModule.getFunction("get_output"); - getOutputFunc.pushArg(OUTPUT_INDEX).pushArg(outputNdArray).invoke(); - float[] output = outputNdArray.asFloatArray(); - // release tvm local variables - outputNdArray.release(); - getOutputFunc.release(); - - if (null != output) { - String[] results = new String[5]; - // top-5 - PriorityQueue pq = new PriorityQueue<>(1000, (Integer idx1, Integer idx2) -> output[idx1] > output[idx2] ? -1 : 1); - - // display the result from extracted output data - for (int j = 0; j < output.length; ++j) { - pq.add(j); - } - for (int l = 0; l < 5; l++) { - //noinspection ConstantConditions - int idx = pq.poll(); - if (idx < labels.length()) { - try { - results[l] = String.format("%.2f", output[idx]) + " : " + labels.getString(Integer.toString(idx)); - } catch (JSONException e) { - Log.e(TAG, "index out of range", e); - } - } else { - results[l] = "???: unknown"; - } - } - return results; - } - return new String[5]; - } - - private void updateActiveModel() { - Log.i(TAG, "updating active model..."); - new LoadModelAsyncTask().execute(); - } - - @Override - public void onViewCreated(final View view, Bundle savedInstanceState) { - - mResultView = view.findViewById(R.id.resultTextView); - mInfoView = view.findViewById(R.id.infoTextView); - mModelView = view.findViewById(R.id.modelListView); - if (assetManager == null) { - assetManager = getActivity().getAssets(); - } - - mModelView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - models = getModels(); - - ArrayAdapter modelAdapter = - new ArrayAdapter<>( - getContext(), R.layout.listview_row, R.id.listview_row_text, models); - mModelView.setAdapter(modelAdapter); - mModelView.setItemChecked(0, true); - mModelView.setOnItemClickListener( - (parent, view1, position, id) -> updateActiveModel()); - - new LoadModelAsyncTask().execute(); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - } - - @Override - public void onDestroy() { - // release tvm local variables - if (null != graphExecutorModule) - graphExecutorModule.release(); - super.onDestroy(); - } - - /** - * Read file from assets and return byte array. - * - * @param assets The asset manager to be used to load assets. - * @param fileName The filepath of read file. - * @return byte[] file content - * @throws IOException - */ - private byte[] getBytesFromFile(AssetManager assets, String fileName) throws IOException { - InputStream is = assets.open(fileName); - int length = is.available(); - byte[] bytes = new byte[length]; - // Read in the bytes - int offset = 0; - int numRead; - try { - while (offset < bytes.length - && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { - offset += numRead; - } - } finally { - is.close(); - } - // Ensure all the bytes have been read in - if (offset < bytes.length) { - throw new IOException("Could not completely read file " + fileName); - } - return bytes; - } - - /** - * Get application cache path where to place compiled functions. - * - * @param fileName library file name. - * @return String application cache folder path - * @throws IOException - */ - private String getTempLibFilePath(String fileName) throws IOException { - File tempDir = File.createTempFile("tvm4j_demo_", ""); - if (!tempDir.delete() || !tempDir.mkdir()) { - throw new IOException("Couldn't create directory " + tempDir.getAbsolutePath()); - } - return (tempDir + File.separator + fileName); - } - - private Bitmap YUV_420_888_toRGB(Image image, int width, int height) { - // Get the three image planes - Image.Plane[] planes = image.getPlanes(); - ByteBuffer buffer = planes[0].getBuffer(); - byte[] y = new byte[buffer.remaining()]; - buffer.get(y); - - buffer = planes[1].getBuffer(); - byte[] u = new byte[buffer.remaining()]; - buffer.get(u); - - buffer = planes[2].getBuffer(); - byte[] v = new byte[buffer.remaining()]; - buffer.get(v); - - int yRowStride = planes[0].getRowStride(); - int uvRowStride = planes[1].getRowStride(); - int uvPixelStride = planes[1].getPixelStride(); - - - // Y,U,V are defined as global allocations, the out-Allocation is the Bitmap. - // Note also that uAlloc and vAlloc are 1-dimensional while yAlloc is 2-dimensional. - Type.Builder typeUcharY = new Type.Builder(rs, Element.U8(rs)); - typeUcharY.setX(yRowStride).setY(height); - Allocation yAlloc = Allocation.createTyped(rs, typeUcharY.create()); - yAlloc.copyFrom(y); - mYuv420.set_ypsIn(yAlloc); - - Type.Builder typeUcharUV = new Type.Builder(rs, Element.U8(rs)); - // note that the size of the u's and v's are as follows: - // ( (width/2)*PixelStride + padding ) * (height/2) - // = (RowStride ) * (height/2) - typeUcharUV.setX(u.length); - Allocation uAlloc = Allocation.createTyped(rs, typeUcharUV.create()); - uAlloc.copyFrom(u); - mYuv420.set_uIn(uAlloc); - - Allocation vAlloc = Allocation.createTyped(rs, typeUcharUV.create()); - vAlloc.copyFrom(v); - mYuv420.set_vIn(vAlloc); - - // handover parameters - mYuv420.set_picWidth(width); - mYuv420.set_uvRowStride(uvRowStride); - mYuv420.set_uvPixelStride(uvPixelStride); - - Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Allocation outAlloc = Allocation.createFromBitmap(rs, outBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); - - Script.LaunchOptions lo = new Script.LaunchOptions(); - lo.setX(0, width); // by this we ignore the y’s padding zone, i.e. the right side of x between width and yRowStride - lo.setY(0, height); - - mYuv420.forEach_doConvert(outAlloc, lo); - outAlloc.copyTo(outBitmap); - - return outBitmap; - } - - private float[] getFrame(ImageProxy imageProxy) { - @SuppressLint("UnsafeOptInUsageError") - Image image = imageProxy.getImage(); - // extract the jpeg content - if (image == null) { - return null; - } - Bitmap imageBitmap = YUV_420_888_toRGB(image, image.getWidth(), image.getHeight()); - - imageProxy.close(); - // crop input image at centre to model input size - Bitmap cropImageBitmap = Bitmap.createBitmap(MODEL_INPUT_SIZE, MODEL_INPUT_SIZE, Bitmap.Config.ARGB_8888); - Matrix frameToCropTransform = getTransformationMatrix(imageBitmap.getWidth(), imageBitmap.getHeight(), - MODEL_INPUT_SIZE, MODEL_INPUT_SIZE, 0, true); - Canvas canvas = new Canvas(cropImageBitmap); - canvas.drawBitmap(imageBitmap, frameToCropTransform, null); - - // image pixel int values - int[] pixelValues = new int[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE]; - // image RGB float values - - // pre-process the image data from 0-255 int to normalized float based on the - // provided parameters. - cropImageBitmap.getPixels(pixelValues, 0, MODEL_INPUT_SIZE, 0, 0, MODEL_INPUT_SIZE, MODEL_INPUT_SIZE); - for (int j = 0; j < pixelValues.length; ++j) { - mCHW2[j * 3 + 0] = ((pixelValues[j] >> 16) & 0xFF) / 255.0f; - mCHW2[j * 3 + 1] = ((pixelValues[j] >> 8) & 0xFF) / 255.0f; - mCHW2[j * 3 + 2] = (pixelValues[j] & 0xFF) / 255.0f; - } - - // pre-process the image rgb data transpose based on the provided parameters. - for (int k = 0; k < IMG_CHANNEL; ++k) { - for (int l = 0; l < MODEL_INPUT_SIZE; ++l) { - for (int m = 0; m < MODEL_INPUT_SIZE; ++m) { - int dst_index = m + MODEL_INPUT_SIZE * l + MODEL_INPUT_SIZE * MODEL_INPUT_SIZE * k; - int src_index = k + IMG_CHANNEL * m + IMG_CHANNEL * MODEL_INPUT_SIZE * l; - mCHW[dst_index] = mCHW2[src_index]; - } - } - } - - return mCHW; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - cameraProviderFuture = ProcessCameraProvider.getInstance(getActivity()); - } - - @SuppressLint({"RestrictedApi", "UnsafeExperimentalUsageError"}) - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_camera2_basic, container, false); - previewView = v.findViewById(R.id.textureView); - rs = RenderScript.create(getActivity()); - mYuv420 = new ScriptC_yuv420888(rs); - cameraProviderFuture.addListener(() -> { - try { - ProcessCameraProvider cameraProvider = cameraProviderFuture.get(); - bindPreview(cameraProvider); - } catch (ExecutionException | InterruptedException e) { - // No errors need to be handled for this Future. This should never be reached - } - }, ContextCompat.getMainExecutor(getActivity())); - - imageAnalysis = new ImageAnalysis.Builder() - .setTargetResolution(new Size(224, 224)) - .setMaxResolution(new Size(300, 300)) - .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) - .build(); - - imageAnalysis.setAnalyzer(threadPoolExecutor, image -> { - Log.e(TAG, "w: " + image.getWidth() + " h: " + image.getHeight()); - if (mRunClassifier && isProcessingDone.tryAcquire()) { - long t1 = SystemClock.uptimeMillis(); - //float[] chw = getFrame(image); - //float[] chw = YUV_420_888_toRGBPixels(image); - float[] chw = getFrame(image); - if (chw != null) { - long t2 = SystemClock.uptimeMillis(); - String[] results = inference(chw); - long t3 = SystemClock.uptimeMillis(); - StringBuilder msgBuilder = new StringBuilder(); - for (int l = 1; l < 5; l++) { - msgBuilder.append(results[l]).append("\n"); - } - String msg = msgBuilder.toString(); - msg += "getFrame(): " + (t2 - t1) + "ms" + "\n"; - msg += "inference(): " + (t3 - t2) + "ms" + "\n"; - String finalMsg = msg; - this.getActivity().runOnUiThread(() -> { - mResultView.setText(String.format("model: %s \n %s", mCurModel, results[0])); - mInfoView.setText(finalMsg); - }); - } - isProcessingDone.release(); - } - image.close(); - }); - return v; - } - - private void bindPreview(@NonNull ProcessCameraProvider cameraProvider) { - @SuppressLint("RestrictedApi") Preview preview = new Preview.Builder() - .setMaxResolution(new Size(800, 800)) - .setTargetName("Preview") - .build(); - - preview.setSurfaceProvider(previewView.getPreviewSurfaceProvider()); - CameraSelector cameraSelector = - new CameraSelector.Builder() - .requireLensFacing(CameraSelector.LENS_FACING_BACK) - .build(); - Camera camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalysis); - } - - @Override - public void onDestroyView() { - threadPoolExecutor.shutdownNow(); - super.onDestroyView(); - } - - private void setInputName(String modelName) { - if (modelName.equals("mobilenet_v2")) { - INPUT_NAME = "input_1"; - } else if (modelName.equals("resnet18_v1")) { - INPUT_NAME = "data"; - } else { - throw new RuntimeException("Model input may not be right. Please set INPUT_NAME here explicitly."); - } - } - - /* - Load precompiled model on TVM graph executor and init the system. - */ - private class LoadModelAsyncTask extends AsyncTask { - - @Override - protected Integer doInBackground(Void... args) { - mRunClassifier = false; - // load synset name - int modelIndex = mModelView.getCheckedItemPosition(); - setInputName(models[modelIndex]); - String model = MODELS + "/" + models[modelIndex]; - String labelFilename = MODEL_LABEL_FILE; - Log.i(TAG, "Reading labels from: " + model + "/" + labelFilename); - try { - labels = new JSONObject(new String(getBytesFromFile(assetManager, model + "/" + labelFilename))); - } catch (IOException | JSONException e) { - Log.e(TAG, "Problem reading labels name file!", e); - return -1;//failure - } - - // load json graph - String modelGraph; - String graphFilename = MODEL_GRAPH_FILE; - Log.i(TAG, "Reading json graph from: " + model + "/" + graphFilename); - try { - modelGraph = new String(getBytesFromFile(assetManager, model + "/" + graphFilename)); - } catch (IOException e) { - Log.e(TAG, "Problem reading json graph file!", e); - return -1;//failure - } - - // upload tvm compiled function on application cache folder - String libCacheFilePath; - String libFilename = EXE_GPU ? MODEL_CL_LIB_FILE : MODEL_CPU_LIB_FILE; - Log.i(TAG, "Uploading compiled function to cache folder"); - try { - libCacheFilePath = getTempLibFilePath(libFilename); - byte[] modelLibByte = getBytesFromFile(assetManager, model + "/" + libFilename); - FileOutputStream fos = new FileOutputStream(libCacheFilePath); - fos.write(modelLibByte); - fos.close(); - } catch (IOException e) { - Log.e(TAG, "Problem uploading compiled function!", e); - return -1;//failure - } - - // load parameters - byte[] modelParams; - try { - modelParams = getBytesFromFile(assetManager, model + "/" + MODEL_PARAM_FILE); - } catch (IOException e) { - Log.e(TAG, "Problem reading params file!", e); - return -1;//failure - } - - Log.i(TAG, "creating java tvm device..."); - // create java tvm device - Device tvmDev = EXE_GPU ? Device.opencl() : Device.cpu(); - - Log.i(TAG, "loading compiled functions..."); - Log.i(TAG, libCacheFilePath); - // tvm module for compiled functions - Module modelLib = Module.load(libCacheFilePath); - - - // get global function module for graph executor - Log.i(TAG, "getting graph executor create handle..."); - - Function runtimeCreFun = Function.getFunction("tvm.graph_executor.create"); - Log.i(TAG, "creating graph executor..."); - - Log.i(TAG, "device type: " + tvmDev.deviceType); - Log.i(TAG, "device id: " + tvmDev.deviceId); - - TVMValue runtimeCreFunRes = runtimeCreFun.pushArg(modelGraph) - .pushArg(modelLib) - .pushArg(tvmDev.deviceType) - .pushArg(tvmDev.deviceId) - .invoke(); - - Log.i(TAG, "as module..."); - graphExecutorModule = runtimeCreFunRes.asModule(); - Log.i(TAG, "getting graph executor load params handle..."); - // get the function from the module(load parameters) - Function loadParamFunc = graphExecutorModule.getFunction("load_params"); - Log.i(TAG, "loading params..."); - loadParamFunc.pushArg(modelParams).invoke(); - // release tvm local variables - modelLib.release(); - loadParamFunc.release(); - runtimeCreFun.release(); - mCurModel = model; - mRunClassifier = true; - return 0;//success - } - } -} diff --git a/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/MainActivity.java b/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/MainActivity.java deleted file mode 100644 index 06b1c9730d05..000000000000 --- a/apps/android_camera/app/src/main/java/org/apache/tvm/android/androidcamerademo/MainActivity.java +++ /dev/null @@ -1,89 +0,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. - */ - -package org.apache.tvm.android.androidcamerademo; - -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - -public class MainActivity extends AppCompatActivity implements - ActivityCompat.OnRequestPermissionsResultCallback { - - private static final int PERMISSIONS_REQUEST_CODE = 1; - - private String[] getRequiredPermissions() { - try { - PackageInfo info = getPackageManager() - .getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS); - String[] ps = info.requestedPermissions; - if (ps != null && ps.length > 0) { - return ps; - } else { - return new String[0]; - } - } catch (Exception e) { - return new String[0]; - } - } - - private boolean allPermissionsGranted() { - for (String permission : getRequiredPermissions()) { - if (ContextCompat.checkSelfPermission(this, permission) - != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - if (!allPermissionsGranted()) { - requestPermissions(getRequiredPermissions(), PERMISSIONS_REQUEST_CODE); - return; - } - startFragment(); - } - - private void startFragment() { - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.container, Camera2BasicFragment.newInstance()) - .commit(); - } - - @Override - public void onRequestPermissionsResult( - int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (allPermissionsGranted()) { - startFragment(); - } else { - Toast.makeText(this, "Required permissions are not granted. App may not run", Toast.LENGTH_SHORT).show(); - finish(); - } - } -} diff --git a/apps/android_camera/app/src/main/jni/Android.mk b/apps/android_camera/app/src/main/jni/Android.mk deleted file mode 100644 index 2201f669653c..000000000000 --- a/apps/android_camera/app/src/main/jni/Android.mk +++ /dev/null @@ -1,61 +0,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. - -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)/src/runtime/rpc \ - $(ROOT_PATH)/3rdparty/dlpack/include \ - $(ROOT_PATH)/3rdparty/dmlc-core/include \ - $(ROOT_PATH)/3rdparty/OpenCL-Headers \ - $(MY_PATH) - -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) diff --git a/apps/android_camera/app/src/main/jni/Application.mk b/apps/android_camera/app/src/main/jni/Application.mk deleted file mode 100644 index 83b7b4417b9e..000000000000 --- a/apps/android_camera/app/src/main/jni/Application.mk +++ /dev/null @@ -1,46 +0,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. - -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 ?= all -APP_STL := c++_shared - -APP_CPPFLAGS += -DTVM_LOG_STACK_TRACE=0 -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 diff --git a/apps/android_camera/app/src/main/jni/make/config.mk b/apps/android_camera/app/src/main/jni/make/config.mk deleted file mode 100644 index 1f601b9afb29..000000000000 --- a/apps/android_camera/app/src/main/jni/make/config.mk +++ /dev/null @@ -1,54 +0,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. - -#------------------------------------------------------------------------------- -# Template configuration for compiling -# -# If you want to change the configuration, please use the following -# steps. Assume you are on the root directory. First copy the this -# file so that any local changes will be ignored by git -# -# cp make/config.mk . -# -# Next modify the according entries, and then compile by -# -# ./build.sh -# -#------------------------------------------------------------------------------- -APP_ABI = all - -APP_PLATFORM = android-24 - -# whether enable OpenCL during compile -USE_OPENCL = 1 - -# whether to enable Vulkan during compile -USE_VULKAN = 0 - -# whether to enable contrib sort functions during compile -USE_SORT = 1 - -ifeq ($(USE_VULKAN), 1) - # Statically linking vulkan requires API Level 24 or higher - APP_PLATFORM = android-24 -endif - -# the additional include headers you want to add, e.g., SDK_PATH/adrenosdk/Development/Inc -ADD_C_INCLUDES = - -# the additional link libs you want to add, e.g., ANDROID_LIB_PATH/libOpenCL.so -ADD_LDLIBS = diff --git a/apps/android_camera/app/src/main/jni/tvm_runtime.h b/apps/android_camera/app/src/main/jni/tvm_runtime.h deleted file mode 100644 index e843b56360bb..000000000000 --- a/apps/android_camera/app/src/main/jni/tvm_runtime.h +++ /dev/null @@ -1,97 +0,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. - */ - -/*! - * \file tvm_runtime.h - * \brief Pack all tvm runtime source files - */ -#include - -#include - -#define DMLC_USE_LOGGING_LIBRARY -#define TVM_USE_LIBBACKTRACE 0 -/* 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 - -#include "../src/runtime/c_runtime_api.cc" -#include "../src/runtime/cpu_device_api.cc" -#include "../src/runtime/dso_library.cc" -#include "../src/runtime/file_utils.cc" -#include "../src/runtime/graph_executor/graph_executor.cc" -#include "../src/runtime/library_module.cc" -#include "../src/runtime/logging.cc" -#include "../src/runtime/memory/memory_manager.cc" -#include "../src/runtime/minrpc/minrpc_logger.cc" -#include "../src/runtime/module.cc" -#include "../src/runtime/ndarray.cc" -#include "../src/runtime/object.cc" -#include "../src/runtime/profiling.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/system_library.cc" -#include "../src/runtime/thread_pool.cc" -#include "../src/runtime/threading_backend.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/opencl/texture_pool.cc" -#include "../src/runtime/source_utils.cc" -#endif - -#ifdef TVM_VULKAN_RUNTIME -#include "../src/runtime/vulkan/vulkan.cc" -#endif - -#ifdef USE_SORT -#include "../src/runtime/contrib/sort/sort.cc" -#endif - -#include - -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 InternalError(file, lineno, message); -} -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 diff --git a/apps/android_camera/app/src/main/res/drawable/item_selector.xml b/apps/android_camera/app/src/main/res/drawable/item_selector.xml deleted file mode 100644 index bd87d8bc06b2..000000000000 --- a/apps/android_camera/app/src/main/res/drawable/item_selector.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - diff --git a/apps/android_camera/app/src/main/res/layout/activity_main.xml b/apps/android_camera/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 14dba9cc01b5..000000000000 --- a/apps/android_camera/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - diff --git a/apps/android_camera/app/src/main/res/layout/fragment_camera2_basic.xml b/apps/android_camera/app/src/main/res/layout/fragment_camera2_basic.xml deleted file mode 100644 index 12dc53b46db3..000000000000 --- a/apps/android_camera/app/src/main/res/layout/fragment_camera2_basic.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/apps/android_camera/app/src/main/res/layout/listview_row.xml b/apps/android_camera/app/src/main/res/layout/listview_row.xml deleted file mode 100644 index 5038a27557e9..000000000000 --- a/apps/android_camera/app/src/main/res/layout/listview_row.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/apps/android_camera/app/src/main/res/values/colors.xml b/apps/android_camera/app/src/main/res/values/colors.xml deleted file mode 100644 index 8cb461a91903..000000000000 --- a/apps/android_camera/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - #DA6A84 - #F6F6F6 - #72BF3A - diff --git a/apps/android_camera/app/src/main/res/values/strings.xml b/apps/android_camera/app/src/main/res/values/strings.xml deleted file mode 100644 index cc69189a2ab6..000000000000 --- a/apps/android_camera/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - TVM Android Demo - diff --git a/apps/android_camera/app/src/main/res/values/styles.xml b/apps/android_camera/app/src/main/res/values/styles.xml deleted file mode 100644 index 545a6eeed59e..000000000000 --- a/apps/android_camera/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/apps/android_camera/app/src/main/res/xml/provider_paths.xml b/apps/android_camera/app/src/main/res/xml/provider_paths.xml deleted file mode 100644 index cef8fc075a53..000000000000 --- a/apps/android_camera/app/src/main/res/xml/provider_paths.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/apps/android_camera/app/src/main/rs/yuv420888.rs b/apps/android_camera/app/src/main/rs/yuv420888.rs deleted file mode 100644 index 05229a261024..000000000000 --- a/apps/android_camera/app/src/main/rs/yuv420888.rs +++ /dev/null @@ -1,49 +0,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. - */ - -// Source: https://stackoverflow.com/questions/36212904/yuv-420-888-interpretation-on-samsung-galaxy-s7-camera2 -#pragma version(1) -#pragma rs java_package_name(org.apache.tvm.android.androidcamerademo); -#pragma rs_fp_relaxed - -int32_t width; -int32_t height; - -uint picWidth, uvPixelStride, uvRowStride ; -rs_allocation ypsIn,uIn,vIn; - -// The LaunchOptions ensure that the Kernel does not enter the padding zone of Y, so yRowStride can be ignored WITHIN the Kernel. -uchar4 __attribute__((kernel)) doConvert(uint32_t x, uint32_t y) { - - // index for accessing the uIn's and vIn's - uint uvIndex= uvPixelStride * (x/2) + uvRowStride*(y/2); - - // get the y,u,v values - uchar yps= rsGetElementAt_uchar(ypsIn, x, y); - uchar u= rsGetElementAt_uchar(uIn, uvIndex); - uchar v= rsGetElementAt_uchar(vIn, uvIndex); - - // calc argb - int4 argb; - argb.r = yps + v * 1436 / 1024 - 179; - argb.g = yps -u * 46549 / 131072 + 44 -v * 93604 / 131072 + 91; - argb.b = yps +u * 1814 / 1024 - 227; - argb.a = 255; - - uchar4 out = convert_uchar4(clamp(argb, 0, 255)); - return out; -} diff --git a/apps/android_camera/build.gradle b/apps/android_camera/build.gradle deleted file mode 100644 index 7f98372768fa..000000000000 --- a/apps/android_camera/build.gradle +++ /dev/null @@ -1,50 +0,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. - -// 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 -} diff --git a/apps/android_camera/dev_tools/gen_keystore.sh b/apps/android_camera/dev_tools/gen_keystore.sh deleted file mode 100755 index ff20597b7aab..000000000000 --- a/apps/android_camera/dev_tools/gen_keystore.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/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/tvmdemo.keystore -alias tvmdemo -keyalg RSA -validity 10000 diff --git a/apps/android_camera/dev_tools/sign_apk.sh b/apps/android_camera/dev_tools/sign_apk.sh deleted file mode 100755 index 29e7777562cf..000000000000 --- a/apps/android_camera/dev_tools/sign_apk.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/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/tv8mdemo-release.apk -jarsigner -verbose -keystore $CURR_DIR/tv8mdemo.keystore -signedjar $SIGNED_APK $UNSIGNED_APK 'tv8mdemo' -echo $SIGNED_APK diff --git a/apps/android_camera/gradle.properties b/apps/android_camera/gradle.properties deleted file mode 100644 index 1add1b540993..000000000000 --- a/apps/android_camera/gradle.properties +++ /dev/null @@ -1,20 +0,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. - -org.gradle.jvmargs=-Xmx4608M -android.useAndroidX=true -android.enableJetifier=true diff --git a/apps/android_camera/models/prepare_model.py b/apps/android_camera/models/prepare_model.py deleted file mode 100644 index 5fd99967aea3..000000000000 --- a/apps/android_camera/models/prepare_model.py +++ /dev/null @@ -1,140 +0,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. - -import json -import os -from os import environ -from pathlib import Path -from typing import Union - -import tvm -import tvm.relay as relay -from tvm.contrib import ndk -from tvm.contrib.download import download, download_testdata - -target = "llvm -mtriple=arm64-linux-android" -target_host = None - - -def del_dir(target: Union[Path, str], only_if_empty: bool = False): - target = Path(target).expanduser() - assert target.is_dir() - for p in sorted(target.glob("**/*"), reverse=True): - if not p.exists(): - continue - p.chmod(0o666) - if p.is_dir(): - p.rmdir() - else: - if only_if_empty: - raise RuntimeError(f"{p.parent} is not empty!") - p.unlink() - target.rmdir() - - -def get_model(model_name, batch_size=1): - if model_name == "resnet18_v1": - import torch - import torchvision - - weights = torchvision.models.ResNet18_Weights.IMAGENET1K_V1 - torch_model = torchvision.models.resnet18(weights=weights).eval() - input_shape = [1, 3, 224, 224] - input_data = torch.randn(input_shape) - scripted_model = torch.jit.trace(torch_model, input_data) - - input_infos = [("data", input_data.shape)] - mod, params = relay.frontend.from_pytorch(scripted_model, input_infos) - return (mod, params) - elif model_name == "mobilenet_v2": - import keras - from keras.applications.mobilenet_v2 import MobileNetV2 - - keras.backend.clear_session() # Destroys the current TF graph and creates a new one. - weights_url = "".join( - [ - "https://github.com/JonathanCMitchell/", - "mobilenet_v2_keras/releases/download/v1.1/", - "mobilenet_v2_weights_tf_dim_ordering_tf_kernels_0.5_224.h5", - ] - ) - weights_file = "mobilenet_v2_weights.h5" - weights_path = download_testdata(weights_url, weights_file, module="keras") - keras_mobilenet_v2 = MobileNetV2( - alpha=0.5, include_top=True, weights=None, input_shape=(224, 224, 3), classes=1000 - ) - keras_mobilenet_v2.load_weights(weights_path) - - img_size = 224 - data_shape = (batch_size, 3, img_size, img_size) - mod, params = relay.frontend.from_keras(keras_mobilenet_v2, {"input_1": data_shape}) - return (mod, params) - - -def main(model_str, output_path): - if output_path.exists(): - del_dir(output_path) - output_path.mkdir() - output_path_str = os.fspath(output_path) - print(model_str) - print("getting model...") - net, params = get_model(model_str) - try: - os.mkdir(model_str) - except FileExistsError: - pass - print("building...") - with tvm.transform.PassContext(opt_level=3): - graph, lib, params = relay.build(net, tvm.target.Target(target, target_host), params=params) - print("dumping lib...") - lib.export_library(output_path_str + "/" + "deploy_lib_cpu.so", fcompile=ndk.create_shared) - print("dumping graph...") - with open(output_path_str + "/" + "deploy_graph.json", "w") as f: - f.write(graph) - print("dumping params...") - with open(output_path_str + "/" + "deploy_param.params", "wb") as f: - f.write(tvm.runtime.save_param_dict(params)) - print("dumping labels...") - synset_url = "".join( - [ - "https://gist.githubusercontent.com/zhreshold/", - "4d0b62f3d01426887599d4f7ede23ee5/raw/", - "596b27d23537e5a1b5751d2b0481ef172f58b539/", - "imagenet1000_clsid_to_human.txt", - ] - ) - synset_path = output_path_str + "/image_net_labels" - download(synset_url, output_path_str + "/image_net_labels") - with open(synset_path) as fi: - synset = eval(fi.read()) - with open(output_path_str + "/image_net_labels.json", "w") as fo: - json.dump(synset, fo, indent=4) - os.remove(synset_path) - - -if __name__ == "__main__": - if environ.get("TVM_NDK_CC") is None: - raise RuntimeError("Require environment variable TVM_NDK_CC") - models_path = Path().absolute().parent.joinpath("app/src/main/assets/models/") - if not models_path.exists(): - models_path.mkdir(parents=True) - models = { - "mobilenet_v2": models_path.joinpath("mobilenet_v2"), - "resnet18_v1": models_path.joinpath("resnet18_v1"), - } - for model, output_path in models.items(): - main(model, output_path) diff --git a/apps/android_camera/models/requirements.txt b/apps/android_camera/models/requirements.txt deleted file mode 100644 index 3e35efdeb66e..000000000000 --- a/apps/android_camera/models/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -keras==2.9 -scipy -tensorflow==2.9.3 -torch -torchvision diff --git a/apps/android_camera/settings.gradle b/apps/android_camera/settings.gradle deleted file mode 100644 index ee503c22bf30..000000000000 --- a/apps/android_camera/settings.gradle +++ /dev/null @@ -1,18 +0,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. - -include ':app' diff --git a/apps/android_deploy/.gitignore b/apps/android_deploy/.gitignore deleted file mode 100644 index 39fb081a42a8..000000000000 --- a/apps/android_deploy/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures -.externalNativeBuild diff --git a/apps/android_deploy/README.md b/apps/android_deploy/README.md deleted file mode 100644 index 25001cf69ea8..000000000000 --- a/apps/android_deploy/README.md +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - -# Android TVM Demo - -This folder contains Android Demo app that allows us to show how to deploy model using TVM runtime api on a Android phone. - -You will need [JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html), [Android SDK](https://developer.android.com/studio/index.html), [Android NDK](https://developer.android.com/ndk) and an Android device to use this. Make sure the `ANDROID_HOME` variable already points to your Android SDK folder or set it using `export ANDROID_HOME=[Path to your Android SDK, e.g., ~/Android/sdk]`. We use [Gradle](https://gradle.org) to build. Please follow [the installation instruction](https://gradle.org/install) for your operating system. - -Alternatively, you may execute Docker image we provide which contains the required packages. Use the command below to build the image and enter interactive session. - -```bash -./docker/build.sh demo_android -it bash -(docker) $ echo $ANDROID_HOME -(docker) /opt/android-sdk-linux -``` - - -## Build and Installation - -### Build APK - -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' -} -``` - -Application default has CPU and GPU (OpenCL) versions TVM runtime flavor and follow below instruction to setup. -In `app/src/main/jni/make` you will find JNI Makefile config `config.mk` and copy it to `app/src/main/jni` and modify it. - -```bash -cd apps/android_deploy/app/src/main/jni -cp make/config.mk . -``` - -Here's a piece of example for `config.mk`. - -```makefile -APP_ABI = arm64-v8a - -APP_PLATFORM = android-17 -``` - -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 -cd apps/android_deploy -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/tvmdemo-release.apk`. - -Upload `tvmdemo-release.apk` to your Android device and install it. - -### 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. - -### Place compiled model on Android application assets folder - -Follow instruction to get compiled version model for android target [here.](https://tvm.apache.org/docs/deploy/android.html) - -Copied these compiled model deploy_lib.so, deploy_graph.json and deploy_param.params to apps/android_deploy/app/src/main/assets/ and modify TVM flavor changes on [java](https://github.com/apache/tvm/blob/main/apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java#L81) - -`CPU Verison flavor` -``` - private static final boolean EXE_GPU = false; -``` - -`OpenCL Verison flavor` -``` - private static final boolean EXE_GPU = true; -``` - - -Install compiled android application on phone and enjoy the image classifier demo using extraction model - -You can define your own TVM operators and deploy via this demo application 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. diff --git a/apps/android_deploy/app/.gitignore b/apps/android_deploy/app/.gitignore deleted file mode 100644 index 796b96d1c402..000000000000 --- a/apps/android_deploy/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/apps/android_deploy/app/build.gradle b/apps/android_deploy/app/build.gradle deleted file mode 100644 index 4b4ec235f653..000000000000 --- a/apps/android_deploy/app/build.gradle +++ /dev/null @@ -1,105 +0,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. - -// import DownloadModels task -project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets' -project.ext.TMP_DIR = project.buildDir.toString() + '/downloads' - -// Download default models(darknet framework extraction model compiled version); -// if you wish to use your own models then place them in the "assets" directory -// and comment out this line. -apply from: "download-models.gradle" - -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 -} - -android { - compileSdkVersion 33 - defaultConfig { - applicationId "org.apache.tvm.android.demo" - 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 'MissingApplicationIcon' // Should explicitly set android:icon, there is no default - disable 'UnsafeNativeCodeLocation' // Shared libraries should not be placed in the res or assets directories. - } - namespace 'org.apache.tvm.android.demo' - -} - -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' -} diff --git a/apps/android_deploy/app/download-models.gradle b/apps/android_deploy/app/download-models.gradle deleted file mode 100644 index a4e865505c31..000000000000 --- a/apps/android_deploy/app/download-models.gradle +++ /dev/null @@ -1,98 +0,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. - -/* - * download-models.gradle - * Downloads model files from ${MODEL_URL} into application's asset folder - * Input: - * project.ext.TMP_DIR: absolute path to hold downloaded zip files - * project.ext.ASSET_DIR: absolute path to save unzipped model files - * Output: - * 3 model files will be downloaded into given folder of ext.ASSET_DIR - */ -// hard coded model files -def models = ['extraction.zip'] - -// Root URL for model archives -def MODEL_URL = 'https://github.com/PariksheetPinjari909/TVM_models/blob/master/extraction_model' -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'de.undercouch:gradle-download-task:5.0.4' - } -} - -import de.undercouch.gradle.tasks.download.Download -task downloadFile(type: Download){ - for (f in models) { - src "${MODEL_URL}/" + f + "?raw=true" - dest new File(project.ext.TMP_DIR + "/" + f) - } - overwrite true -} - -task extractModels(type: Copy) { - def needDownload = false - for (f in models) { - def localFile = f.split("/")[-1] - if (!(new File(project.ext.TMP_DIR + '/' + localFile)).exists()) { - needDownload = true - } - } - - if (needDownload) { - dependsOn downloadFile - } - - for (f in models) { - def localFile = f.split("/")[-1] - from zipTree(project.ext.TMP_DIR + '/' + localFile) - } - - into file(project.ext.ASSET_DIR) - fileMode 0644 - exclude '**/LICENSE' -} - -tasks.whenTaskAdded { task -> - if (task.name == 'assembleDebug') { - task.dependsOn 'extractModels' - } - if (task.name == 'assembleRelease') { - task.dependsOn 'extractModels' - } - if (task.name == 'mergeDebugAssets') { - task.dependsOn 'extractModels' - } - if (task.name == 'mergeReleaseAssets') { - task.dependsOn 'extractModels' - } - if (task.name == 'lintVitalAnalyzeRelease') { - task.dependsOn 'extractModels' - } - if (task.name == 'lintVitalReportRelease') { - task.dependsOn 'extractModels' - } - if (task.name == 'lintAnalyzeDebug') { - task.dependsOn 'extractModels' - } - if (task.name == 'lintReportDebug') { - task.dependsOn 'extractModels' - } -} diff --git a/apps/android_deploy/app/src/main/AndroidManifest.xml b/apps/android_deploy/app/src/main/AndroidManifest.xml deleted file mode 100644 index 1201ad5f37f2..000000000000 --- a/apps/android_deploy/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java b/apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java deleted file mode 100644 index 6320b6aa8afd..000000000000 --- a/apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java +++ /dev/null @@ -1,635 +0,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. - */ - -package org.apache.tvm.android.demo; - -import android.Manifest; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.AssetManager; -import android.app.AlertDialog; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.os.SystemClock; -import android.provider.MediaStore; -import androidx.core.content.FileProvider; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; -import android.util.Log; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.Vector; - -import org.apache.tvm.Function; -import org.apache.tvm.Module; -import org.apache.tvm.NDArray; -import org.apache.tvm.Device; -import org.apache.tvm.TVMValue; -import org.apache.tvm.TVMType; - -public class MainActivity extends AppCompatActivity { - private static final String TAG = MainActivity.class.getSimpleName(); - - private static final int PERMISSIONS_REQUEST = 100; - private static final int PICTURE_FROM_GALLERY = 101; - private static final int PICTURE_FROM_CAMERA = 102; - private static final int IMAGE_PREVIEW_WIDTH = 960; - private static final int IMAGE_PREVIEW_HEIGHT = 720; - - // TVM constants - private static final int OUTPUT_INDEX = 0; - private static final int IMG_CHANNEL = 3; - private static final String INPUT_NAME = "data"; - - // Configuration values for extraction model. Note that the graph, lib and params is not - // included with TVM and must be manually placed in the assets/ directory by the user. - // Graphs and models downloaded from https://github.com/pjreddie/darknet/blob/ may be - // converted e.g. via define_and_compile_model.py. - private static final boolean EXE_GPU = false; - private static final int MODEL_INPUT_SIZE = 224; - private static final String MODEL_CL_LIB_FILE = "file:///android_asset/deploy_lib_opencl.so"; - private static final String MODEL_CPU_LIB_FILE = "file:///android_asset/deploy_lib_cpu.so"; - private static final String MODEL_GRAPH_FILE = "file:///android_asset/deploy_graph.json"; - private static final String MODEL_PARAM_FILE = "file:///android_asset/deploy_param.params"; - private static final String MODEL_LABEL_FILE = "file:///android_asset/imagenet.shortnames.list"; - - private Uri mCameraImageUri; - private ImageView mImageView; - private TextView mResultView; - private AssetManager assetManager; - private Module graphExecutorModule; - private Vector labels = new Vector(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - assetManager = getAssets(); - - mImageView = (ImageView) findViewById(R.id.imageView); - mResultView = (TextView) findViewById(R.id.resultTextView); - findViewById(R.id.btnPickImage).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showPictureDialog(); - } - }); - - if (hasPermission()) { - // instantiate tvm runtime and setup environment on background after application begin - new LoadModleAsyncTask().execute(); - } else { - requestPermission(); - } - } - - /* - Load precompiled model on TVM graph executor and init the system. - */ - private class LoadModleAsyncTask extends AsyncTask { - ProgressDialog dialog = new ProgressDialog(MainActivity.this); - - @Override - protected Integer doInBackground(Void... args) { - - // load synset name - String lableFilename = MODEL_LABEL_FILE.split("file:///android_asset/")[1]; - Log.i(TAG, "Reading synset name from: " + lableFilename); - try { - String labelsContent = new String(getBytesFromFile(assetManager, lableFilename)); - for (String line : labelsContent.split("\\r?\\n")) { - labels.add(line); - } - } catch (IOException e) { - Log.e(TAG, "Problem reading synset name file!" + e); - return -1;//failure - } - - // load json graph - String modelGraph = null; - String graphFilename = MODEL_GRAPH_FILE.split("file:///android_asset/")[1]; - Log.i(TAG, "Reading json graph from: " + graphFilename); - try { - modelGraph = new String(getBytesFromFile(assetManager, graphFilename)); - } catch (IOException e) { - Log.e(TAG, "Problem reading json graph file!" + e); - return -1;//failure - } - - // upload tvm compiled function on application cache folder - String libCacheFilePath = null; - String libFilename = EXE_GPU ? MODEL_CL_LIB_FILE.split("file:///android_asset/")[1] : - MODEL_CPU_LIB_FILE.split("file:///android_asset/")[1]; - Log.i(TAG, "Uploading compiled function to cache folder"); - try { - libCacheFilePath = getTempLibFilePath(libFilename); - byte[] modelLibByte = getBytesFromFile(assetManager, libFilename); - FileOutputStream fos = new FileOutputStream(libCacheFilePath); - fos.write(modelLibByte); - fos.close(); - } catch (IOException e) { - Log.e(TAG, "Problem uploading compiled function!" + e); - return -1;//failure - } - - // load parameters - byte[] modelParams = null; - String paramFilename = MODEL_PARAM_FILE.split("file:///android_asset/")[1]; - try { - modelParams = getBytesFromFile(assetManager, paramFilename); - } catch (IOException e) { - Log.e(TAG, "Problem reading params file!" + e); - return -1;//failure - } - - // create java tvm device - Device tvmDev = EXE_GPU ? Device.opencl() : Device.cpu(); - - // tvm module for compiled functions - Module modelLib = Module.load(libCacheFilePath); - - // get global function module for graph executor - Function runtimeCreFun = Function.getFunction("tvm.graph_executor.create"); - TVMValue runtimeCreFunRes = runtimeCreFun.pushArg(modelGraph) - .pushArg(modelLib) - .pushArg(tvmDev.deviceType) - .pushArg(tvmDev.deviceId) - .invoke(); - graphExecutorModule = runtimeCreFunRes.asModule(); - - // get the function from the module(load parameters) - Function loadParamFunc = graphExecutorModule.getFunction("load_params"); - loadParamFunc.pushArg(modelParams).invoke(); - - // release tvm local variables - modelLib.release(); - loadParamFunc.release(); - runtimeCreFun.release(); - - return 0;//success - } - - @Override - protected void onPreExecute() { - dialog.setCancelable(false); - dialog.setMessage("Loading Model..."); - dialog.show(); - super.onPreExecute(); - } - - @Override - protected void onPostExecute(Integer status) { - if (dialog != null && dialog.isShowing()) { - dialog.dismiss(); - } - if (status != 0) { - showDialog("Error", "Fail to initialized model, check compiled model"); - } - } - } - - /* - Execute prediction for processed decode input bitmap image content on TVM graph executor. - */ - private class ModelRunAsyncTask extends AsyncTask { - ProgressDialog dialog = new ProgressDialog(MainActivity.this); - - @Override - protected Integer doInBackground(Bitmap... bitmaps) { - if (null != graphExecutorModule) { - int count = bitmaps.length; - for (int i = 0 ; i < count ; i++) { - long processingTimeMs = SystemClock.uptimeMillis(); - Log.i(TAG, "Decode JPEG image content"); - - // extract the jpeg content - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - bitmaps[i].compress(Bitmap.CompressFormat.JPEG,100,stream); - byte[] byteArray = stream.toByteArray(); - Bitmap imageBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); - - // crop input image at centre to model input size - // commecial deploy note:: instead of cropying image do resize - // image to model input size so we never lost the image content - Bitmap cropImageBitmap = Bitmap.createBitmap(MODEL_INPUT_SIZE, MODEL_INPUT_SIZE, Bitmap.Config.ARGB_8888); - Matrix frameToCropTransform = getTransformationMatrix(imageBitmap.getWidth(), imageBitmap.getHeight(), - MODEL_INPUT_SIZE, MODEL_INPUT_SIZE, 0, true); - Canvas canvas = new Canvas(cropImageBitmap); - canvas.drawBitmap(imageBitmap, frameToCropTransform, null); - - // image pixel int values - int[] pixelValues = new int[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE]; - // image RGB float values - float[] imgRgbValues = new float[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE * IMG_CHANNEL]; - // image RGB transpose float values - float[] imgRgbTranValues = new float[MODEL_INPUT_SIZE * MODEL_INPUT_SIZE * IMG_CHANNEL]; - - // pre-process the image data from 0-255 int to normalized float based on the - // provided parameters. - cropImageBitmap.getPixels(pixelValues, 0, MODEL_INPUT_SIZE, 0, 0, MODEL_INPUT_SIZE, MODEL_INPUT_SIZE); - for (int j = 0; j < pixelValues.length; ++j) { - imgRgbValues[j * 3 + 0] = ((pixelValues[j] >> 16) & 0xFF)/255.0f; - imgRgbValues[j * 3 + 1] = ((pixelValues[j] >> 8) & 0xFF)/255.0f; - imgRgbValues[j * 3 + 2] = (pixelValues[j] & 0xFF)/255.0f; - } - - // pre-process the image rgb data transpose based on the provided parameters. - for (int k = 0; k < IMG_CHANNEL; ++k) { - for (int l = 0; l < MODEL_INPUT_SIZE; ++l) { - for (int m = 0; m < MODEL_INPUT_SIZE; ++m) { - int dst_index = m + MODEL_INPUT_SIZE*l + MODEL_INPUT_SIZE*MODEL_INPUT_SIZE*k; - int src_index = k + IMG_CHANNEL*m + IMG_CHANNEL*MODEL_INPUT_SIZE*l; - imgRgbTranValues[dst_index] = imgRgbValues[src_index]; - } - } - } - - // get the function from the module(set input data) - Log.i(TAG, "set input data"); - NDArray inputNdArray = NDArray.empty(new long[]{1, IMG_CHANNEL, MODEL_INPUT_SIZE, MODEL_INPUT_SIZE}, new TVMType("float32"));; - inputNdArray.copyFrom(imgRgbTranValues); - Function setInputFunc = graphExecutorModule.getFunction("set_input"); - setInputFunc.pushArg(INPUT_NAME).pushArg(inputNdArray).invoke(); - // release tvm local variables - inputNdArray.release(); - setInputFunc.release(); - - // get the function from the module(run it) - Log.i(TAG, "run function on target"); - Function runFunc = graphExecutorModule.getFunction("run"); - runFunc.invoke(); - // release tvm local variables - runFunc.release(); - - // get the function from the module(get output data) - Log.i(TAG, "get output data"); - NDArray outputNdArray = NDArray.empty(new long[]{1, 1000}, new TVMType("float32")); - Function getOutputFunc = graphExecutorModule.getFunction("get_output"); - getOutputFunc.pushArg(OUTPUT_INDEX).pushArg(outputNdArray).invoke(); - float[] output = outputNdArray.asFloatArray(); - // release tvm local variables - outputNdArray.release(); - getOutputFunc.release(); - - // display the result from extracted output data - if (null != output) { - int maxPosition = -1; - float maxValue = 0; - for (int j = 0; j < output.length; ++j) { - if (output[j] > maxValue) { - maxValue = output[j]; - maxPosition = j; - } - } - processingTimeMs = SystemClock.uptimeMillis() - processingTimeMs; - String label = "Prediction Result : "; - label += labels.size() > maxPosition ? labels.get(maxPosition) : "unknown"; - label += "\nPrediction Time : " + processingTimeMs + "ms"; - mResultView.setText(label); - } - Log.i(TAG, "prediction finished"); - } - return 0; - } - return -1; - } - - @Override - protected void onPreExecute() { - dialog.setCancelable(false); - dialog.setMessage("Prediction running on image..."); - dialog.show(); - super.onPreExecute(); - } - - @Override - protected void onPostExecute(Integer status) { - if (dialog != null && dialog.isShowing()) { - dialog.dismiss(); - } - if (status != 0) { - showDialog("Error", "Fail to predict image, GraphExecutor exception"); - } - } - } - - @Override - protected void onDestroy() { - // release tvm local variables - if (null != graphExecutorModule) - graphExecutorModule.release(); - super.onDestroy(); - } - - /** - * Read file from assets and return byte array. - * - * @param assets The asset manager to be used to load assets. - * @param fileName The filepath of read file. - * @return byte[] file content - * @throws IOException - */ - private byte[] getBytesFromFile(AssetManager assets, String fileName) throws IOException { - InputStream is = assets.open(fileName); - int length = is.available(); - byte[] bytes = new byte[length]; - // Read in the bytes - int offset = 0; - int numRead = 0; - try { - while (offset < bytes.length - && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { - offset += numRead; - } - } finally { - is.close(); - } - // Ensure all the bytes have been read in - if (offset < bytes.length) { - throw new IOException("Could not completely read file " + fileName); - } - return bytes; - } - - /** - * Dialog show pick option for select image from Gallery or Camera. - */ - private void showPictureDialog(){ - AlertDialog.Builder pictureDialog = new AlertDialog.Builder(this); - pictureDialog.setTitle("Select Action"); - String[] pictureDialogItems = { - "Select photo from gallery", - "Capture photo from camera" }; - pictureDialog.setItems(pictureDialogItems, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case 0: - choosePhotoFromGallery(); - break; - case 1: - takePhotoFromCamera(); - break; - } - } - }); - pictureDialog.show(); - } - - /** - * Request to pick image from Gallery. - */ - public void choosePhotoFromGallery() { - Intent galleryIntent = new Intent(Intent.ACTION_PICK, - android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - - startActivityForResult(galleryIntent, PICTURE_FROM_GALLERY); - } - - /** - * Request to capture image from Camera. - */ - private void takePhotoFromCamera() { - Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - mCameraImageUri = Uri.fromFile(createImageFile()); - } else { - File file = new File(createImageFile().getPath()); - mCameraImageUri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", file); - } - - intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraImageUri); - startActivityForResult(intent, PICTURE_FROM_CAMERA); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == this.RESULT_CANCELED) { - return; - } - Uri contentURI = null; - if (requestCode == PICTURE_FROM_GALLERY) { - if (data != null) { - contentURI = data.getData(); - } - } else if (requestCode == PICTURE_FROM_CAMERA) { - contentURI = mCameraImageUri; - } - if (null != contentURI) { - try { - Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI); - Bitmap scaled = Bitmap.createScaledBitmap(bitmap, IMAGE_PREVIEW_HEIGHT, IMAGE_PREVIEW_WIDTH, true); - mImageView.setImageBitmap(scaled); - new ModelRunAsyncTask().execute(scaled); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * Get application cache path where to place compiled functions. - * - * @param fileName library file name. - * @return String application cache folder path - * @throws IOException - */ - private final String getTempLibFilePath(String fileName) throws IOException { - File tempDir = File.createTempFile("tvm4j_demo_", ""); - if (!tempDir.delete() || !tempDir.mkdir()) { - throw new IOException("Couldn't create directory " + tempDir.getAbsolutePath()); - } - return (tempDir + File.separator + fileName); - } - - /** - * Create image file under storage where camera application save captured image. - * - * @return File image file under sdcard where camera can save image - */ - private File createImageFile() { - // Create an image file name - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); - String imageFileName = "JPEG_" + timeStamp + "_"; - File storageDir = Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES); - try { - File image = File.createTempFile( - imageFileName, // prefix - ".jpg", // suffix - storageDir // directory - ); - return image; - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - /** - * Show dialog to user. - * - * @param title dialog display title - * @param msg dialog display message - */ - 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(); - finish(); - } - }); - builder.create().show(); - } - - @Override - public void onRequestPermissionsResult (final int requestCode, final String[] permissions, final int[] grantResults){ - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == PERMISSIONS_REQUEST) { - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED - && grantResults[1] == PackageManager.PERMISSION_GRANTED) { - // instantiate tvm runtime and setup environment on background after application begin - new LoadModleAsyncTask().execute(); - } else { - requestPermission(); - } - } - } - - /** - * Whether application has required mandatory permissions to run. - */ - private boolean hasPermission() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - return checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED && - checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; - } else { - return true; - } - } - - /** - * Request required mandatory permission for application to run. - */ - private void requestPermission() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA) || - shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - Toast.makeText(this, - "Camera AND storage permission are required for this demo", Toast.LENGTH_LONG).show(); - } - requestPermissions(new String[] {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST); - } - } - - /** - * Returns a transformation matrix from one reference frame into another. - * Handles cropping (if maintaining aspect ratio is desired) and rotation. - * - * @param srcWidth Width of source frame. - * @param srcHeight Height of source frame. - * @param dstWidth Width of destination frame. - * @param dstHeight Height of destination frame. - * @param applyRotation Amount of rotation to apply from one frame to another. - * Must be a multiple of 90. - * @param maintainAspectRatio If true, will ensure that scaling in x and y remains constant, - * cropping the image if necessary. - * @return The transformation fulfilling the desired requirements. - */ - public static Matrix getTransformationMatrix( - final int srcWidth, - final int srcHeight, - final int dstWidth, - final int dstHeight, - final int applyRotation, - final boolean maintainAspectRatio) { - final Matrix matrix = new Matrix(); - - if (applyRotation != 0) { - if (applyRotation % 90 != 0) { - Log.w(TAG, "Rotation of %d % 90 != 0 " + applyRotation); - } - - // Translate so center of image is at origin. - matrix.postTranslate(-srcWidth / 2.0f, -srcHeight / 2.0f); - - // Rotate around origin. - matrix.postRotate(applyRotation); - } - - // Account for the already applied rotation, if any, and then determine how - // much scaling is needed for each axis. - final boolean transpose = (Math.abs(applyRotation) + 90) % 180 == 0; - - final int inWidth = transpose ? srcHeight : srcWidth; - final int inHeight = transpose ? srcWidth : srcHeight; - - // Apply scaling if necessary. - if (inWidth != dstWidth || inHeight != dstHeight) { - final float scaleFactorX = dstWidth / (float) inWidth; - final float scaleFactorY = dstHeight / (float) inHeight; - - if (maintainAspectRatio) { - // Scale by minimum factor so that dst is filled completely while - // maintaining the aspect ratio. Some image may fall off the edge. - final float scaleFactor = Math.max(scaleFactorX, scaleFactorY); - matrix.postScale(scaleFactor, scaleFactor); - } else { - // Scale exactly to fill dst from src. - matrix.postScale(scaleFactorX, scaleFactorY); - } - } - - if (applyRotation != 0) { - // Translate back from origin centered reference to destination frame. - matrix.postTranslate(dstWidth / 2.0f, dstHeight / 2.0f); - } - - return matrix; - } -} diff --git a/apps/android_deploy/app/src/main/jni/Android.mk b/apps/android_deploy/app/src/main/jni/Android.mk deleted file mode 100644 index ad9cee9bbdb5..000000000000 --- a/apps/android_deploy/app/src/main/jni/Android.mk +++ /dev/null @@ -1,58 +0,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. - -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/dlpack/include \ - $(ROOT_PATH)/3rdparty/dmlc-core/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) diff --git a/apps/android_deploy/app/src/main/jni/Application.mk b/apps/android_deploy/app/src/main/jni/Application.mk deleted file mode 100644 index 4a83907ff329..000000000000 --- a/apps/android_deploy/app/src/main/jni/Application.mk +++ /dev/null @@ -1,33 +0,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. - -ifndef config - ifneq ("$(wildcard ./config.mk)","") - config ?= config.mk - else - config ?= make/config.mk - endif -endif - -include $(config) - -APP_STL := c++_static - -APP_CPPFLAGS += -DTVM_LOG_STACK_TRACE=0 -DTVM4J_ANDROID=1 -std=c++17 -Oz -frtti -ifeq ($(USE_OPENCL), 1) - APP_CPPFLAGS += -DTVM_OPENCL_RUNTIME=1 -endif diff --git a/apps/android_deploy/app/src/main/jni/make/config.mk b/apps/android_deploy/app/src/main/jni/make/config.mk deleted file mode 100644 index b06f42b2647a..000000000000 --- a/apps/android_deploy/app/src/main/jni/make/config.mk +++ /dev/null @@ -1,43 +0,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. - -#------------------------------------------------------------------------------- -# Template configuration for compiling -# -# If you want to change the configuration, please use the following -# steps. Assume you are on the root directory. First copy the this -# file so that any local changes will be ignored by git -# -# cp make/config.mk . -# -# Next modify the according entries, and then compile by -# -# ./build.sh -# -#------------------------------------------------------------------------------- -APP_ABI = all - -APP_PLATFORM = android-17 - -# whether enable OpenCL during compile -USE_OPENCL = 1 - -# the additional include headers you want to add, e.g., SDK_PATH/adrenosdk/Development/Inc -ADD_C_INCLUDES = - -# the additional link libs you want to add, e.g., ANDROID_LIB_PATH/libOpenCL.so -ADD_LDLIBS = diff --git a/apps/android_deploy/app/src/main/jni/tvm_runtime.h b/apps/android_deploy/app/src/main/jni/tvm_runtime.h deleted file mode 100644 index 9eda834eb433..000000000000 --- a/apps/android_deploy/app/src/main/jni/tvm_runtime.h +++ /dev/null @@ -1,54 +0,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. - */ - -/*! - * \file tvm_runtime.h - * \brief Pack all tvm runtime source files - */ -#include - -#include - -#define DMLC_USE_LOGGING_LIBRARY -#define TVM_USE_LIBBACKTRACE 0 - -#include "../src/runtime/c_runtime_api.cc" -#include "../src/runtime/cpu_device_api.cc" -#include "../src/runtime/dso_library.cc" -#include "../src/runtime/file_utils.cc" -#include "../src/runtime/graph_executor/graph_executor.cc" -#include "../src/runtime/library_module.cc" -#include "../src/runtime/logging.cc" -#include "../src/runtime/memory/memory_manager.cc" -#include "../src/runtime/module.cc" -#include "../src/runtime/ndarray.cc" -#include "../src/runtime/object.cc" -#include "../src/runtime/registry.cc" -#include "../src/runtime/system_library.cc" -#include "../src/runtime/thread_pool.cc" -#include "../src/runtime/threading_backend.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/opencl/texture_pool.cc" -#include "../src/runtime/source_utils.cc" -#endif diff --git a/apps/android_deploy/app/src/main/res/layout/activity_main.xml b/apps/android_deploy/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 4b019e1fbdb3..000000000000 --- a/apps/android_deploy/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/apps/android_deploy/app/src/main/res/layout/content_main.xml b/apps/android_deploy/app/src/main/res/layout/content_main.xml deleted file mode 100644 index 6bf3c19f7f81..000000000000 --- a/apps/android_deploy/app/src/main/res/layout/content_main.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - -