3

I'm trying to use the Java Vector API from the Panama project to add some SIMD code to the java.math.BigInteger class. I cloned the Panama repo and built a JDK:

hg clone http://hg.openjdk.java.net/panama/dev/
cd dev/
hg checkout vectorIntrinsics
hg branch vectorIntrinsics
bash configure
make images

I was able to compile and run a simple little program that uses the vector API:

import static jdk.incubator.vector.Vector.Shape.S_256_BIT;
import jdk.incubator.vector.IntVector;
import static jdk.incubator.vector.IntVector.IntSpecies;

public class Panama {

    public static void main(String... args) {
        IntSpecies int256Species = (IntSpecies)IntSpecies.of(int.class, S_256_BIT);
        int[] arr = new int[] {1, 5, 0, 2, 8, -1, 4, 3};
        IntVector vec = IntVector.fromArray(int256Species, arr, 0);
        IntVector vec2 = vec.mul(vec);
        int[] arr2 = new int[8];
        vec2.intoArray(arr2, 0);
        System.out.println("x\tx²");
        System.out.println("-------------------");
        for (int i=0; i<8; i++)
            System.out.println(arr[i] + "\t" + arr2[i]);
    }
}

The commands I used for compiling and running the program were:

dev/build/linux-x86_64-server-release/jdk/bin/javac --add-modules=jdk.incubator.vector,java.base --patch-module java.base=src/ --add-reads java.base=jdk.incubator.vector src/Panama.java

dev/build/linux-x86_64-server-release/jdk/bin/java --add-modules=jdk.incubator.vector -cp src/ Panama

Next, I wanted to incorporate the code into BigInteger.java from the sources that come with the JDK. I simply added the import statements and the main method to BigInteger.java. I compiled the code:

dev/build/linux-x86_64-server-release/jdk/bin/javac --add-reads java.base=jdk.incubator.vector --patch-module java.base=src/ --add-modules=jdk.incubator.vector src/java/math/BigInteger.java

When I tried to run it using

dev/build/linux-x86_64-server-release/jdk/bin/java --add-reads java.base=jdk.incubator.vector --patch-module java.base=src/ --add-modules=jdk.incubator.vector --add-exports jdk.incubator.vector/jdk.incubator.vector=java.base -cp src/ java.math.BigInteger

I got the error below:

Exception in thread "main" java.lang.NoClassDefFoundError: jdk/incubator/vector/Vector$Shape
    at java.base/java.math.BigInteger.main(BigInteger.java:4837)

Line 4837 is the one that starts with IntSpecies int256Species = ....

So it looks like the java.base module cannot access the jdk.incubator.vector module. Note that jdk.incubator.vector is part of the Panama JDK.

My question is, why am I getting this error even though I allowed access from java.base to jdk.incubator.vector using the --add-exports and --add-reads options? Is there another option I need to give it so I can use jdk.incubator.vector classes in BigInteger?

Edit: add hg checkout and hg branch

Edit^2: Panama API changed since I cloned the repo two weeks ago. Code has been updated so it compiles again.

xhunterx
  • 31
  • 3
  • SIMD is generally hard to use for BigInteger, at an asm level. You don't get carry-out from packed-addition, and on x86 at least you have scalar 64x64 => 128-bit multiply, but SIMD only 32x32 => 64-bit widening multiply. (Or with AVX512DQ, 64x64=>64, but that doesn't help). Still, with wide enough vectors, like AVX2, you can get a speedup vs. scalar for doing multiple 64x64 => 64-bit multiplies over an array, e.g. [Fastest way to multiply an array of int64\_t?](//stackoverflow.com/q/37296289) – Peter Cordes Mar 05 '19 at 00:27
  • Or are you just trying to basically type-pun a SIMD vector into a BigInteger here? (Sorry I don't know Java well, and haven't used these libraries.) – Peter Cordes Mar 05 '19 at 00:29

0 Answers0