Skip to content

Commit

Permalink
Amalgamation JNI bug for Java/Android prediction (apache#5109)
Browse files Browse the repository at this point in the history
* corrected an indexing bug in amalgamation/jni/predictor.cc
the bug results in a wrong shape inference

* added jni/predictor.cc as a dependent file for jni_libmxnet_predict.o
  • Loading branch information
freddycct authored and piiswrong committed Feb 24, 2017
1 parent 8294809 commit 38a33ef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ List of Contributors
* [Xu Dong](https://github.com/dsqx71)
* [Chihiro Komaki](https://github.com/ckomaki)
* [Piyush Singh](https://github.com/Piyush3dB)
* [Freddy Chua](https://github.com/freddycct)
2 changes: 1 addition & 1 deletion amalgamation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mxnet_predict-all.o: mxnet_predict-all.cc
libmxnet_predict.a: mxnet_predict-all.o
ar rcs libmxnet_predict.a $+

jni_libmxnet_predict.o: mxnet_predict-all.cc
jni_libmxnet_predict.o: mxnet_predict-all.cc jni/predictor.cc
${CXX} ${CFLAGS} -fPIC -o $@ -c jni/predictor.cc

jni_libmxnet_predict.so: jni_libmxnet_predict.o
Expand Down
7 changes: 5 additions & 2 deletions amalgamation/jni/predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ JNIEXPORT jlong JNICALL Java_org_dmlc_mxnet_Predictor_createPredictor
track.emplace_back(js, s);
}

std::vector<mx_uint> index{0};
std::vector<mx_uint> index;
std::vector<mx_uint> shapes;
mx_uint prev = 0;
index.emplace_back(prev);
for (int i=0; i<env->GetArrayLength(jshapes); i++) {
jintArray jshape = (jintArray) env->GetObjectArrayElement(jshapes, i);
jsize shape_len = env->GetArrayLength(jshape);
jint *shape = env->GetIntArrayElements(jshape, 0);

index.emplace_back(shape_len);
prev += shape_len;
index.emplace_back(prev);
for (int j=0; j<shape_len; ++j) shapes.emplace_back((mx_uint)shape[j]);
env->ReleaseIntArrayElements(jshape, shape, 0);
}
Expand Down

0 comments on commit 38a33ef

Please sign in to comment.