Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Linux/Android native deploy #980

Merged
merged 9 commits into from
Mar 29, 2018
Merged

Conversation

PariksheetPinjari909
Copy link
Contributor

For #973

@tqchen
Copy link
Member

tqchen commented Mar 9, 2018

@PariksheetPinjari909 this example uses the C API and requires JNI. Can you build a version that uses the java API instead of JNI? The Fix for thread runtime is useful and we can bring that in first in a separate PR. Thanks!

Specifically, we can:

  • Build a library.so with export_library
  • Build TVM java runtime without RPC support
  • Use TVM java runtime to run the prediction in java

@tqchen
Copy link
Member

tqchen commented Mar 9, 2018

The native JNI deployment can also be helpful, but it would be great to show a java API example, since that is much easier for the users. Also if we are only running prediction example, we don't need to have extra library to save arrays, simply print out the class id and possible class would do for a demo app

@tqchen
Copy link
Member

tqchen commented Mar 9, 2018

cc @yzhliu

@PariksheetPinjari909 PariksheetPinjari909 changed the title Linux/Android native deploy [WIP] Linux/Android native deploy Mar 10, 2018
@PariksheetPinjari909
Copy link
Contributor Author

Ref: "Talk about how to use the java API": Yes, build with JAVA makes it much easier than JNI for android app developers. Working in it

Ref: " we don't need to have extra library to save arrays, simply print out the class id and possible class would do for a demo app"

  • NPY format for in & out was with an intention of developers first try with Python for initial experiments on X86 then bring it to target.
  • Input varies like direct JPEG stream, decoded Tensor (resized, converted to YUV domain ...etc.)

So to keep the deploy tool generic I preferred npy format. NPY format dump is a single addition to initial python script to dump input and to feed model output back for processing after prediction.

@tqchen
Copy link
Member

tqchen commented Mar 10, 2018

Usually, app developer wants something that is more stand alone. Like take an image and how could I feed it to the app. We can build an example app that takes an image(from camera or file) do a preprocessing and feed it to java runtime. See https://github.com/dmlc/nnvm/blob/master/tutorials/web/resnet.html#L80 for a javascript version of preprocessing

@PariksheetPinjari909
Copy link
Contributor Author

Android Standalone demo application tutorial updated.

@tqchen
Copy link
Member

tqchen commented Mar 20, 2018

@yzhliu can you review this?

@janboeye
Copy link

@PariksheetPinjari909
How to native deploy tvm.build for just one layer? Is it same?

Thanks

fo.write(graph.json())
with open("YOLOv2_tiny-aarch64.params", "wb") as fo:
fo.write(nnvm.compiler.save_param_dict(params))
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use 4-space indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.



Prerequisites:
Android stand alone tool chain : ANDROID_NDK_PATH/ndk/android-toolchain-arm64/bin/aarch64-linux-android-
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path looks incomplete? Moreover, I think users need extra steps to generate the standalone toolchains from NDK, e.g., by $ANDROID_NDK_PATH/build/tools/ ./make-standalone-toolchain.sh ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path is complete only, it's tool chain prefix reference.

About standalone tool chain building: I think it's out of scope for current context. Any way I added android URL reference to build it.

OPENCL_PATH=<path to OOPENCL path> CXX=<ANDROID_NDK_PATH>/ndk/android-toolchain-arm64/bin/aarch64-linux-android-g++ make lib/libtvm_runtime.so
```

Result of this setp is the libtvm_runtime.so which is a dependency for Android native while building application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo 'setp'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

- Below command can build libtvm_runtime.so for android.

```
OPENCL_PATH=<path to OOPENCL path> CXX=<ANDROID_NDK_PATH>/ndk/android-toolchain-arm64/bin/aarch64-linux-android-g++ make lib/libtvm_runtime.so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOPENCL -> OPENCL

└── libOpenCL.so
```

- Enable OPENCL in make/config.mk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remind users to make sure whether the libOpenCL.so is compatible with their devices?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added required explanation for this.

```
// create tvm context
TVMContext tvmCtx = TVMContext.opencl();
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```java

@@ -0,0 +1,62 @@
/*!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about README.md instead of .txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

uint64_t num_samples=1;
TVMArrayAlloc(in_shape, in_ndim, dtype_code, dtype_bits, dtype_lanes, kDLCPU, device_id, &x);

// Initlalize the Input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo 'Initlalize'

@PariksheetPinjari909
Copy link
Contributor Author

@janboeye yes the procedure is same for one layer too.

@tqchen
Copy link
Member

tqchen commented Mar 27, 2018

@PariksheetPinjari909 Thanks for the changes, let us move tutorials/deployment/android -> apps/android_deploy
because this is less like a conventional tutorial, but more of an example app

#include "../src/runtime/file_util.cc"
#include "../src/runtime/dso_module.cc"
#include "../src/runtime/thread_pool.cc"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #include "../src/runtime/thread_backend.cc" Please rebase against the master and test the workflow


1: Build a model for android target.
2: TVM runtime building for android target.
3: A sample native application to test the model on ADB before integrating into android application (apk).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should first refer to the apps/deploy_android on how to use java API, the native API comes second

@tqchen
Copy link
Member

tqchen commented Mar 28, 2018

@PariksheetPinjari909 Let us remove the native deployment tutorial for now as it is in largely duplicates with the apps/how_to_deploy. Focusing on the java api example and make it clear and good is useful for most users

We can still keep a section on what is needed to be done if user prefers JNI and refers most of example code to apps/how_to_deploy.

Copy link
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the changes, let us remove the native example for now and focus on making the java example clear and useful

@tqchen tqchen merged commit 043ed4b into apache:master Mar 29, 2018
@tqchen
Copy link
Member

tqchen commented Mar 29, 2018

Thanks for the patient during the reviewing process and keep improving the PR, this is now merged

tqchen pushed a commit to tqchen/tvm that referenced this pull request Jul 6, 2018
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants