-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
@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:
|
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 |
cc @yzhliu |
f65b51f
to
748cf63
Compare
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"
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. |
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 |
Android Standalone demo application tutorial updated. |
@yzhliu can you review this? |
@PariksheetPinjari909 Thanks |
docs/how_to/deploy_android.md
Outdated
fo.write(graph.json()) | ||
with open("YOLOv2_tiny-aarch64.params", "wb") as fo: | ||
fo.write(nnvm.compiler.save_param_dict(params)) | ||
``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/how_to/deploy_android.md
Outdated
|
||
|
||
Prerequisites: | ||
Android stand alone tool chain : ANDROID_NDK_PATH/ndk/android-toolchain-arm64/bin/aarch64-linux-android- |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
docs/how_to/deploy_android.md
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo 'setp'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/how_to/deploy_android.md
Outdated
- 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOPENCL -> OPENCL
docs/how_to/deploy_android.md
Outdated
└── libOpenCL.so | ||
``` | ||
|
||
- Enable OPENCL in make/config.mk |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); | ||
``` |
There was a problem hiding this comment.
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 @@ | |||
/*! |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo 'Initlalize'
@janboeye yes the procedure is same for one layer too. |
1a9fa69
to
5f8e5f8
Compare
@PariksheetPinjari909 Thanks for the changes, let us move |
#include "../src/runtime/file_util.cc" | ||
#include "../src/runtime/dso_module.cc" | ||
#include "../src/runtime/thread_pool.cc" | ||
|
There was a problem hiding this comment.
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
docs/how_to/deploy_android.md
Outdated
|
||
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). |
There was a problem hiding this comment.
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
@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. |
There was a problem hiding this 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
Thanks for the patient during the reviewing process and keep improving the PR, this is now merged |
For #973