Merge branch 'main' into vector_512: stomping over any possible conflicting changes: if you made any, i erased them. git is garbage.

This commit is contained in:
Robert Muir 2023-10-15 08:20:43 -04:00
commit 650a47e707
No known key found for this signature in database
GPG Key ID: 817AE1DD322D7ECA
3 changed files with 42 additions and 32 deletions

View File

@ -168,6 +168,9 @@ Improvements
is too old. It also logs partial vectorization support if old CPU or disabled AVX. is too old. It also logs partial vectorization support if old CPU or disabled AVX.
(Uwe Schindler, Robert Muir) (Uwe Schindler, Robert Muir)
* GITHUB#12677: Better detect vector module in non-default setups (e.g., custom module layers).
(Uwe Schindler)
Optimizations Optimizations
--------------------- ---------------------
* GITHUB#12183: Make TermStates#build concurrent. (Shubham Chaudhary) * GITHUB#12183: Make TermStates#build concurrent. (Shubham Chaudhary)

View File

@ -25,6 +25,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.lucene.util.SuppressForbidden; import org.apache.lucene.util.SuppressForbidden;
@ -82,11 +83,14 @@ public abstract class VectorizationProvider {
} }
// is the incubator module present and readable (JVM providers may to exclude them or it is // is the incubator module present and readable (JVM providers may to exclude them or it is
// build with jlink) // build with jlink)
if (!vectorModulePresentAndReadable()) { final var vectorMod = lookupVectorModule();
if (vectorMod.isEmpty()) {
LOG.warning( LOG.warning(
"Java vector incubator module is not readable. For optimal vector performance, pass '--add-modules jdk.incubator.vector' to enable Vector API."); "Java vector incubator module is not readable. For optimal vector performance, pass '--add-modules jdk.incubator.vector' to enable Vector API.");
return new DefaultVectorizationProvider(); return new DefaultVectorizationProvider();
} }
vectorMod.ifPresent(VectorizationProvider.class.getModule()::addReads);
// check if client VM
if (!testMode && isClientVM()) { if (!testMode && isClientVM()) {
LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled"); LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");
return new DefaultVectorizationProvider(); return new DefaultVectorizationProvider();
@ -119,7 +123,7 @@ public abstract class VectorizationProvider {
} else if (runtimeVersion >= 22) { } else if (runtimeVersion >= 22) {
LOG.warning( LOG.warning(
"You are running with Java 22 or later. To make full use of the Vector API, please update Apache Lucene."); "You are running with Java 22 or later. To make full use of the Vector API, please update Apache Lucene.");
} else if (vectorModulePresentAndReadable()) { } else if (lookupVectorModule().isPresent()) {
LOG.warning( LOG.warning(
"Java vector incubator module was enabled by command line flags, but your Java version is too old: " "Java vector incubator module was enabled by command line flags, but your Java version is too old: "
+ runtimeVersion); + runtimeVersion);
@ -127,16 +131,13 @@ public abstract class VectorizationProvider {
return new DefaultVectorizationProvider(); return new DefaultVectorizationProvider();
} }
private static boolean vectorModulePresentAndReadable() { /**
var opt = * Looks up the vector module from Lucene's {@link ModuleLayer} or the root layer (if unnamed).
ModuleLayer.boot().modules().stream() */
.filter(m -> m.getName().equals("jdk.incubator.vector")) private static Optional<Module> lookupVectorModule() {
.findFirst(); return Optional.ofNullable(VectorizationProvider.class.getModule().getLayer())
if (opt.isPresent()) { .orElse(ModuleLayer.boot())
VectorizationProvider.class.getModule().addReads(opt.get()); .findModule("jdk.incubator.vector");
return true;
}
return false;
} }
/** /**

View File

@ -131,6 +131,8 @@ public class TestVectorSimilarityValuesSource extends LuceneTestCase {
VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT)); VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT));
document3.add(new KnnByteVectorField("knnByteField5", new byte[] {-120, -2, 3})); document3.add(new KnnByteVectorField("knnByteField5", new byte[] {-120, -2, 3}));
iw.addDocument(document3); iw.addDocument(document3);
iw.commit();
iw.forceMerge(1);
reader = iw.getReader(); reader = iw.getReader();
searcher = newSearcher(reader); searcher = newSearcher(reader);
@ -313,11 +315,12 @@ public class TestVectorSimilarityValuesSource extends LuceneTestCase {
DoubleValues dv = DoubleValues dv =
DoubleValuesSource.similarityToQueryVector( DoubleValuesSource.similarityToQueryVector(
searcher.reader.leaves().get(0), floatQueryVector, "knnFloatField4"); searcher.reader.leaves().get(0), floatQueryVector, "knnFloatField4");
assertTrue( assertTrue(dv.advanceExact(0));
dv.advanceExact(0) assertEquals(
&& dv.doubleValue() VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare(
== VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare( new float[] {-1.3f, 1.0f, 1.0f}, floatQueryVector),
new float[] {-1.3f, 1.0f, 1.0f}, floatQueryVector)); dv.doubleValue(),
0.0001);
assertFalse(dv.advanceExact(1)); assertFalse(dv.advanceExact(1));
assertFalse(dv.advanceExact(2)); assertFalse(dv.advanceExact(2));
@ -326,21 +329,24 @@ public class TestVectorSimilarityValuesSource extends LuceneTestCase {
dv = dv =
DoubleValuesSource.similarityToQueryVector( DoubleValuesSource.similarityToQueryVector(
searcher.reader.leaves().get(0), byteQueryVector, "knnByteField4"); searcher.reader.leaves().get(0), byteQueryVector, "knnByteField4");
assertTrue( assertTrue(dv.advanceExact(0));
dv.advanceExact(0) assertEquals(
&& dv.doubleValue() VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare(
== VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare( new byte[] {-127, 127, 127}, byteQueryVector),
new byte[] {-127, 127, 127}, byteQueryVector)); dv.doubleValue(),
assertTrue( 0.0001);
dv.advanceExact(1) assertTrue(dv.advanceExact(1));
&& dv.doubleValue() assertEquals(
== VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare( VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare(
new byte[] {14, 29, 31}, byteQueryVector)); new byte[] {14, 29, 31}, byteQueryVector),
assertTrue( dv.doubleValue(),
dv.advanceExact(2) 0.0001);
&& dv.doubleValue() assertTrue(dv.advanceExact(2));
== VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare( assertEquals(
new byte[] {-4, -2, -128}, byteQueryVector)); VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT.compare(
new byte[] {-4, -2, -128}, byteQueryVector),
dv.doubleValue(),
0.0001);
} }
public void testFailuresWithSimilarityValuesSource() throws Exception { public void testFailuresWithSimilarityValuesSource() throws Exception {