diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/TestsAndRandomizationPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/TestsAndRandomizationPlugin.java index cf8010949564..77c23f300290 100644 --- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/TestsAndRandomizationPlugin.java +++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/TestsAndRandomizationPlugin.java @@ -543,20 +543,14 @@ private static boolean addVectorizationOptions( Provider defaultVectorizationOption = buildOptions.addBooleanOption( "tests.defaultvectorization", - "Uses defaults for running tests with correct JVM settings to test Panama vectorization (tests.jvmargs, tests.vectorsize, tests.forceintegervectors).", + "Uses defaults for running tests with correct JVM settings to test Panama vectorization (tests.jvmargs, tests.vectorsize).", false); buildOptions.addOption( "tests.vectorsize", "Sets preferred vector size in bits.", project.provider(() -> defaultVectorizationOption.get() ? "default" : randomVectorSize)); - buildOptions.addBooleanOption( - "tests.forceintegervectors", - "Forces use of integer vectors even when slow.", - project.provider( - () -> defaultVectorizationOption.get() ? false : (randomVectorSize != "default"))); - - optionsInheritedAsProperties.addAll(List.of("tests.vectorsize", "tests.forceintegervectors")); + optionsInheritedAsProperties.add("tests.vectorsize"); return defaultVectorizationOption.get(); } diff --git a/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java b/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java index f725de389a6a..69b3e040242a 100644 --- a/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java +++ b/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java @@ -46,7 +46,6 @@ public abstract class VectorizationProvider { static final OptionalInt TESTS_VECTOR_SIZE; - static final boolean TESTS_FORCE_INTEGER_VECTORS; static final int UPPER_JAVA_FEATURE_VERSION = getUpperJavaFeatureVersion(); static { @@ -63,16 +62,6 @@ public abstract class VectorizationProvider { // ignored } TESTS_VECTOR_SIZE = vs; - - boolean enforce = false; - try { - enforce = Boolean.getBoolean("tests.forceintegervectors"); - } catch ( - @SuppressWarnings("unused") - SecurityException se) { - // ignored - } - TESTS_FORCE_INTEGER_VECTORS = enforce; } private static final String UPPER_JAVA_FEATURE_VERSION_SYSPROP = @@ -157,9 +146,9 @@ static VectorizationProvider lookup(boolean testMode) { vectorMod.ifPresent(VectorizationProvider.class.getModule()::addReads); // check for testMode and otherwise fallback to default if slowness could happen if (!testMode) { - if (TESTS_VECTOR_SIZE.isPresent() || TESTS_FORCE_INTEGER_VECTORS) { + if (TESTS_VECTOR_SIZE.isPresent()) { LOG.warning( - "Vector bitsize and/or integer vectors enforcement; using default vectorization provider outside of testMode"); + "Vector bitsize enforcement; using default vectorization provider outside of testMode"); return new DefaultVectorizationProvider(); } if (Constants.IS_CLIENT_VM) { diff --git a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorConstants.java b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorConstants.java index e0c5bbca38ee..a5e080db2609 100644 --- a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorConstants.java +++ b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorConstants.java @@ -27,9 +27,8 @@ final class PanamaVectorConstants { static final int PREFERRED_VECTOR_BITSIZE; /** Whether integer vectors can be trusted to actually be fast. */ - static final boolean HAS_FAST_INTEGER_VECTORS; + static final boolean ENABLE_INTEGER_VECTORS; - static final VectorSpecies PRERERRED_LONG_SPECIES; static final VectorSpecies PRERERRED_INT_SPECIES; static { @@ -42,11 +41,9 @@ final class PanamaVectorConstants { // to be fair, they do document this thing only works well with AVX2/AVX3 and Neon boolean isAMD64withoutAVX2 = Constants.OS_ARCH.equals("amd64") && PREFERRED_VECTOR_BITSIZE < 256; - HAS_FAST_INTEGER_VECTORS = - VectorizationProvider.TESTS_FORCE_INTEGER_VECTORS || (isAMD64withoutAVX2 == false); + ENABLE_INTEGER_VECTORS = + (isAMD64withoutAVX2 == false) || VectorizationProvider.TESTS_VECTOR_SIZE.isPresent(); - PRERERRED_LONG_SPECIES = - VectorSpecies.of(long.class, VectorShape.forBitSize(PREFERRED_VECTOR_BITSIZE)); PRERERRED_INT_SPECIES = VectorSpecies.of(int.class, VectorShape.forBitSize(PREFERRED_VECTOR_BITSIZE)); } diff --git a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java index 9aa4bc09e348..e19b85ebce78 100644 --- a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java +++ b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java @@ -46,7 +46,6 @@ * *
    *
  • tests.vectorsize (int) - *
  • tests.forceintegervectors (boolean) *
* * Setting these properties will make this code run EXTREMELY slow! @@ -313,9 +312,8 @@ public static int dotProduct(MemorySegment a, MemorySegment b) { int i = 0; int res = 0; - // only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit - // vectors (256-bit on intel to dodge performance landmines) - if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + // only vectorize if we'll at least enter the loop a single time + if (a.byteSize() >= 16) { // compute vectorized dot product consistent with VPDPBUSD instruction if (VECTOR_BITSIZE >= 512) { i += BYTE_SPECIES.loopBound(a.byteSize()); @@ -409,7 +407,7 @@ public int int4DotProduct(byte[] a, boolean apacked, byte[] b, boolean bpacked) } else if (VECTOR_BITSIZE == 256) { i += ByteVector.SPECIES_128.loopBound(packed.length); res += dotProductBody256Int4Packed(unpacked, packed, i); - } else if (PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + } else { i += ByteVector.SPECIES_64.loopBound(packed.length); res += dotProductBody128Int4Packed(unpacked, packed, i); } @@ -425,7 +423,7 @@ public int int4DotProduct(byte[] a, boolean apacked, byte[] b, boolean bpacked) } else { if (VECTOR_BITSIZE >= 512 || VECTOR_BITSIZE == 256) { return dotProduct(a, b); - } else if (a.length >= 32 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + } else if (a.length >= 32) { i += ByteVector.SPECIES_128.loopBound(a.length); res += int4DotProductBody128(a, b, i); } @@ -581,9 +579,8 @@ public static float cosine(MemorySegment a, MemorySegment b) { int norm1 = 0; int norm2 = 0; - // only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit - // vectors (256-bit on intel to dodge performance landmines) - if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + // only vectorize if we'll at least enter the loop a single time + if (a.byteSize() >= 16) { final float[] ret; if (VECTOR_BITSIZE >= 512) { i += BYTE_SPECIES.loopBound((int) a.byteSize()); @@ -704,9 +701,8 @@ public static int squareDistance(MemorySegment a, MemorySegment b) { int i = 0; int res = 0; - // only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit - // vectors (256-bit on intel to dodge performance landmines) - if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + // only vectorize if we'll at least enter the loop a single time + if (a.byteSize() >= 16) { if (VECTOR_BITSIZE >= 256) { i += BYTE_SPECIES.loopBound((int) a.byteSize()); res += squareDistanceBody256(a, b, i); @@ -798,7 +794,7 @@ public int findNextGEQ(int[] buffer, int target, int from, int to) { public long int4BitDotProduct(byte[] q, byte[] d) { assert q.length == d.length * 4; // 128 / 8 == 16 - if (d.length >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) { + if (d.length >= 16) { if (VECTOR_BITSIZE >= 256) { return int4BitDotProduct256(q, d); } else if (VECTOR_BITSIZE == 128) { diff --git a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorizationProvider.java b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorizationProvider.java index 2e061ee6f5fc..b30af21653ed 100644 --- a/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorizationProvider.java +++ b/lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorizationProvider.java @@ -45,6 +45,11 @@ final class PanamaVectorizationProvider extends VectorizationProvider { "Vector bit size is less than 128: " + PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE); } + if (PanamaVectorConstants.ENABLE_INTEGER_VECTORS == false) { + throw new UnsupportedOperationException( + "CPU type or flags do not guarantee support for fast integer vectorization"); + } + this.vectorUtilSupport = new PanamaVectorUtilSupport(); var log = Logger.getLogger(getClass().getName()); @@ -54,7 +59,7 @@ final class PanamaVectorizationProvider extends VectorizationProvider { "Java vector incubator API enabled; uses preferredBitSize=%d%s%s", PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE, Constants.HAS_FAST_VECTOR_FMA ? "; FMA enabled" : "", - PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS ? "" : "; floating-point vectors only")); + VectorizationProvider.TESTS_VECTOR_SIZE.isPresent() ? "; testMode enabled" : "")); } @Override @@ -69,8 +74,7 @@ public FlatVectorsScorer getLucene99FlatVectorsScorer() { @Override public PostingDecodingUtil newPostingDecodingUtil(IndexInput input) throws IOException { - if (PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS - && input instanceof MemorySegmentAccessInput msai) { + if (input instanceof MemorySegmentAccessInput msai) { MemorySegment ms = msai.segmentSliceOrNull(0, input.length()); if (ms != null) { return new MemorySegmentPostingDecodingUtil(input, ms);