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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/apps/android_deploy/app/src/main/res/values/colors.xml b/apps/android_deploy/app/src/main/res/values/colors.xml
deleted file mode 100644
index de118e84f241..000000000000
--- a/apps/android_deploy/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
- #3F51B5
- #303F9F
- #06d467
-
diff --git a/apps/android_deploy/app/src/main/res/values/strings.xml b/apps/android_deploy/app/src/main/res/values/strings.xml
deleted file mode 100644
index 2a3877425303..000000000000
--- a/apps/android_deploy/app/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
- TVM Android Demo
- Select or Capture Picture
- Input Image
-
diff --git a/apps/android_deploy/app/src/main/res/values/styles.xml b/apps/android_deploy/app/src/main/res/values/styles.xml
deleted file mode 100644
index ff46174caf9d..000000000000
--- a/apps/android_deploy/app/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/apps/android_deploy/app/src/main/res/xml/provider_paths.xml b/apps/android_deploy/app/src/main/res/xml/provider_paths.xml
deleted file mode 100644
index d456cf24918f..000000000000
--- a/apps/android_deploy/app/src/main/res/xml/provider_paths.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
diff --git a/apps/android_deploy/build.gradle b/apps/android_deploy/build.gradle
deleted file mode 100644
index b6d686b4e4c1..000000000000
--- a/apps/android_deploy/build.gradle
+++ /dev/null
@@ -1,51 +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'
- classpath 'org.apache.httpcomponents:httpclient:4.5.13'
-
- // 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_deploy/dev_tools/gen_keystore.sh b/apps/android_deploy/dev_tools/gen_keystore.sh
deleted file mode 100644
index 31f3d2acf3b9..000000000000
--- a/apps/android_deploy/dev_tools/gen_keystore.sh
+++ /dev/null
@@ -1,19 +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_deploy/dev_tools/sign_apk.sh b/apps/android_deploy/dev_tools/sign_apk.sh
deleted file mode 100644
index cd28998a7782..000000000000
--- a/apps/android_deploy/dev_tools/sign_apk.sh
+++ /dev/null
@@ -1,23 +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/tvmdemo-release.apk
-jarsigner -verbose -keystore $CURR_DIR/tvmdemo.keystore -signedjar $SIGNED_APK $UNSIGNED_APK 'tvmdemo'
-echo $SIGNED_APK
diff --git a/apps/android_deploy/gradle.properties b/apps/android_deploy/gradle.properties
deleted file mode 100644
index a7f4fa066909..000000000000
--- a/apps/android_deploy/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=-Xmx4096M
-android.useAndroidX=true
-android.enableJetifier=true
diff --git a/apps/android_deploy/settings.gradle b/apps/android_deploy/settings.gradle
deleted file mode 100644
index ee503c22bf30..000000000000
--- a/apps/android_deploy/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/bundle_deploy/Makefile b/apps/bundle_deploy/Makefile
deleted file mode 100644
index bea2269d75db..000000000000
--- a/apps/bundle_deploy/Makefile
+++ /dev/null
@@ -1,177 +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.
-
-# Makefile Example to bundle TVM modules.
-
-# Setup build environment
-TVM_ROOT=$(shell cd ../..; pwd)
-CRT_ROOT ?= ../../build/standalone_crt
-ifeq ($(shell ls -lhd $(CRT_ROOT)),)
-$(error "CRT not found. Ensure you have built the standalone_crt target and try again")
-endif
-
-ENABLE_TVM_PLATFORM_ABORT_BACKTRACE ?= 1
-
-build_dir := build
-
-DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
-PKG_COMPILE_OPTS = -g -Wall -O2 -fPIC
-PKG_CXXFLAGS = ${PKG_COMPILE_OPTS} -std=c++17 \
- -I${TVM_ROOT}/include \
- -I${DMLC_CORE}/include \
- -I${TVM_ROOT}/3rdparty/dlpack/include \
- -I${build_dir}/crt_config \
- -DDMLC_USE_LOGGING_LIBRARY=\
-PKG_CFLAGS = ${PKG_COMPILE_OPTS} \
- -I${TVM_ROOT}/include \
- -I${DMLC_CORE}/include \
- -I${TVM_ROOT}/3rdparty/dlpack/include \
- -I${build_dir}/crt_config \
- -DDMLC_USE_LOGGING_LIBRARY=\
-
-PKG_LDFLAGS = -pthread -lm
-
-
-
-BACKTRACE_SRCS =
-BACKTRACE_LDFLAGS =
-BACKTRACE_CFLAGS =
-$(ifeq ENABLE_TVM_PLATFORM_ABORT_BACKTRACE,1)
-BACKTRACE_SRCS += backtrace.c
-BACKTRACE_LDFLAGS += -ldl
-BACKTRACE_CFLAGS += -DENABLE_TVM_PLATFORM_ABORT_BACKTRACE
-$(endif)
-
-BACKTRACE_OBJS = $(patsubst %.c,$(build_dir)/%.o,$(BACKTRACE_SRCS))
-
-$(ifeq VERBOSE,1)
-QUIET ?=
-$(else)
-QUIET ?= @
-$(endif)
-
-MODEL_OBJ = $(build_dir)/model_c/devc.o $(build_dir)/model_c/lib0.o $(build_dir)/model_c/lib1.o
-TEST_MODEL_OBJ = $(build_dir)/test_model_c/devc.o $(build_dir)/test_model_c/lib0.o $(build_dir)/test_model_c/lib1.o
-
-demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/bundle.so $(build_dir)/graph_cpp.json $(build_dir)/graph_c.json $(build_dir)/params_cpp.bin $(build_dir)/params_c.bin $(build_dir)/cat.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/graph_cpp.json $(build_dir)/params_cpp.bin $(build_dir)/cat.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/demo_dynamic $(build_dir)/bundle_c.so $(build_dir)/graph_c.json $(build_dir)/params_c.bin $(build_dir)/cat.bin
-
-test_dynamic: $(build_dir)/test_dynamic $(build_dir)/test_bundle.so $(build_dir)/test_bundle_c.so $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin $(build_dir)/test_data_cpp.bin $(build_dir)/test_output_cpp.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/test_dynamic $(build_dir)/test_bundle.so $(build_dir)/test_data_cpp.bin $(build_dir)/test_output_cpp.bin $(build_dir)/test_graph_cpp.json $(build_dir)/test_params_cpp.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/test_dynamic $(build_dir)/test_bundle_c.so $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin $(build_dir)/test_graph_c.json $(build_dir)/test_params_c.bin
-
-demo_static: $(build_dir)/demo_static $(build_dir)/cat.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/demo_static $(build_dir)/cat.bin
-
-test_static: $(build_dir)/crt_config/crt_config.h $(build_dir)/test_static $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin
- $(QUIET)TVM_NUM_THREADS=1 $(build_dir)/test_static $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin $(build_dir)/test_graph_c.json $(build_dir)/test_params_c.bin
-
-$(build_dir)/crt_config/crt_config.h:
- $(QUIET)mkdir --parents $(build_dir)/crt_config && cp ../../build/microtvm_template_projects/crt/crt_config/crt_config.h $(build_dir)/crt_config/crt_config.h
-
-$(build_dir)/crt:
- $(QUIET)mkdir --parents $(build_dir)/crt && cp -r $(CRT_ROOT)/* $(build_dir)/crt
-
-$(build_dir)/libcommon.a: $(build_dir)/crt $(build_dir)/crt_config/crt_config.h
- $(QUIET)cd $(build_dir)/crt && mkdir -p build && cd build && cmake -DCRT_CONFIG_PATH=$(abspath $(build_dir)/crt_config) -DCMAKE_C_FLAGS="${PKG_COMPILE_OPTS}" .. && make && cp libcommon.a $(abspath $(build_dir)/libcommon.a)
-
-$(build_dir)/libgraph_executor.a: $(build_dir)/crt $(build_dir)/crt_config/crt_config.h
- $(QUIET)cd $(build_dir)/crt && mkdir -p build && cd build && cmake -DCRT_CONFIG_PATH=$(abspath $(build_dir)/crt_config) -DCMAKE_C_FLAGS="${PKG_COMPILE_OPTS}" .. && make && cp libgraph_executor.a $(abspath $(build_dir)/libgraph_executor.a)
-
-$(build_dir)/libmemory.a: $(build_dir)/crt $(build_dir)/crt_config/crt_config.h
- $(QUIET)cd $(build_dir)/crt && mkdir -p build && cd build && cmake -DCRT_CONFIG_PATH=$(abspath $(build_dir)/crt_config) -DCMAKE_C_FLAGS="${PKG_COMPILE_OPTS}" .. && make && cp libmemory.a $(abspath $(build_dir)/libmemory.a)
-
-$(build_dir)/demo_dynamic: demo.cc
- $(QUIET)mkdir -p $(@D)
- $(QUIET)g++ $(PKG_CXXFLAGS) -o $@ demo.cc $(BACKTRACE_LDFLAGS)
-
-$(build_dir)/test_dynamic: test.cc ${build_dir}/test_graph_c.json ${build_dir}/test_params_c.bin $(BACKTRACE_OBJS)
- $(QUIET)mkdir -p $(@D)
- $(QUIET)g++ $(PKG_CXXFLAGS) -o $@ test.cc $(BACKTRACE_OBJS) $(BACKTRACE_LDFLAGS)
-
-$(build_dir)/demo_static: demo_static.c ${build_dir}/bundle_static.o $(MODEL_OBJ) ${build_dir}/libmemory.a ${build_dir}/libgraph_executor.a ${build_dir}/libcommon.a ${build_dir}/graph_c.json.c ${build_dir}/params_c.bin.c $(BACKTRACE_OBJS)
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc $(PKG_CFLAGS) -o $@ $^ $(PKG_LDFLAGS) $(BACKTRACE_LDFLAGS) $(BACKTRACE_CFLAGS)
-
-$(build_dir)/test_static: test_static.c ${build_dir}/bundle_static.o $(TEST_MODEL_OBJ) ${build_dir}/libmemory.a ${build_dir}/libgraph_executor.a ${build_dir}/libcommon.a $(BACKTRACE_OBJS)
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc $(PKG_CFLAGS) -o $@ $^ $(BACKTRACE_LDFLAGS)
-
-$(build_dir)/backtrace.o: backtrace.c
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc -c $(PKG_CFLAGS) -o $@ $^ $(BACKTRACE_CFLAGS)
-
-# Serialize our graph.json file.
-$(build_dir)/graph_cpp.json.c: $(build_dir)/graph_cpp.json
- $(QUIET)xxd -i $^ > $@
-
-$(build_dir)/graph_c.json.c: $(build_dir)/graph_c.json
- $(QUIET)xxd -i $^ > $@
-
-# Serialize our params.bin file.
-$(build_dir)/params_c.bin.c: $(build_dir)/params_c.bin
- $(QUIET)xxd -i $^ > $@
-
-$(build_dir)/params_cpp.bin.c: $(build_dir)/params_cpp.bin
- $(QUIET)xxd -i $^ > $@
-
-$(MODEL_OBJ) $(build_dir)/graph_c.json $(build_dir)/model_cpp.o $(build_dir)/graph_cpp.json $(build_dir)/params.bin $(build_dir)/cat.bin: build_model.py
- $(QUIET)python3 $< -o $(build_dir)
- $(QUIET)mkdir -p build/model_c
- $(QUIET)tar -C build/model_c -xvf build/model_c.tar
-
-$(TEST_MODEL_OBJ) $(build_dir)/test_graph_c.json $(build_dir)/test_params_c.bin $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin $(build_dir)/test_model_cpp.o $(build_dir)/test_graph_cpp.json $(build_dir)/test_params_cpp.bin $(build_dir)/test_data_cpp.bin $(build_dir)/test_output_cpp.bin: build_model.py
- $(QUIET)python3 $< -o $(build_dir) --test
- $(QUIET)mkdir -p build/test_model_c
- $(QUIET)tar -C build/test_model_c -xvf build/test_model_c.tar
-
-# Build our bundle against the serialized bundle.c API, the runtime.cc API, and
-# the serialized graph.json and params.bin
-$(build_dir)/bundle.so: bundle.cc runtime.cc $(build_dir)/model_cpp.o
- $(QUIET)mkdir -p $(@D)
- $(QUIET)g++ -shared $(PKG_CXXFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS)
-
-$(build_dir)/bundle_c.so: bundle.c $(MODEL_OBJ) ${build_dir}/libmemory.a ${build_dir}/libgraph_executor.a ${build_dir}/libcommon.a $(BACKTRACE_OBJS)
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc -shared $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS) $(BACKTRACE_LDFLAGS) $(BACKTRACE_CFLAGS)
-
-$(build_dir)/test_bundle.so: bundle.cc runtime.cc $(build_dir)/test_model_cpp.o
- $(QUIET)mkdir -p $(@D)
- $(QUIET)g++ -shared $(PKG_CXXFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS)
-
-$(build_dir)/test_bundle_c.so: bundle.c $(TEST_MODEL_OBJ) ${build_dir}/libmemory.a ${build_dir}/libgraph_executor.a ${build_dir}/libcommon.a $(BACKTRACE_OBJS)
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc -shared $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS) $(BACKTRACE_LDFLAGS) $(BACKTRACE_CFLAGS)
-
-$(build_dir)/bundle_static.o: bundle_static.c
- $(QUIET)mkdir -p $(@D)
- $(QUIET)gcc -c $(PKG_CFLAGS) -o $@ $^ $(BACKTRACE_CFLAGS)
-
-clean:
- $(QUIET)rm -rf $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/test_bundle.so $(build_dir)/test_bundle_c.so $(build_dir)/crt
-
-cleanall:
- $(QUIET)rm -rf $(build_dir)
-
-# Don't define implicit rules; they tend to match on logical target names that aren't targets (i.e. bundle_static)
-.SUFFIXES:
-
-.DEFAULT: demo_static demo_dynamic
-
-test: test_static test_dynamic
-.PHONY: test
diff --git a/apps/bundle_deploy/README.md b/apps/bundle_deploy/README.md
deleted file mode 100644
index dc7d29619a6e..000000000000
--- a/apps/bundle_deploy/README.md
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-How to Bundle TVM Modules
-=========================
-
-This folder contains an example on how to bundle a TVM module (with the required
-interpreter runtime modules such as `runtime::GraphExecutor`, the graph JSON, and
-the params) into a single, self-contained shared object (`bundle.so`) which
-exposes a C API wrapping the appropriate `runtime::GraphExecutor` instance.
-
-This is useful for cases where we'd like to avoid deploying the TVM runtime
-components to the target host in advance - instead, we simply deploy the bundled
-shared-object to the host, which embeds both the model and the runtime
-components. The bundle should only depend on libc/libc++.
-
-It also contains an example code (`demo.cc`) to load this shared object and
-invoke the packaged TVM model instance. This is a dependency-free binary that
-uses the functionality packaged in `bundle.so` (which means that `bundle.so` can
-be deployed lazily at runtime, instead of at compile time) to invoke TVM
-functionality.
-
-Type the following command to run the sample code under the current folder,
-after building TVM first.
-
-```bash
-make demo_dynamic
-```
-
-This will:
-
-- Download the mobilenet0.25 model from the MXNet Gluon Model Zoo
-- Compile the model with Relay
-- Build a `bundle.so` shared object containing the model specification and
- parameters
-- Build a `demo_dynamic` executable that `dlopen`'s `bundle.so` (or `bundle_c.so` in
- terms of the MISRA-C runtime), instantiates the contained graph executor,
- and invokes the `GraphExecutor::Run` function on a cat image, then prints
- the output results.
-
-Type the following command to run the sample code with static linking.
-
-```bash
-make demo_static
-```
-
-This will:
-- Download the mobilenet0.25 model from the MXNet Gluon Model Zoo
-- Compile the model with Relay and outputs `model.o`
-- Build a `bundle_static.o` object containing the runtime functions
-- Build a `demo_static` executable which has static link to `bundle_static.o` and
- `model.o`, functions on a cat image, then prints the output results.
diff --git a/apps/bundle_deploy/backtrace.c b/apps/bundle_deploy/backtrace.c
deleted file mode 100644
index adb9b94959e2..000000000000
--- a/apps/bundle_deploy/backtrace.c
+++ /dev/null
@@ -1,57 +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.
- */
-
-#define _GNU_SOURCE
-#include "backtrace.h"
-
-#include
-#include
-#include
-#include
-#include
-
-const char* g_argv0 = NULL;
-
-void tvm_platform_abort_backtrace() {
- void* trace[200];
- int nptrs = backtrace(trace, sizeof(trace) / sizeof(void*));
- fprintf(stderr, "backtrace: %d\n", nptrs);
- if (nptrs < 0) {
- perror("backtracing");
- } else {
- backtrace_symbols_fd(trace, nptrs, STDOUT_FILENO);
-
- char cmd_buf[1024];
- for (int i = 0; i < nptrs; i++) {
- Dl_info info;
- if (dladdr(trace[i], &info)) {
- fprintf(stderr, "symbol %d: %s %s %p (%p)\n", i, info.dli_sname, info.dli_fname,
- info.dli_fbase, (void*)(trace[i] - info.dli_fbase));
- snprintf(cmd_buf, sizeof(cmd_buf), "addr2line --exe=%s -p -i -a -f %p", g_argv0,
- (void*)(trace[i] - info.dli_fbase));
- int result = system(cmd_buf);
- if (result < 0) {
- perror("invoking backtrace command");
- }
- } else {
- fprintf(stderr, "symbol %d: %p (unmapped)\n", i, trace[i]);
- }
- }
- }
-}
diff --git a/apps/bundle_deploy/backtrace.h b/apps/bundle_deploy/backtrace.h
deleted file mode 100644
index 1f6346b85703..000000000000
--- a/apps/bundle_deploy/backtrace.h
+++ /dev/null
@@ -1,30 +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.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const char* g_argv0;
-
-void tvm_platform_abort_backtrace(void);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/apps/bundle_deploy/build_model.py b/apps/bundle_deploy/build_model.py
deleted file mode 100644
index 2f8feeba633b..000000000000
--- a/apps/bundle_deploy/build_model.py
+++ /dev/null
@@ -1,167 +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.
-"""Creates a simple TVM modules."""
-
-import argparse
-import os
-import pathlib
-
-from tvm import relay
-import tvm
-from tvm import runtime as tvm_runtime
-import logging
-from tvm.relay.backend import Runtime
-from tvm.contrib import cc as _cc
-
-RUNTIMES = [
- (Runtime("crt", {"system-lib": True}), "{name}_c.{ext}"),
- (Runtime("cpp", {"system-lib": True}), "{name}_cpp.{ext}"),
-]
-
-
-def build_module(opts):
- dshape = (1, 3, 224, 224)
- from mxnet.gluon.model_zoo.vision import get_model
-
- block = get_model("mobilenet0.25", pretrained=True)
- shape_dict = {"data": dshape}
- mod, params = relay.frontend.from_mxnet(block, shape_dict)
- func = mod["main"]
- func = relay.Function(
- func.params, relay.nn.softmax(func.body), None, func.type_params, func.attrs
- )
-
- for runtime, file_format_str in RUNTIMES:
- with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
- graph, lib, params = relay.build(func, "llvm", runtime=runtime, params=params)
-
- build_dir = os.path.abspath(opts.out_dir)
- if not os.path.isdir(build_dir):
- os.makedirs(build_dir)
- ext = "tar" if str(runtime) == "crt" else "o"
- lib_file_name = os.path.join(build_dir, file_format_str.format(name="model", ext=ext))
- if str(runtime) == "crt":
- lib.export_library(lib_file_name)
- else:
- # NOTE: at present, export_libarary will always create _another_ shared object, and you
- # can't stably combine two shared objects together (in this case, init_array is not
- # populated correctly when you do that). So for now, must continue to use save() with the
- # C++ library.
- # TODO(areusch): Obliterate runtime.cc and replace with libtvm_runtime.so.
- lib.save(lib_file_name)
- with open(
- os.path.join(build_dir, file_format_str.format(name="graph", ext="json")), "w"
- ) as f_graph_json:
- f_graph_json.write(graph)
- with open(
- os.path.join(build_dir, file_format_str.format(name="params", ext="bin")), "wb"
- ) as f_params:
- f_params.write(tvm_runtime.save_param_dict(params))
-
-
-def build_test_module(opts):
- import numpy as np
-
- x = relay.var("x", shape=(10, 5))
- y = relay.var("y", shape=(1, 5))
- z = relay.add(x, y)
- func = relay.Function([x, y], z)
- x_data = np.random.rand(10, 5).astype("float32")
- y_data = np.random.rand(1, 5).astype("float32")
- params = {"y": y_data}
-
- for runtime, file_format_str in RUNTIMES:
- with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
- graph, lib, lowered_params = relay.build(
- tvm.IRModule.from_expr(func),
- "llvm",
- runtime=runtime,
- params=params,
- )
-
- build_dir = os.path.abspath(opts.out_dir)
- if not os.path.isdir(build_dir):
- os.makedirs(build_dir)
- ext = "tar" if str(runtime) == "crt" else "o"
- lib_file_name = os.path.join(build_dir, file_format_str.format(name="test_model", ext=ext))
- if str(runtime) == "crt":
- lib.export_library(lib_file_name)
- else:
- # NOTE: at present, export_libarary will always create _another_ shared object, and you
- # can't stably combine two shared objects together (in this case, init_array is not
- # populated correctly when you do that). So for now, must continue to use save() with the
- # C++ library.
- # TODO(areusch): Obliterate runtime.cc and replace with libtvm_runtime.so.
- lib.save(lib_file_name)
- with open(
- os.path.join(build_dir, file_format_str.format(name="test_graph", ext="json")), "w"
- ) as f_graph_json:
- f_graph_json.write(graph)
- with open(
- os.path.join(build_dir, file_format_str.format(name="test_params", ext="bin")), "wb"
- ) as f_params:
- f_params.write(tvm_runtime.save_param_dict(lowered_params))
- with open(
- os.path.join(build_dir, file_format_str.format(name="test_data", ext="bin")), "wb"
- ) as fp:
- fp.write(x_data.astype(np.float32).tobytes())
- x_output = x_data + y_data
- with open(
- os.path.join(build_dir, file_format_str.format(name="test_output", ext="bin")), "wb"
- ) as fp:
- fp.write(x_output.astype(np.float32).tobytes())
-
-
-def build_inputs(opts):
- from tvm.contrib import download
- from PIL import Image
- import numpy as np
-
- build_dir = os.path.abspath(opts.out_dir)
-
- # Download test image
- image_url = "https://homes.cs.washington.edu/~moreau/media/vta/cat.jpg"
- image_fn = os.path.join(build_dir, "cat.png")
- download.download(image_url, image_fn)
- image = Image.open(image_fn).resize((224, 224))
-
- def transform_image(image):
- image = np.array(image) - np.array([123.0, 117.0, 104.0])
- image /= np.array([58.395, 57.12, 57.375])
- image = image.transpose((2, 0, 1))
- image = image[np.newaxis, :]
- return image
-
- x = transform_image(image)
- print("x", x.shape)
- with open(os.path.join(build_dir, "cat.bin"), "wb") as fp:
- fp.write(x.astype(np.float32).tobytes())
-
-
-if __name__ == "__main__":
- logging.basicConfig(level=logging.INFO)
-
- parser = argparse.ArgumentParser()
- parser.add_argument("-o", "--out-dir", default=".")
- parser.add_argument("-t", "--test", action="store_true")
- opts = parser.parse_args()
-
- if opts.test:
- build_test_module(opts)
- else:
- build_module(opts)
- build_inputs(opts)
diff --git a/apps/bundle_deploy/bundle.c b/apps/bundle_deploy/bundle.c
deleted file mode 100644
index 6018d40dd300..000000000000
--- a/apps/bundle_deploy/bundle.c
+++ /dev/null
@@ -1,131 +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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifdef ENABLE_TVM_ABORT_BACKTRACE
-#include "backtrace.h"
-#endif
-
-#define CRT_MEMORY_NUM_PAGES 16384
-#define CRT_MEMORY_PAGE_SIZE_LOG2 10
-
-static uint8_t g_crt_memory[CRT_MEMORY_NUM_PAGES * (1 << CRT_MEMORY_PAGE_SIZE_LOG2)];
-static MemoryManagerInterface* g_memory_manager;
-
-/*! \brief macro to do C API call */
-#define TVM_CCALL(func) \
- do { \
- int ret = (func); \
- if (ret != 0) { \
- fprintf(stderr, "%s: %d: error: %s\n", __FILE__, __LINE__, TVMGetLastError()); \
- exit(ret); \
- } \
- } while (0)
-
-TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
- const uint64_t params_size, const char* argv0) {
-#ifdef ENABLE_TVM_ABORT_BACKTRACE
- g_argv0 = argv0;
-#endif
-
- int64_t device_type = kDLCPU;
- int64_t device_id = 0;
-
- TVMByteArray params;
- params.data = params_data;
- params.size = params_size;
-
- DLDevice dev;
- dev.device_type = (DLDeviceType)device_type;
- dev.device_id = device_id;
-
- // declare pointers
- TVM_CCALL(PageMemoryManagerCreate(&g_memory_manager, g_crt_memory, sizeof(g_crt_memory),
- CRT_MEMORY_PAGE_SIZE_LOG2));
- TVM_CCALL(TVMInitializeRuntime());
- TVMPackedFunc pf;
- TVMArgs args = TVMArgs_Create(NULL, NULL, 0);
- TVM_CCALL(TVMPackedFunc_InitGlobalFunc(&pf, "runtime.SystemLib", &args));
- TVM_CCALL(TVMPackedFunc_Call(&pf));
-
- TVMModuleHandle mod_syslib = TVMArgs_AsModuleHandle(&pf.ret_value, 0);
-
- // run modules
- TVMGraphExecutor* graph_executor = NULL;
- TVM_CCALL(TVMGraphExecutor_Create(json_data, mod_syslib, &dev, &graph_executor));
- TVM_CCALL(TVMGraphExecutor_LoadParams(graph_executor, params.data, params.size));
-
- return graph_executor;
-}
-
-TVM_DLL void tvm_runtime_destroy(void* executor) {
- TVMGraphExecutor_Release((TVMGraphExecutor**)&executor);
-}
-
-TVM_DLL void tvm_runtime_set_input(void* executor, const char* name, DLTensor* tensor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_SetInput(graph_executor, name, tensor);
-}
-
-TVM_DLL void tvm_runtime_run(void* executor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_Run(graph_executor);
-}
-
-TVM_DLL void tvm_runtime_get_output(void* executor, int32_t index, DLTensor* tensor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_GetOutput(graph_executor, index, tensor);
-}
-
-void TVMLogf(const char* msg, ...) {
- va_list args;
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
-}
-
-void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t error_code) {
- fprintf(stderr, "TVMPlatformAbort: %d\n", error_code);
-#ifdef ENABLE_TVM_ABORT_BACKTRACE
- tvm_platform_abort_backtrace();
-#endif
- exit(-1);
-}
-
-tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr) {
- return g_memory_manager->Allocate(g_memory_manager, num_bytes, dev, out_ptr);
-}
-
-tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) {
- return g_memory_manager->Free(g_memory_manager, ptr, dev);
-}
-
-tvm_crt_error_t TVMPlatformTimerStart() { return kTvmErrorFunctionCallNotImplemented; }
-
-tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
- return kTvmErrorFunctionCallNotImplemented;
-}
diff --git a/apps/bundle_deploy/bundle.cc b/apps/bundle_deploy/bundle.cc
deleted file mode 100644
index 435d0e41f3db..000000000000
--- a/apps/bundle_deploy/bundle.cc
+++ /dev/null
@@ -1,64 +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
-#include
-
-#include
-
-#define TVM_BUNDLE_FUNCTION __attribute__((visibility("default")))
-
-extern "C" {
-
-TVM_BUNDLE_FUNCTION void* tvm_runtime_create(const char* build_graph_json,
- const char* build_params_bin,
- const uint64_t build_params_bin_len) {
- const int build_graph_json_len = strlen(build_graph_json);
- const std::string json_data(&build_graph_json[0], &build_graph_json[0] + build_graph_json_len);
- tvm::runtime::Module mod_syslib = (*tvm::runtime::Registry::Get("runtime.SystemLib"))();
- int device_type = kDLCPU;
- int device_id = 0;
-
- tvm::runtime::Module mod = (*tvm::runtime::Registry::Get("tvm.graph_executor.create"))(
- json_data, mod_syslib, device_type, device_id);
- TVMByteArray params;
- params.data = reinterpret_cast(&build_params_bin[0]);
- params.size = build_params_bin_len;
- mod.GetFunction("load_params")(params);
- return new tvm::runtime::Module(mod);
-}
-
-TVM_BUNDLE_FUNCTION void tvm_runtime_destroy(void* handle) {
- delete reinterpret_cast(handle);
-}
-
-TVM_BUNDLE_FUNCTION void tvm_runtime_set_input(void* handle, const char* name, void* tensor) {
- reinterpret_cast(handle)->GetFunction("set_input")(
- name, reinterpret_cast(tensor));
-}
-
-TVM_BUNDLE_FUNCTION void tvm_runtime_run(void* handle) {
- reinterpret_cast(handle)->GetFunction("run")();
-}
-
-TVM_BUNDLE_FUNCTION void tvm_runtime_get_output(void* handle, int index, void* tensor) {
- reinterpret_cast(handle)->GetFunction("get_output")(
- index, reinterpret_cast(tensor));
-}
-}
diff --git a/apps/bundle_deploy/bundle.h b/apps/bundle_deploy/bundle.h
deleted file mode 100644
index 0d7cab7d5a8d..000000000000
--- a/apps/bundle_deploy/bundle.h
+++ /dev/null
@@ -1,36 +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 TVM_APPS_BUNDLE_DEPLOY_BUNDLE_H_
-#define TVM_APPS_BUNDLE_DEPLOY_BUNDLE_H_
-
-#include
-
-TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
- const uint64_t params_size, const char* argv);
-
-TVM_DLL void tvm_runtime_destroy(void* runtime);
-
-TVM_DLL void tvm_runtime_set_input(void* runtime, const char* name, DLTensor* tensor);
-
-TVM_DLL void tvm_runtime_run(void* runtime);
-
-TVM_DLL void tvm_runtime_get_output(void* runtime, int32_t index, DLTensor* tensor);
-
-#endif /* TVM_APPS_BUNDLE_DEPLOY_BUNDLE_H_ */
diff --git a/apps/bundle_deploy/bundle_static.c b/apps/bundle_deploy/bundle_static.c
deleted file mode 100644
index 18a7b2bbb0ff..000000000000
--- a/apps/bundle_deploy/bundle_static.c
+++ /dev/null
@@ -1,132 +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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifdef ENABLE_TVM_PLATFORM_ABORT_BACKTRACE
-#include "backtrace.h"
-#endif
-#include "bundle.h"
-
-#define CRT_MEMORY_NUM_PAGES 16384
-#define CRT_MEMORY_PAGE_SIZE_LOG2 10
-
-static uint8_t g_crt_memory[CRT_MEMORY_NUM_PAGES * (1 << CRT_MEMORY_PAGE_SIZE_LOG2)];
-static MemoryManagerInterface* g_memory_manager;
-
-/*! \brief macro to do C API call */
-#define TVM_CCALL(func) \
- do { \
- tvm_crt_error_t ret = (func); \
- if (ret != kTvmErrorNoError) { \
- fprintf(stderr, "%s: %d: error: %s\n", __FILE__, __LINE__, TVMGetLastError()); \
- exit(ret); \
- } \
- } while (0)
-
-TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
- const uint64_t params_size, const char* argv0) {
-#ifdef ENABLE_TVM_PLATFORM_ABORT_BACKTRACE
- g_argv0 = argv0;
-#endif
- int64_t device_type = kDLCPU;
- int64_t device_id = 0;
-
- TVMByteArray params;
- params.data = params_data;
- params.size = params_size;
-
- DLDevice dev;
- dev.device_type = (DLDeviceType)device_type;
- dev.device_id = device_id;
-
- // get pointers
- TVM_CCALL(PageMemoryManagerCreate(&g_memory_manager, g_crt_memory, sizeof(g_crt_memory),
- CRT_MEMORY_PAGE_SIZE_LOG2));
- TVM_CCALL(TVMInitializeRuntime());
- TVMPackedFunc pf;
- TVMArgs args = TVMArgs_Create(NULL, NULL, 0);
- TVM_CCALL(TVMPackedFunc_InitGlobalFunc(&pf, "runtime.SystemLib", &args));
- TVM_CCALL(TVMPackedFunc_Call(&pf));
-
- TVMModuleHandle mod_syslib = TVMArgs_AsModuleHandle(&pf.ret_value, 0);
-
- // run modules
- TVMGraphExecutor* graph_executor = NULL;
- TVM_CCALL(TVMGraphExecutor_Create(json_data, mod_syslib, &dev, &graph_executor));
- TVM_CCALL(TVMGraphExecutor_LoadParams(graph_executor, params.data, params.size));
-
- return graph_executor;
-}
-
-TVM_DLL void tvm_runtime_destroy(void* executor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_Release(&graph_executor);
-}
-
-TVM_DLL void tvm_runtime_set_input(void* executor, const char* name, DLTensor* tensor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_SetInput(graph_executor, name, tensor);
-}
-
-TVM_DLL void tvm_runtime_run(void* executor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_Run(graph_executor);
-}
-
-TVM_DLL void tvm_runtime_get_output(void* executor, int32_t index, DLTensor* tensor) {
- TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)executor;
- TVMGraphExecutor_GetOutput(graph_executor, index, tensor);
-}
-
-void TVMLogf(const char* msg, ...) {
- va_list args;
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
-}
-
-void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t error_code) {
- fprintf(stderr, "TVMPlatformAbort: %d\n", error_code);
-#ifdef ENABLE_TVM_PLATFORM_ABORT_BACKTRACE
- tvm_platform_abort_backtrace();
-#endif
- exit(-1);
-}
-
-tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr) {
- return g_memory_manager->Allocate(g_memory_manager, num_bytes, dev, out_ptr);
-}
-
-tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) {
- return g_memory_manager->Free(g_memory_manager, ptr, dev);
-}
-
-tvm_crt_error_t TVMPlatformTimerStart() { return kTvmErrorFunctionCallNotImplemented; }
-
-tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
- return kTvmErrorFunctionCallNotImplemented;
-}
diff --git a/apps/bundle_deploy/demo.cc b/apps/bundle_deploy/demo.cc
deleted file mode 100644
index 09370385a683..000000000000
--- a/apps/bundle_deploy/demo.cc
+++ /dev/null
@@ -1,175 +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
-#include //dlopen
-#include
-#include
-
-#include
-#include
-#include
-
-template
-auto getFunc(void* bundle, const char* name) {
- dlerror();
- auto* f = reinterpret_cast::type>(dlsym(bundle, name));
- assert(!dlerror());
- return f;
-}
-
-static int read_all(const char* file_description, const char* file_path, char** out_params,
- size_t* params_size) {
- FILE* fp = fopen(file_path, "rb");
- if (fp == NULL) {
- return 2;
- }
-
- int error = 0;
- error = fseek(fp, 0, SEEK_END);
- if (error < 0) {
- return error;
- }
-
- long file_size = ftell(fp);
- if (file_size < 0) {
- return (int)file_size;
- } else if (file_size == 0 || file_size > (10 << 20)) { // file size should be in (0, 20MB].
- char buf[128];
- snprintf(buf, sizeof(buf), "determing file size: %s", file_path);
- perror(buf);
- return 2;
- }
-
- if (params_size != NULL) {
- *params_size = file_size;
- }
-
- error = fseek(fp, 0, SEEK_SET);
- if (error < 0) {
- return error;
- }
-
- *out_params = (char*)malloc((unsigned long)file_size);
- if (fread(*out_params, file_size, 1, fp) != 1) {
- free(*out_params);
- *out_params = NULL;
-
- char buf[128];
- snprintf(buf, sizeof(buf), "reading: %s", file_path);
- perror(buf);
- return 2;
- }
-
- error = fclose(fp);
- if (error != 0) {
- free(*out_params);
- *out_params = NULL;
- }
-
- return 0;
-}
-
-int main(int argc, char** argv) {
- assert(argc == 5 && "Usage: demo ");
- auto* bundle = dlopen(argv[1], RTLD_LAZY | RTLD_LOCAL);
- assert(bundle);
-
- char* json_data;
- int error = read_all("graph.json", argv[2], &json_data, NULL);
- if (error != 0) {
- return error;
- }
-
- char* params_data;
- size_t params_size;
- error = read_all("params.bin", argv[3], ¶ms_data, ¶ms_size);
- if (error != 0) {
- return error;
- }
-
- struct timeval t0, t1, t2, t3, t4, t5;
- gettimeofday(&t0, 0);
-
- auto* handle = getFunc(bundle, "tvm_runtime_create")(
- json_data, params_data, params_size);
- gettimeofday(&t1, 0);
-
- float input_storage[1 * 3 * 224 * 224];
- FILE* fp = fopen(argv[4], "rb");
- fread(input_storage, 3 * 224 * 224, 4, fp);
- fclose(fp);
-
- std::vector input_shape = {1, 3, 224, 224};
- DLTensor input;
- input.data = input_storage;
- input.device = DLDevice{kDLCPU, 0};
- input.ndim = 4;
- input.dtype = DLDataType{kDLFloat, 32, 1};
- input.shape = input_shape.data();
- input.strides = nullptr;
- input.byte_offset = 0;
-
- getFunc(bundle, "tvm_runtime_set_input")(handle, "data", &input);
- gettimeofday(&t2, 0);
-
- auto* ftvm_runtime_run = (auto(*)(void*)->void)dlsym(bundle, "tvm_runtime_run");
- assert(!dlerror());
- ftvm_runtime_run(handle);
- gettimeofday(&t3, 0);
-
- float output_storage[1000];
- std::vector output_shape = {1, 1000};
- DLTensor output;
- output.data = output_storage;
- output.device = DLDevice{kDLCPU, 0};
- output.ndim = 2;
- output.dtype = DLDataType{kDLFloat, 32, 1};
- output.shape = output_shape.data();
- output.strides = nullptr;
- output.byte_offset = 0;
-
- getFunc(bundle, "tvm_runtime_get_output")(handle, 0, &output);
- gettimeofday(&t4, 0);
-
- float max_iter = -std::numeric_limits::max();
- int32_t max_index = -1;
- for (auto i = 0; i < 1000; ++i) {
- if (output_storage[i] > max_iter) {
- max_iter = output_storage[i];
- max_index = i;
- }
- }
-
- getFunc(bundle, "tvm_runtime_destroy")(handle);
- gettimeofday(&t5, 0);
-
- printf("The maximum position in output vector is: %d, with max-value %f.\n", max_index, max_iter);
- printf(
- "timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
- "%.2f ms (get_output), %.2f ms (destroy)\n",
- (t1.tv_sec - t0.tv_sec) * 1000.0f + (t1.tv_usec - t0.tv_usec) / 1000.f,
- (t2.tv_sec - t1.tv_sec) * 1000.0f + (t2.tv_usec - t1.tv_usec) / 1000.f,
- (t3.tv_sec - t2.tv_sec) * 1000.0f + (t3.tv_usec - t2.tv_usec) / 1000.f,
- (t4.tv_sec - t3.tv_sec) * 1000.0f + (t4.tv_usec - t3.tv_usec) / 1000.f,
- (t5.tv_sec - t4.tv_sec) * 1000.0f + (t5.tv_usec - t4.tv_usec) / 1000.f);
- dlclose(bundle);
-
- return 0;
-}
diff --git a/apps/bundle_deploy/demo_static.c b/apps/bundle_deploy/demo_static.c
deleted file mode 100644
index a2fec6937311..000000000000
--- a/apps/bundle_deploy/demo_static.c
+++ /dev/null
@@ -1,112 +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
-#include
-#include
-#include
-#include
-#include
-
-#include "bundle.h"
-
-extern const char build_graph_c_json[];
-extern unsigned int build_graph_c_json_len;
-
-extern const char build_params_c_bin[];
-extern unsigned int build_params_c_bin_len;
-
-#define OUTPUT_LEN 1000
-
-int main(int argc, char** argv) {
- assert(argc == 2 && "Usage: demo_static ");
-
- char* json_data = (char*)(build_graph_c_json);
- char* params_data = (char*)(build_params_c_bin);
- uint64_t params_size = build_params_c_bin_len;
-
- struct timeval t0, t1, t2, t3, t4, t5;
- gettimeofday(&t0, 0);
-
- void* handle = tvm_runtime_create(json_data, params_data, params_size, argv[0]);
- gettimeofday(&t1, 0);
-
- float input_storage[1 * 3 * 224 * 224];
- FILE* fp = fopen(argv[1], "rb");
- (void)fread(input_storage, 3 * 224 * 224, 4, fp);
- fclose(fp);
-
- DLTensor input;
- input.data = input_storage;
- DLDevice dev = {kDLCPU, 0};
- input.device = dev;
- input.ndim = 4;
- DLDataType dtype = {kDLFloat, 32, 1};
- input.dtype = dtype;
- int64_t shape[4] = {1, 3, 224, 224};
- input.shape = shape;
- input.strides = NULL;
- input.byte_offset = 0;
-
- tvm_runtime_set_input(handle, "data", &input);
- gettimeofday(&t2, 0);
-
- tvm_runtime_run(handle);
- gettimeofday(&t3, 0);
-
- float output_storage[OUTPUT_LEN];
- DLTensor output;
- output.data = output_storage;
- DLDevice out_dev = {kDLCPU, 0};
- output.device = out_dev;
- output.ndim = 2;
- DLDataType out_dtype = {kDLFloat, 32, 1};
- output.dtype = out_dtype;
- int64_t out_shape[2] = {1, OUTPUT_LEN};
- output.shape = out_shape;
- output.strides = NULL;
- output.byte_offset = 0;
-
- tvm_runtime_get_output(handle, 0, &output);
- gettimeofday(&t4, 0);
-
- float max_iter = -FLT_MAX;
- int32_t max_index = -1;
- for (int i = 0; i < OUTPUT_LEN; ++i) {
- if (output_storage[i] > max_iter) {
- max_iter = output_storage[i];
- max_index = i;
- }
- }
-
- tvm_runtime_destroy(handle);
- gettimeofday(&t5, 0);
-
- printf("The maximum position in output vector is: %d, with max-value %f.\n", max_index, max_iter);
- printf(
- "timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
- "%.2f ms (get_output), %.2f ms (destroy)\n",
- (t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_usec - t0.tv_usec) / 1000.f,
- (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000.f,
- (t3.tv_sec - t2.tv_sec) * 1000 + (t3.tv_usec - t2.tv_usec) / 1000.f,
- (t4.tv_sec - t3.tv_sec) * 1000 + (t4.tv_usec - t3.tv_usec) / 1000.f,
- (t5.tv_sec - t4.tv_sec) * 1000 + (t5.tv_usec - t4.tv_usec) / 1000.f);
-
- return 0;
-}
diff --git a/apps/bundle_deploy/runtime.cc b/apps/bundle_deploy/runtime.cc
deleted file mode 100644
index e52a4796bb48..000000000000
--- a/apps/bundle_deploy/runtime.cc
+++ /dev/null
@@ -1,40 +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
-#include
-#include
-#include
-
-#include "../../src/runtime/c_runtime_api.cc"
-#include "../../src/runtime/container.cc"
-#include "../../src/runtime/cpu_device_api.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"
diff --git a/apps/bundle_deploy/test.cc b/apps/bundle_deploy/test.cc
deleted file mode 100644
index 25056f4d17a6..000000000000
--- a/apps/bundle_deploy/test.cc
+++ /dev/null
@@ -1,170 +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
-#include //dlopen
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-template
-auto getFunc(void* bundle, const char* name) {
- dlerror();
- auto* f = reinterpret_cast::type>(dlsym(bundle, name));
- assert(!dlerror());
- return f;
-}
-
-char* read_all_or_die(const char* name, const char* file_path, size_t* out_size) {
- struct stat st;
- if (stat(file_path, &st)) {
- char err[1024];
- snprintf(err, sizeof(err), "%s: statting file", name);
- perror(err);
- abort();
- }
- if (st.st_size > 1024 * 1024) {
- std::cerr << name << ": file is over 1MB limit: " << st.st_size << " bytes" << std::endl;
- abort();
- }
-
- if (out_size != nullptr) {
- *out_size = st.st_size;
- }
-
- char* data = (char*)malloc(st.st_size);
- FILE* fp = fopen(file_path, "rb");
- size_t bytes_to_read = st.st_size;
- size_t bytes_read = 0;
- while (bytes_read < bytes_to_read) {
- size_t this_round = fread(data, 1, st.st_size, fp);
- if (this_round == 0) {
- if (ferror(fp)) {
- char err[1024];
- snprintf(err, sizeof(err), "%s: error during read", name);
- perror(err);
- } else if (feof(fp)) {
- std::cerr << name << ": file is shorter than its stat size (" << bytes_read << " v "
- << st.st_size << ")" << std::endl;
- } else {
- std::cerr << name << ": fread stopped returning data" << std::endl;
- }
- abort();
- }
- bytes_read += this_round;
- }
-
- fclose(fp);
- return data;
-}
-
-int main(int argc, char** argv) {
- assert(argc == 6 && "Usage: test ");
- auto* bundle = dlopen(argv[1], RTLD_LAZY | RTLD_LOCAL);
- assert(bundle);
-
- char* json_data;
- char* params_data;
- size_t params_size;
-
- json_data = read_all_or_die("json_data", argv[4], nullptr);
- params_data = read_all_or_die("params_data", argv[5], ¶ms_size);
-
- struct timeval t0, t1, t2, t3, t4, t5;
- gettimeofday(&t0, 0);
-
- auto* handle = getFunc(bundle, "tvm_runtime_create")(
- json_data, params_data, params_size);
- gettimeofday(&t1, 0);
-
- size_t input_storage_size;
- float* input_storage =
- reinterpret_cast(read_all_or_die("input_storage", argv[2], &input_storage_size));
- size_t result_storage_size;
- float* result_storage =
- reinterpret_cast(read_all_or_die("result_storage", argv[3], &result_storage_size));
-
- size_t expected_size = 10 * 5 * sizeof(float);
- if (input_storage_size != expected_size || result_storage_size != expected_size) {
- std::cerr << "wrong input or result storage size (want " << expected_size
- << "input_storage_size=" << input_storage_size
- << "; result_storage_size=" << result_storage_size << std::endl;
- }
-
- std::vector input_shape = {10, 5};
- DLTensor input;
- input.data = input_storage;
- input.device = DLDevice{kDLCPU, 0};
- input.ndim = 2;
- input.dtype = DLDataType{kDLFloat, 32, 1};
- input.shape = input_shape.data();
- input.strides = nullptr;
- input.byte_offset = 0;
-
- getFunc(bundle, "tvm_runtime_set_input")(handle, "x", &input);
- gettimeofday(&t2, 0);
-
- auto* ftvm_runtime_run = (auto(*)(void*)->void)dlsym(bundle, "tvm_runtime_run");
- assert(!dlerror());
- ftvm_runtime_run(handle);
- gettimeofday(&t3, 0);
-
- float output_storage[10 * 5];
- std::vector output_shape = {10, 5};
- DLTensor output;
- output.data = output_storage;
- output.device = DLDevice{kDLCPU, 0};
- output.ndim = 2;
- output.dtype = DLDataType{kDLFloat, 32, 1};
- output.shape = output_shape.data();
- output.strides = nullptr;
- output.byte_offset = 0;
-
- getFunc(bundle, "tvm_runtime_get_output")(handle, 0, &output);
- gettimeofday(&t4, 0);
-
- for (auto i = 0; i < 10 * 5; ++i) {
- assert(fabs(output_storage[i] - result_storage[i]) < 1e-5f);
- if (fabs(output_storage[i] - result_storage[i]) >= 1e-5f) {
- printf("got %f, expected %f\n", output_storage[i], result_storage[i]);
- }
- }
-
- getFunc(bundle, "tvm_runtime_destroy")(handle);
- gettimeofday(&t5, 0);
-
- printf(
- "timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
- "%.2f ms (get_output), %.2f ms (destroy)\n",
- (t1.tv_sec - t0.tv_sec) * 1000.0f + (t1.tv_usec - t0.tv_usec) / 1000.f,
- (t2.tv_sec - t1.tv_sec) * 1000.0f + (t2.tv_usec - t1.tv_usec) / 1000.f,
- (t3.tv_sec - t2.tv_sec) * 1000.0f + (t3.tv_usec - t2.tv_usec) / 1000.f,
- (t4.tv_sec - t3.tv_sec) * 1000.0f + (t4.tv_usec - t3.tv_usec) / 1000.f,
- (t5.tv_sec - t4.tv_sec) * 1000.0f + (t5.tv_usec - t4.tv_usec) / 1000.f);
-
- free(json_data);
- free(params_data);
- dlclose(bundle);
-
- return 0;
-}
diff --git a/apps/bundle_deploy/test_static.c b/apps/bundle_deploy/test_static.c
deleted file mode 100644
index b9c980843ea1..000000000000
--- a/apps/bundle_deploy/test_static.c
+++ /dev/null
@@ -1,124 +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
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "bundle.h"
-
-int main(int argc, char** argv) {
- assert(argc == 5 && "Usage: test_static ");
-
- struct stat st;
- char* json_data;
- char* params_data;
- uint64_t params_size;
-
- FILE* fp = fopen(argv[3], "rb");
- stat(argv[3], &st);
- json_data = (char*)malloc(st.st_size);
- fread(json_data, st.st_size, 1, fp);
- fclose(fp);
-
- fp = fopen(argv[4], "rb");
- stat(argv[4], &st);
- params_data = (char*)malloc(st.st_size);
- fread(params_data, st.st_size, 1, fp);
- params_size = st.st_size;
- fclose(fp);
-
- struct timeval t0, t1, t2, t3, t4, t5;
- gettimeofday(&t0, 0);
-
- void* handle = tvm_runtime_create(json_data, params_data, params_size, argv[0]);
- gettimeofday(&t1, 0);
-
- float input_storage[10 * 5];
- fp = fopen(argv[1], "rb");
- fread(input_storage, 10 * 5, 4, fp);
- fclose(fp);
-
- float result_storage[10 * 5];
- fp = fopen(argv[2], "rb");
- fread(result_storage, 10 * 5, 4, fp);
- fclose(fp);
-
- DLTensor input;
- input.data = input_storage;
- DLDevice dev = {kDLCPU, 0};
- input.device = dev;
- input.ndim = 2;
- DLDataType dtype = {kDLFloat, 32, 1};
- input.dtype = dtype;
- int64_t shape[2] = {10, 5};
- input.shape = shape;
- input.strides = NULL;
- input.byte_offset = 0;
-
- tvm_runtime_set_input(handle, "x", &input);
- gettimeofday(&t2, 0);
-
- tvm_runtime_run(handle);
- gettimeofday(&t3, 0);
-
- float output_storage[10 * 5];
- DLTensor output;
- output.data = output_storage;
- DLDevice out_dev = {kDLCPU, 0};
- output.device = out_dev;
- output.ndim = 2;
- DLDataType out_dtype = {kDLFloat, 32, 1};
- output.dtype = out_dtype;
- int64_t out_shape[2] = {10, 5};
- output.shape = out_shape;
- output.strides = NULL;
- output.byte_offset = 0;
-
- tvm_runtime_get_output(handle, 0, &output);
- gettimeofday(&t4, 0);
-
- for (int i = 0; i < 10 * 5; ++i) {
- assert(fabs(output_storage[i] - result_storage[i]) < 1e-5f);
- if (fabs(output_storage[i] - result_storage[i]) >= 1e-5f) {
- printf("got %f, expected %f\n", output_storage[i], result_storage[i]);
- }
- }
-
- tvm_runtime_destroy(handle);
- gettimeofday(&t5, 0);
-
- printf(
- "timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
- "%.2f ms (get_output), %.2f ms (destroy)\n",
- (t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_usec - t0.tv_usec) / 1000.f,
- (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000.f,
- (t3.tv_sec - t2.tv_sec) * 1000 + (t3.tv_usec - t2.tv_usec) / 1000.f,
- (t4.tv_sec - t3.tv_sec) * 1000 + (t4.tv_usec - t3.tv_usec) / 1000.f,
- (t5.tv_sec - t4.tv_sec) * 1000 + (t5.tv_usec - t4.tv_usec) / 1000.f);
-
- free(json_data);
- free(params_data);
-
- return 0;
-}
diff --git a/apps/dso_plugin_module/.gitignore b/apps/dso_plugin_module/.gitignore
deleted file mode 100644
index a65b41774ad5..000000000000
--- a/apps/dso_plugin_module/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-lib
diff --git a/apps/dso_plugin_module/Makefile b/apps/dso_plugin_module/Makefile
deleted file mode 100644
index 6b4575032d7d..000000000000
--- a/apps/dso_plugin_module/Makefile
+++ /dev/null
@@ -1,34 +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.
-
-TVM_ROOT=$(shell cd ../..; pwd)
-PKG_CFLAGS = -std=c++17 -O2 -fPIC\
- -I${TVM_ROOT}/include\
- -I${TVM_ROOT}/3rdparty/dmlc-core/include\
- -I${TVM_ROOT}/3rdparty/dlpack/include\
- -DDMLC_USE_LOGGING_LIBRARY=\
-
-PKG_LDFLAGS =-L${TVM_ROOT}/build
-UNAME_S := $(shell uname -s)
-
-ifeq ($(UNAME_S), Darwin)
- PKG_LDFLAGS += -undefined dynamic_lookup
-endif
-
-lib/plugin_module.so: plugin_module.cc
- @mkdir -p $(@D)
- $(CXX) $(PKG_CFLAGS) -shared -o $@ $^ $(PKG_LDFLAGS)
diff --git a/apps/dso_plugin_module/README.md b/apps/dso_plugin_module/README.md
deleted file mode 100644
index 8dc9622d8ed4..000000000000
--- a/apps/dso_plugin_module/README.md
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Example Plugin Module
-=====================
-This folder contains an example that implements a C++ module
-that can be directly loaded as TVM's DSOModule (via tvm.runtime.load_module)
-
-## Guideline
-
-When possible, we always recommend exposing
-functions that modifies memory passed by the caller,
-and calls into the runtime API for memory allocations.
-
-## Advanced Usecases
-
-In advanced usecases, we do allow the plugin module to
-create and return managed objects.
-However, there are several restrictions to keep in mind:
-
-- If the module returns an object, we need to make sure
- that the object get destructed before the module get unloaded.
- Otherwise segfault can happen because of calling into an unloaded destructor.
-- If the module returns a PackedFunc, then
- we need to ensure that the libc of the DLL and tvm runtime matches.
- Otherwise segfault can happen due to incompatibility of std::function.
diff --git a/apps/dso_plugin_module/plugin_module.cc b/apps/dso_plugin_module/plugin_module.cc
deleted file mode 100644
index ae8e7d7817de..000000000000
--- a/apps/dso_plugin_module/plugin_module.cc
+++ /dev/null
@@ -1,68 +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.
- */
-/*!
- * \brief Example code that can be compiled and loaded by TVM runtime.
- * \file plugin_module.cc
- */
-#include
-#include
-#include
-#include
-
-namespace tvm_dso_plugin {
-
-using namespace tvm::runtime;
-
-class MyModuleNode : public ModuleNode {
- public:
- explicit MyModuleNode(int value) : value_(value) {}
-
- virtual const char* type_key() const final { return "MyModule"; }
-
- virtual PackedFunc GetFunction(const String& name, const ObjectPtr