-
Notifications
You must be signed in to change notification settings - Fork 734
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
using gsl with shared libcblas instead of javacpp's provided libgslblas #18
Comments
Glad to hear it's working well :) I'm not sure how they are making this work from C, but maybe it works the same from Java. Can you try to call something like |
No, this isn't going to work. I see that we need to relink the
And rebuild by calling BTW, are there any other C/C++ libraries that you would like to use or are using from Java? They might be good candidates to add to this project :) Thanks for the feedback |
Hi, thanks for the help. Regarding atlas, it is pointless to bundle it with the jar because the whole point of atlas is to build it and fine tune it for a specific processor architecture. I had to change plans and build my own java blas wrapper because gsl is gpl, so I am not allowed to mix it with Clojure libraries, which are usually EPL license. Ideas for native libraries? I tend to think that cblas and lapacke would be good candidates, since Java still sucks at number crunching. Still, I am very impressed by javacpp - excellent performance :) |
I see, thanks for the feedback! BTW, we could easily wrap CBLAS and LAPACK with JavaCPP: |
Oh wait, you need to use When we're after performance, we should be using direct NIO buffers. Those are as fast as arrays inside both Java and in native code with JNI, and are well supported by the JDK in general. |
I use the critical version on all arrays. It MIGHT return a copy, but in my (preliminary and simple, but run millions of times) tests it never did. On the other hand, the non-critical version always returned a copy. I heard different kinds of stories about critical vs. buffer. Only anecdotal, without an example or demonstration, and without the any link to detailed discussion. I cannot find any part in the docs where critical call is not recommended or discouraged. There are only constraints, which are fine for my use case. fommil (netlib-java), who has similar use case, also uses critical calls for the project, and he did not have any problems. I am still quite open to NIO, but that also have drawbacks - unnatural API. Instead of methods that take arrays, there would be bytebuffers all the way. I am puzzled by another thing. In all java libs that I tried, even the simplest JNI call with primitive arguments took several time longer than a simple calculation JNI hello world. For example, javacpp-gsl call to logarithm function took, if I remember well, 25 ns (measured by the criterium library). The call to hello takes 8 ns. Where do 17 ns go? Even java's Math.log takes 2 ns or so, so I expect gsl log to be similar. I understand that nanoseconds are not that important for the majority of software, but for the building blocks of numerical code that is a considerable waste that multiplies quickly ;) |
In the link above they say "After calling There are a few places where the overhead might come from. In this case, I think the largest overhead would come from checking for C++ exceptions, but we'd have to check the generated code to make sure. We can disable checking for C++ exceptions with the |
One source for the complexity might be that autogen libraries try to cover C++, which is very complex, and they have to deal with many edge cases, whereas when I choose plain C there are less of those things to consider, and also I can choose what applies in my use case. |
Of course if you know exactly what you're doing, it's better to code everything in C, and a bit of JNI isn't going to change a whole lot. But the point of developing with Java is usually because we don't know exactly what we're doing. We build prototypes, try stuff out, debug the hell out of everything, etc, and the better the tools we have for those tasks, the more time we can spend on the essential. For example, let's assume that we need to call the logarithm function on only one scalar very often. With the Java wrappers, we could start experimenting with that, and make sure that our algorithm works well. Then, when we know that everything is fine, but that it has become the bottleneck of our application, we make a new function in C/C++, and call that function from Java. And JavaCPP can still help here in calling that new function by abstracting the differences between platforms, and by maintaining compatibility with the rest of the native functions without effort. |
It's been a while, but with the commit above, presets for GSL now link automatically with OpenBLAS, MKL, Accelerate, etc instead of GSL CBLAS, and they do not try to catch C++ exceptions anymore, so they should be pretty much as fast as manually written JNI wrapper code. |
Hi, thank you for this fantastic project. I imported the library, an it works.
I would like to use atlas blas implementation for the blas part of gsl. In c, that would mean changing the make file to link libcblas and/or atlas instead of libgslblas. However, javacpp provides the prepackaged build that ignores system's files and uses the one provided in a platform jar.
Is there a way to specify which (shared) libraries to use instead of the ones provided inside jars?
If I'd have to build javacpp's gsl manually, where should i change the libcblas setting?
The text was updated successfully, but these errors were encountered: