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

[android_deploy] CRASH caused by Module.load func while running App on Android Device with #4884

Closed
KindleHe opened this issue Feb 14, 2020 · 4 comments

Comments

@KindleHe
Copy link

I install the apk in vivo X6S A, according to the Android TVM Demo

vivo X6S A is arm64-v8a with android-22, so I modify config.mk as following:

APP_ABI = arm64-v8a

APP_PLATFORM = android-22

# whether enable OpenCL during compile
USE_OPENCL = 0

# 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 =

However, I run app in device, the app crash immediately, so I add some lines for debug:

Log.i(TAG, "libCacheFilePath=" + libCacheFilePath);
Module modelLib = Module.load(libCacheFilePath);
Log.i(TAG, "Finish Module.load");

Then, I use adb logcat -b main -v time>app.log command to capture crash on android device machine to get the following log file
app.log
Here is some important information of app.log

02-14 23:38:51.469 I/MainActivity(28024): libCacheFilePath=/data/data/org.apache.tvm.android.demo/cache/tvm4j_demo_-856121318/deploy_lib_cpu.so
02-14 23:38:51.469 W/System.err(28024): Try loading tvm4j from native path.
02-14 23:38:51.469 W/System.err(28024): Try loading tvm4j-linux-x86_64 from native path.
02-14 23:38:51.469 W/System.err(28024): [WARN] TVM native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH), or specifying by Java cmd option -Djava.library.path=[lib path].
02-14 23:38:51.469 W/System.err(28024): Attempting to load libtvm4j.so
02-14 23:38:51.469 W/System.err(28024): [WARN] Couldn't find native library tvm4j.
02-14 23:38:51.469 W/System.err(28024): java.lang.UnsatisfiedLinkError: Couldn't find the resource libtvm4j.so
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.NativeLibraryLoader.extractResourceFileToTempDir(NativeLibraryLoader.java:127)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:87)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Base.<clinit>(Base.java:73)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Function.listGlobalFuncNames(Function.java:52)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Function.getFunction(Function.java:38)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Module.getApi(Module.java:41)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Module.load(Module.java:140)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.Module.load(Module.java:146)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.android.demo.MainActivity$LoadModleAsyncTask.doInBackground(MainActivity.java:186)
02-14 23:38:51.469 W/System.err(28024):         at org.apache.tvm.android.demo.MainActivity$LoadModleAsyncTask.doInBackground(MainActivity.java:124)
02-14 23:38:51.469 W/System.err(28024):         at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-14 23:38:51.469 W/System.err(28024):         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-14 23:38:51.469 W/System.err(28024):         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-14 23:38:51.469 W/System.err(28024):         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-14 23:38:51.469 W/System.err(28024):         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-14 23:38:51.469 W/System.err(28024):         at java.lang.Thread.run(Thread.java:818)
02-14 23:38:51.469 W/System.err(28024): Try to load tvm4j (runtime packed version) ...
02-14 23:38:51.469 W/linker  (28024): /data/app/org.apache.tvm.android.demo-1/lib/arm64/libtvm4j_runtime_packed.so: unused DT entry: type 0x6ffffef5 arg 0x54f0
02-14 23:38:51.469 W/linker  (28024): /data/app/org.apache.tvm.android.demo-1/lib/arm64/libtvm4j_runtime_packed.so: unused DT entry: type 0x6ffffffe arg 0x514d8
02-14 23:38:51.469 W/linker  (28024): /data/app/org.apache.tvm.android.demo-1/lib/arm64/libtvm4j_runtime_packed.so: unused DT entry: type 0x6fffffff arg 0x2
02-14 23:38:51.479 W/System.err(28024): libtvm4j loads successfully.
02-14 23:38:51.479 E/AndroidRuntime(28024): FATAL EXCEPTION: AsyncTask #1
02-14 23:38:51.479 E/AndroidRuntime(28024): Process: org.apache.tvm.android.demo, PID: 28024
02-14 23:38:51.479 E/AndroidRuntime(28024): java.lang.RuntimeException: An error occured while executing doInBackground()
02-14 23:38:51.479 E/AndroidRuntime(28024):     at android.os.AsyncTask$3.done(AsyncTask.java:304)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.lang.Thread.run(Thread.java:818)
02-14 23:38:51.479 E/AndroidRuntime(28024): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.apache.tvm.Function org.apache.tvm.Function.pushArg(java.lang.String)' on a null object reference
02-14 23:38:51.479 E/AndroidRuntime(28024):     at org.apache.tvm.Module.load(Module.java:140)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at org.apache.tvm.Module.load(Module.java:146)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at org.apache.tvm.android.demo.MainActivity$LoadModleAsyncTask.doInBackground(MainActivity.java:186)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at org.apache.tvm.android.demo.MainActivity$LoadModleAsyncTask.doInBackground(MainActivity.java:124)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-14 23:38:51.479 E/AndroidRuntime(28024):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)

As you can see, libCacheFilePath occurs while Finish Module.load not, which means that Module modelLib = Module.load(libCacheFilePath); failed. Meanwhile, the app.log says Caused by: java.lang.NullPointerException.

So, I locate the crash is caused by Module.load func or libCacheFilePath, however libCacheFilePath=/data/data/org.apache.tvm.android.demo/cache/tvm4j_demo_-856121318/deploy_lib_cpu.so, and I find deploy_lib_cpu.so indeed exist in

➜  app git:(dev/kindlehe/walk-through) ✗ find ./ -name deploy_lib_cpu.so
.//build/intermediates/merged_assets/release/out/deploy_lib_cpu.so
.//build/intermediates/merged_assets/debug/out/deploy_lib_cpu.so
.//build/intermediates/assets/release/deploy_lib_cpu.so
.//build/intermediates/assets/debug/deploy_lib_cpu.so
.//src/main/assets/deploy_lib_cpu.so

Finally, I conclude the crash is caused by Module.load func.

But, I don' t know how to sovle the crash problem, begging for your kind-hearted help sincerely!

@KindleHe KindleHe changed the title [android_deploy] crash is caused by Module.load func while running App on Android Device with [android_deploy] CRASH caused by Module.load func while running App on Android Device with Feb 14, 2020
@tqchen
Copy link
Member

tqchen commented Feb 14, 2020

Can you see if #4871 resolved your problem, please make sure to rebuild the native app along with the java source

@KindleHe
Copy link
Author

KindleHe commented Feb 17, 2020

Thanks for your quick reply!

As you said in [REFACTOR][PY][API-Change] Polish tvm.runtime, tvm.runtime.module API update

API changes wrt to runtime.Module
tvm.module.load -> tvm.runtime.load_module
tvm.module.enabled -> tvm.runtime.enabled
tvm.module.system_lib -> tvm.runtime.system_lib

However, the tvm.module related codes did not change yet, even I keep my dev branch the same with newest master branch.
in src/main/java/org/apache/tvm/android/demo/MainActivity.java

Module modelLib = Module.load(libCacheFilePath);

Finally, I get the same crash error ,and I m not sure what's the problem?
Could you offer me some further help?

Can you see if #4871 resolved your problem, please make sure to rebuild the native app along with the java source

@KindleHe
Copy link
Author

@tqchen Yes! I find the answer finally! Your answer is right!

TVM4J is Java Frontend for TVM Runtime, and the CRASH occurs at calling Module.load func.

As #4871 said, runtime PackedFunc is changed at this commit. Namely, the corresponding Java interface for TVM runtime changed.

So, even I synced my branch with remote master newest branch and rebuild the android apk, I get the same CRASH due to I forget to rebuild TVM4J to get a new java interface after #4871.

The key is rebuild TVM4J before rebuild the android apk

I am glad to learn more about Java as a Java newcomer and thanks for your kind help very much!

Thanks for your quick reply!

As you said in [REFACTOR][PY][API-Change] Polish tvm.runtime, tvm.runtime.module API update

API changes wrt to runtime.Module
tvm.module.load -> tvm.runtime.load_module
tvm.module.enabled -> tvm.runtime.enabled
tvm.module.system_lib -> tvm.runtime.system_lib

However, the tvm.module related codes did not change yet, even I keep my dev branch the same with newest master branch.
in src/main/java/org/apache/tvm/android/demo/MainActivity.java

Module modelLib = Module.load(libCacheFilePath);

Finally, I get the same crash error ,and I m not sure what's the problem?
Could you offer me some further help?

Can you see if #4871 resolved your problem, please make sure to rebuild the native app along with the java source

@tqchen
Copy link
Member

tqchen commented Feb 17, 2020

Glad that the problem is resolved. For future trouble shooting questions, you are more than welcomed to open new threads on https://discuss.tvm.ai/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants