Skip to content

Commit 94190a3

Browse files
committed
Add a vector implementation for FastPFOR.
This patch: - adds a vector implementation for FastPFOR and provides an example of usage. - modifies pom.xml and build.xml files to conditionally support Java Vector API use. - upgrades a few dependencies for compatibility with latest JDK versions. - adds an explanation on how to build JavaFastPFOR with vector support. Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com>
1 parent 522ed5a commit 94190a3

9 files changed

Lines changed: 14260 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ in sorted orders and use differential coding (they compress deltas).
6767
They can be found in the package me.lemire.integercompression.differential.
6868
Most others do not.
6969

70+
The Java Team at Intel (R) introduced the vector implementation for FastPFOR
71+
based on the Java Vector API that showed significant gains over the
72+
non-vectorized implementation. For an example usage, see
73+
examples/vector/Example.java. The feature requires JDK 19+.
7074

7175
Maven central repository
7276
------------------------
@@ -123,6 +127,7 @@ with contributions by
123127
* Di Wu, http://www.facebook.com/diwu1989
124128
* Stefan Ackermann, https://github.com/Stivo
125129
* Samit Roy, https://github.com/roysamit
130+
* Mulugeta Mammo, https://github.com/mulugetam (for VectorFastPFOR)
126131

127132
How does it compare to the Kamikaze PForDelta library?
128133
------------------------------------------------------
@@ -161,7 +166,17 @@ Speed is always reported in millions of integers per second.
161166
For Maven users
162167
---------------
163168

169+
If you are running JDK 19+
170+
171+
```
164172
mvn compile
173+
```
174+
175+
If you are running earlier versions of JDK
176+
177+
```
178+
mvn compiler:compile@default-compile
179+
```
165180

166181
mvn exec:java
167182

‎build.xml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
<depend srcdir="src/main/java" destdir="target/classes" />
99
<javac includeantruntime="false" destdir="target/classes">
1010
<src path="src/main/java" />
11+
<exclude name="me/lemire/integercompression/vector/*.java" />
12+
<exclude name="module-info.java" />
13+
</javac>
14+
</target>
15+
16+
<target name="vector-fastpfor">
17+
<mkdir dir="target/classes" />
18+
<depend srcdir="src/main/java" destdir="target/classes" />
19+
<javac includeantruntime="false" destdir="target/classes" release="19">
20+
<src path="src/main/java" />
1121
</javac>
1222
</target>
1323

‎examples/vector/Example.java‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2022 Intel Corporation
2+
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
import java.util.Arrays;
6+
import me.lemire.integercompression.FastPFOR;
7+
import me.lemire.integercompression.IntWrapper;
8+
import me.lemire.integercompression.Composition;
9+
import me.lemire.integercompression.IntegerCODEC;
10+
import me.lemire.integercompression.VariableByte;
11+
import me.lemire.integercompression.vector.VectorFastPFOR;
12+
13+
public class Example {
14+
public static void main(String[] args) {
15+
if (args.length == 0)
16+
throw new IllegalArgumentException();
17+
18+
// pass 0 for Vector compressor , non-zero for default compressor
19+
int compressorToUse = Integer.parseInt(args[0]);
20+
21+
final int N = 1310720;
22+
int[] data = new int[N];
23+
24+
// 2-bit data
25+
for (int k = 0; k < N; k += 1)
26+
data[k] = 3;
27+
28+
// a few large values
29+
for (int k = 0; k < N; k += 5)
30+
data[k] = 100;
31+
for (int k = 0; k < N; k += 533)
32+
data[k] = 10000;
33+
34+
int[] compressed = new int[N + 1024];
35+
36+
IntegerCODEC codec = new Composition(
37+
compressorToUse == 0 ? new VectorFastPFOR() : new FastPFOR(),
38+
new VariableByte());
39+
40+
IntWrapper inputoffset = new IntWrapper(0);
41+
IntWrapper outputoffset = new IntWrapper(0);
42+
43+
codec.compress(data, inputoffset, data.length, compressed, outputoffset);
44+
45+
System.out.println("compressed unsorted integers from " +
46+
data.length * 4 / 1024 + "KB to " +
47+
outputoffset.intValue() * 4 / 1024 + "KB");
48+
49+
compressed = Arrays.copyOf(compressed, outputoffset.intValue());
50+
51+
int[] recovered = new int[N];
52+
IntWrapper recoffset = new IntWrapper(0);
53+
54+
codec.uncompress(compressed, new IntWrapper(0), compressed.length,
55+
recovered, recoffset);
56+
57+
System.out.println("compressed length = " + compressed.length +
58+
", uncompressed length = " + recoffset.intValue());
59+
60+
if (Arrays.equals(data, recovered))
61+
System.out.println("data is recovered without loss");
62+
else
63+
throw new RuntimeException("bug"); // could use assert
64+
65+
System.out.println();
66+
}
67+
}

‎examples/vector/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Compile
2+
-------
3+
```
4+
javac -cp <path/to/javafastpfor.jar> Example.java
5+
```
6+
7+
Run
8+
---
9+
```
10+
java --add-modules jdk.incubator.vector -cp <path/to/javafastpfor.jar> Example 0
11+
```
12+

‎pom.xml‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<version>0.1.13-SNAPSHOT</version>
66
<packaging>jar</packaging>
77
<properties>
8-
<maven.compiler.source>1.6</maven.compiler.source>
9-
<maven.compiler.target>1.6</maven.compiler.target>
8+
<maven.compiler.source>1.7</maven.compiler.source>
9+
<maven.compiler.target>1.7</maven.compiler.target>
1010
<encoding>UTF-8</encoding>
1111
</properties>
1212
<licenses>
@@ -60,6 +60,36 @@
6060
</parent>
6161
<build>
6262
<plugins>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<version>3.8.0</version>
67+
<executions>
68+
<execution>
69+
<id>default-compile</id>
70+
<phase>compile</phase>
71+
<goals>
72+
<goal>compile</goal>
73+
</goals>
74+
<configuration>
75+
<excludes>
76+
<exclude>me/lemire/integercompression/vector/*</exclude>
77+
<exclude>module-info.java</exclude>
78+
</excludes>
79+
</configuration>
80+
</execution>
81+
<execution>
82+
<id>vector-fastpfor</id>
83+
<phase>compile</phase>
84+
<goals>
85+
<goal>compile</goal>
86+
</goals>
87+
<configuration>
88+
<release>19</release>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
6393
<plugin>
6494
<groupId>org.apache.felix</groupId>
6595
<artifactId>maven-bundle-plugin</artifactId>
@@ -78,9 +108,6 @@
78108
<version>1.1</version>
79109
<configuration>
80110
<mainClass>me.lemire.integercompression.benchmarktools.Benchmark</mainClass>
81-
<!--
82-
<mainClass>me.lemire.integercompression.benchmarktools.BenchmarkOffsettedSeries</mainClass>
83-
-->
84111
</configuration>
85112
</plugin>
86113
<plugin>
@@ -100,7 +127,7 @@
100127
<plugin>
101128
<groupId>org.apache.maven.plugins</groupId>
102129
<artifactId>maven-javadoc-plugin</artifactId>
103-
<version>2.8</version>
130+
<version>3.0.0</version>
104131
<configuration>
105132
<excludePackageNames>com.kamikaze.pfordelta:me.lemire.integercompression.benchmarktools</excludePackageNames>
106133
</configuration>
@@ -129,7 +156,7 @@
129156
<plugin>
130157
<groupId>org.jacoco</groupId>
131158
<artifactId>jacoco-maven-plugin</artifactId>
132-
<version>0.7.8</version>
159+
<version>0.8.8</version>
133160
<configuration>
134161
<excludes>
135162
<exclude>me/lemire/integercompression/Kamikaze</exclude>

0 commit comments

Comments
 (0)