Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

MKL and Java

brownm_uk
Beginner
879 Views
I'm wondering if anyone has tried using MKL from Java JNI. This might seem a foolish thing to want to do but I can't seem to find an established numerical library for Java.
If you have tried this I'd be interested in hearing your experiences.
Thanks in advance,
Martin Brown
0 Kudos
9 Replies
mouna_hammami
Beginner
879 Views
hi, well Im looking to the same thing. I want to integrate MKL in my java program.
Is it possible??
0 Kudos
Yevgeny_Latkin__Inte
879 Views

Hello Martin and Mouna,

Your questions sound interesting; they encouraged me to try invoking couple of MKL functions from Java environment.

I have written JNI stubs for few functions from the MKL 8.0 convolution software, and a simple Java program to test these functions. The test works fine for me. I tried the test at Windows/IA32 environment. I used Microsoft Visual Studio 6.0 for compiling the stubs; and Sun JDK 1.5 for compiling the Java codes and running the test. I tried both static and dynamic MKL libraries.

If you would like to, we could discuss your questions in more details. Particularly, I could review examples of your code if you would share them at the forum.

Please note however, that for my best knowledge, MKL 8.0 is not tested for interoperability with Java environment. Indeed, one may try invoking MKL functions from Java programs on his/her own risk.

Yevgeny Latkin (Intel Employee)

0 Kudos
sj777
Beginner
879 Views
hi Ylatkin,
I'm very interested in the performance you get using this stubs. I never have used JNI so I'm worried about the cost of this interface.. if using jni will make me losto all the advanteges of using mkl I will not even try to use mkl form java code.
Thanks,
Dimitri
0 Kudos
Yevgeny_Latkin__Inte
879 Views

Dmitri,

Thank you for very interesting question! I made a brief performance experiment with the stubs using my laptop. At this first glance, performance loss is 1.6-2.3 times depending on test parameters.

Such loss may look disapointing, or it may look acceptable; the decision depends on your goals. Please note, that you may get different performance results as an overhead of using JNI depends on the particular situation. I guess I could see better results if I tried optimizing my stubs. And overhead of using JNI might be less important if a slower function were called.

FYI few more details: I tried Fourier method of 1-dimensional linear convolution over single-precision data. A large sequence (1 million elements) was convolved with a series of shorter sequences (100 to 10000 elements). Performance loss of using JNI for 100-elements sequence was about 2.3 times, loss for 1000-elements sequence was about 1.8 times, and loss for 10000-elements was 1.6 times.

Sincerely,

Yevgeny Latkin (Intel employee)

0 Kudos
sj777
Beginner
879 Views
thanks Yevgeny,
your answer let me have an idea of the problem, do you know if there is some other resource on java and mkl? I've build a nn system for robotics in the last 3 months, and I had to use java, i had written about 130 classes btw gui control and model.. now i'd like to port optimize the model, becouse i've already used all my tricks to optimize java..
However thanks again
0 Kudos
Yevgeny_Latkin__Inte
879 Views

Dmitri,

I still believe that using MKL for Java applications could be profitable in many cases.

Right now I don't have a Java implementation of the Fast Fourier Transform, so I tried the direct method for the same experiment. Despite of the overhead for the JNI stubs, combination of Java plus MKL is much (few times!) faster than pure Java for my experiments.

Though, JNI loss isn't as important for the direct method: the degradation to pure native MKL is only 5-20% for most lengths of a shorter sequence.

Sincerely,

Yevgeny Latkin (Intel employee)

0 Kudos
sj777
Beginner
879 Views
thanks Yevgeny
ok i'll do my test and if their results sutisfy me i'll start an open source project with some friend or coworker.. If you have any suggestion or if you can supply official or personal support I'll be very gratefull
Regards
Dimitri Ognibene
ISTC-CNR Research Assistant
0 Kudos
Yevgeny_Latkin__Inte
879 Views

Dmitri,

As for my contribution to your project, I cannot make such commitment at this moment. But please do not hesitate to write to this forum if you have questions.

Anyway, please let me know if you start the project. Using a high-performance math library like MKL for speeding up a Java application looks an interesting approach.

Thanks,

Yevgeny Latkin

0 Kudos
Intel_C_Intel
Employee
879 Views

MKL 9.1 has some examples for the use of MKL in Java code.

Bruce

0 Kudos
Reply