Re: "Generator Outputs native JNI code in C++ (.cpp, .cu, .mm, etc)"

90 views
Skip to first unread message

Samuel Audet

unread,
May 29, 2020, 10:45:34 AM5/29/20
to Beixing Yin, javacpp
You'll need to install CUDA on your system. NVIDIA doesn't offer a way to install it locally.
For Linux, we can use the nvidia/cuda:10.2-cudnn7-devel-centos7 docker image as per the builds on Travis CI:

You can find more information about how JavaCPP works on these pages:

Let me know if there is anything unclear!

On 5/29/20 8:24 PM, Beixing Yin wrote:
Hi Samuel,


However, within the CentOS7 container I found cuda has build failure. I attached the complete build log for your reference.

And could you please add some example file to explain what's the input and output files of "The Builder --> 3.Generator", https://github.com/bytedeco/javacpp/wiki/Basic-Architecture. I was trying to find "Outputs native JNI code in C++ (.cpp, .cu, .mm, etc)" but couldn't find any generated code after build one of the javacpp-presets, such as opencv. Does the generator output file contain code like below?

JNIEXPORT jlong JNICALL Java_come_xxx_Cuda_cudaMallocHost(JNIEnv *env, jclass, jlong size) {
try {
cudf::jni::auto_set_device(env);
void * ret = nullptr;
JNI_CUDA_TRY(env, 0, cudaMallocHost(&ret, size));
return reinterpret_cast<jlong>(ret);
} CATCH_STD(env, 0);
}

And cudaMallocHost is the C++ function name read from C++ header files hence will match that in the binary .so, right?

Thanks,
Yin


Samuel Audet

unread,
May 30, 2020, 11:02:52 PM5/30/20
to Beixing Yin, javacpp
The docker command is just an example of what we can do. The presets themselves use the original versioned directory name for CUDA:

As to what JavaCPP does exactly, please study the output of the following simple examples:

I think it's pretty clear what it does, but if there are still things you don't understand after that, let me know.

On 5/30/20 3:04 AM, Beixing Yin wrote:
Hi Samuel,

I do have CUDA 10.2 installed on my host, and because I used your command to launch the CentOS 7 container which has volume mount to the cuda directory in host. And I checked the cuda.h does exist. But the build failure message is cannot find cuda.h.

$ sudo docker run --privileged -it -v /usr/local/lib/bazel:/usr/local/lib/bazel -v /usr/local/cuda:/usr/local/cuda centos:7 /bin/bash


I did read these two docs before, but seems they're about how JavaCpp Parser convert C++ header files .h to .java file(definition in C++ to definition in Java with native keyword, which is the part I understand). The question I was trying to ask is after this, JavaCpp Generator will convert the .java definition file to "native JNI code in C++ (.cpp, .cu, .mm, etc)". The unclear thing is what are these "native JNI code in C++ (.cpp, .cu, .mm, etc)" in JavaCpp. Are they the medium C++ layer that route into the existing C++ binary or they're the self complete new implementation?

Namely, please allow me to comment my questions on the doc to make it easier to express:

  1. Runs optional external build scripts, such as cppbuild.sh from the JavaCPP Presets,
    • Outputs native libraries (.so, .dylib, .dll, etc), <Yin>At this step, are output native libraries the original libs that has nothing to do with JavaCpp yet, or the libs built from injected/modified source code somehow manipulated by the cppbuild.sh?</Yin>
  2. Runs the Parser on the given InfoMap and the header files listed in the @Platform annotation,
    • Outputs native Java interfaces (.java), as explained further in the Mapping Recipes, <Yin>Is this Java methods definitions(no any implementation) with native keyword? Are they the file under gen directory in existing presets?</Yin>
  3. Runs the Generator on the Java interfaces,
    • Outputs native JNI code in C++ (.cpp, .cu, .mm, etc), <Yin>Are they the medium C++ layer that route into the existing C++ binary or they're the self complete new entire implementation? I am asking because I see it could be cuda kernel source code which should be the native implementation</Yin>
  4. Runs the native C++ compiler (GCC, Clang, MSVC, NVCC, etc) on the JNI code,
    • Outputs native libraries containing JNI wrappers, optionally archived in a JAR file. <Yin>What does this "JNI wrappers" refer to?</Yin>
Thank you so much for reading it,
Yin
Reply all
Reply to author
Forward
0 new messages