Skip to content

Commit ebaa34a

Browse files
rmuiruschindler
authored andcommitted
speedup all binary functions on avx256, speedup binary square on avx512 (#12681)
- Move testing properties to provider class (no classloading deadlock possible) and fallback to default provider in non-test mode - fix html - tidy - fix Panama provider to only have static final constants, but allow sysprops for testing. - Set those sysprops by the build when running tests: force integer vectors on always, and randomize vector size - stop using SPECIES_PREFERRED except at the top of this file - speedup all binary functions on avx256, speedup binary square on avx512 - cleanup cosine too, no perf impact - simple cleanups to vector code
1 parent 2615c03 commit ebaa34a

File tree

4 files changed

+505
-326
lines changed

4 files changed

+505
-326
lines changed

gradle/testing/randomization.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ allprojects {
105105
// miscellaneous; some of them very weird.
106106
[propName: 'tests.LUCENE_VERSION', value: baseVersion, description: "Base Lucene version."],
107107
[propName: 'tests.bwcdir', value: null, description: "Data for backward-compatibility indexes."],
108+
// vectorization related
109+
[propName: 'tests.vectorsize',
110+
value: { ->
111+
RandomPicks.randomFrom(new Random(projectSeedLong), ["128", "256", "512"])
112+
},
113+
description: "Sets preferred vector size in bits."],
114+
[propName: 'tests.forceintegervectors', value: "true", description: "Forces use of integer vectors even when slow."],
108115
]
109116
}
110117
}

lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
import java.util.Locale;
2727
import java.util.Objects;
2828
import java.util.Optional;
29+
import java.util.OptionalInt;
2930
import java.util.Set;
31+
import java.util.function.Predicate;
3032
import java.util.logging.Logger;
33+
import java.util.stream.Stream;
3134
import org.apache.lucene.util.SuppressForbidden;
3235
import org.apache.lucene.util.VectorUtil;
3336

@@ -40,6 +43,35 @@
4043
*/
4144
public abstract class VectorizationProvider {
4245

46+
static final OptionalInt TESTS_VECTOR_SIZE;
47+
static final boolean TESTS_FORCE_INTEGER_VECTORS;
48+
49+
static {
50+
var vs = OptionalInt.empty();
51+
try {
52+
vs =
53+
Stream.ofNullable(System.getProperty("tests.vectorsize"))
54+
.filter(Predicate.not(String::isEmpty))
55+
.mapToInt(Integer::parseInt)
56+
.findAny();
57+
} catch (
58+
@SuppressWarnings("unused")
59+
SecurityException se) {
60+
// ignored
61+
}
62+
TESTS_VECTOR_SIZE = vs;
63+
64+
boolean enforce = false;
65+
try {
66+
enforce = Boolean.getBoolean("tests.forceintegervectors");
67+
} catch (
68+
@SuppressWarnings("unused")
69+
SecurityException se) {
70+
// ignored
71+
}
72+
TESTS_FORCE_INTEGER_VECTORS = enforce;
73+
}
74+
4375
/**
4476
* Returns the default instance of the provider matching vectorization possibilities of actual
4577
* runtime.
@@ -90,10 +122,17 @@ static VectorizationProvider lookup(boolean testMode) {
90122
return new DefaultVectorizationProvider();
91123
}
92124
vectorMod.ifPresent(VectorizationProvider.class.getModule()::addReads);
93-
// check if client VM
94-
if (!testMode && isClientVM()) {
95-
LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");
96-
return new DefaultVectorizationProvider();
125+
// check for testMode and otherwise fallback to default if slowness could happen
126+
if (!testMode) {
127+
if (TESTS_VECTOR_SIZE.isPresent() || TESTS_FORCE_INTEGER_VECTORS) {
128+
LOG.warning(
129+
"Vector bitsize and/or integer vectors enforcement; using default vectorization provider outside of testMode");
130+
return new DefaultVectorizationProvider();
131+
}
132+
if (isClientVM()) {
133+
LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");
134+
return new DefaultVectorizationProvider();
135+
}
97136
}
98137
try {
99138
// we use method handles with lookup, so we do not need to deal with setAccessible as we
@@ -102,10 +141,9 @@ static VectorizationProvider lookup(boolean testMode) {
102141
final var cls =
103142
lookup.findClass(
104143
"org.apache.lucene.internal.vectorization.PanamaVectorizationProvider");
105-
final var constr =
106-
lookup.findConstructor(cls, MethodType.methodType(void.class, boolean.class));
144+
final var constr = lookup.findConstructor(cls, MethodType.methodType(void.class));
107145
try {
108-
return (VectorizationProvider) constr.invoke(testMode);
146+
return (VectorizationProvider) constr.invoke();
109147
} catch (UnsupportedOperationException uoe) {
110148
// not supported because preferred vector size too small or similar
111149
LOG.warning("Java vector incubator API was not enabled. " + uoe.getMessage());

0 commit comments

Comments
 (0)