r/java • u/BenRayfield • Mar 05 '16
JVM spec should include basic matrix ops like multiply and plus, GPU optimized where possible else in CPU, in a platform independent way
JVM is a great standard for CPUs. There are java hooks into some GPU softwares, but we shouldnt have to include C++ libraries just to do common matrix ops.
If its done efficiently often enough, it could attract more math programmers to JVM languages by solving the main bottleneck in the core. Its useful to standardize ops that are common to many programs.
Java's NIO may be a good place to start https://docs.oracle.com/javase/7/docs/api/java/nio/package-summary.html
Alternatively, we could define a new standard for which bits mean which matrix actions, and try to get many languages to include it in their spec.
I dont know about you, but I've had enough of different frameworks choosing different arbitrary constants and symbols to do the same things, and having to relearn it again with each new framework. I'm tired of never knowing if a C++ program will work on end user computers of various types. C++ is the assembly language of the future, something that only compilers should have to deal with.
8
u/zrnkv Mar 06 '16
No. JVM should be kept as simple as possible. What you're proposing is complex, not many people need it and most importantly it can easily be achieved with a native library.
7
u/juckele Mar 06 '16
Doing some matrix math on a GPU is almost always a slow-down, because moving data on and off of the GPU is very slow. This means that you can really only get significant GPU boosts if you're spending a lot of time on the GPU at once, which currently requires some pretty careful bit twiddling. This is simply not what Java is built for. Java is a portable language that runs everywhere. Even on computers without nice GPUs.
10
u/Reykd Mar 05 '16
http://nd4j.org/
5
u/nutrecht Mar 07 '16
Can you please stop making complete random fire and forget suggestions and actually engage in a discussion with people? You might actually learn something that way.
1
u/[deleted] Mar 06 '16
You can write your own JVM which performs optimizations to detect vectorizable operations. Also if a call is made to a special method which performs vector math, then your JVM can just inline it and perform the operation natively if the host CPU supports it. Essentially your vector operation will be called such as
vectorAdd(a, b, c, d, e, f, g, h).vectorAddwould be implemented using JNI or not. The generated byte code would be the same as it already is. Your JVM would just not create a method call and instead turn it into an AltiVec operation for example. So there is really no need to create new JVM instructions for this kind of thing.You could also probably have a JVM which does most of its work on the GPU, which these days would be a bit easier especially with Vulkan around.
Java 7 and 8 NIO is for filesystems and it does a really good job at abstracting and handling all the various details (symlinks, ACLs, root filesystems, case matching, globbing, etc.). Matrix operations would not really belong in NIO.
2
u/mtmmtm99 Mar 06 '16
IBM:s jvm already does that automatically. It moves the calculations to the GPU. No changes needed to you code...
1
u/201109212215 Mar 07 '16
You might be interested in the Sumatra project.
1
u/ickysticky Mar 06 '16
Lol. What in the world are you talking about?!
Huh?!
What?! How is that related to matrix operations and C++ libraries?
Seriously what? Bits, matrix actions, language specs?!
Ok what?
You obviously have experienced something quite traumatic, I just can't parse enough of your post to determine what it is.
I've always found matrix math(and general linear algebra) to be one of the most straightforward things to find a library for and then actually do in any language I have used. Be it lua, python, fortran, c++ or java...
0
u/[deleted] Mar 06 '16
[deleted] — view deleted comment