Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.lucene.util.quantization.ScalarQuantizer;
import org.elasticsearch.common.logging.LogConfigurator;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;
import org.elasticsearch.simdvec.VectorScorerFactory;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand Down Expand Up @@ -61,6 +63,10 @@ public class Int7uScorerBenchmark {

static {
LogConfigurator.configureESLogging(); // native access requires logging to be initialized
if (supportsHeapSegments() == false) {
final Logger LOG = LogManager.getLogger(Int7uScorerBenchmark.class);
LOG.warn("*Query targets cannot run on " + "JDK " + Runtime.version());
}
}

@Param({ "96", "768", "1024" })
Expand Down Expand Up @@ -129,15 +135,17 @@ public void setup() throws IOException {
nativeSqrScorer = factory.getInt7SQVectorScorerSupplier(EUCLIDEAN, in, values, scoreCorrectionConstant).get().scorer();
nativeSqrScorer.setScoringOrdinal(0);

// setup for getInt7SQVectorScorer / query vector scoring
float[] queryVec = new float[dims];
for (int i = 0; i < dims; i++) {
queryVec[i] = ThreadLocalRandom.current().nextFloat();
if (supportsHeapSegments()) {
// setup for getInt7SQVectorScorer / query vector scoring
float[] queryVec = new float[dims];
for (int i = 0; i < dims; i++) {
queryVec[i] = ThreadLocalRandom.current().nextFloat();
}
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();
}
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();
}

@TearDown
Expand Down Expand Up @@ -208,6 +216,10 @@ public float squareDistanceNativeQuery() throws IOException {
return nativeSqrScorerQuery.score(1);
}

static boolean supportsHeapSegments() {
return Runtime.version().feature() >= 22;
}

QuantizedByteVectorValues vectorValues(int dims, int size, IndexInput in, VectorSimilarityFunction sim) throws IOException {
var sq = new ScalarQuantizer(0.1f, 0.9f, (byte) 7);
var slice = in.slice("values", 0, in.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public void testDotProduct() throws Exception {
assertEquals(expected, bench.dotProductLucene(), delta);
assertEquals(expected, bench.dotProductNative(), delta);

expected = bench.dotProductLuceneQuery();
assertEquals(expected, bench.dotProductNativeQuery(), delta);
if (Int7uScorerBenchmark.supportsHeapSegments()) {
expected = bench.dotProductLuceneQuery();
assertEquals(expected, bench.dotProductNativeQuery(), delta);
}
} finally {
bench.teardown();
}
Expand All @@ -60,8 +62,10 @@ public void testSquareDistance() throws Exception {
assertEquals(expected, bench.squareDistanceLucene(), delta);
assertEquals(expected, bench.squareDistanceNative(), delta);

expected = bench.squareDistanceLuceneQuery();
assertEquals(expected, bench.squareDistanceNativeQuery(), delta);
if (Int7uScorerBenchmark.supportsHeapSegments()) {
expected = bench.squareDistanceLuceneQuery();
assertEquals(expected, bench.squareDistanceNativeQuery(), delta);
}
} finally {
bench.teardown();
}
Expand Down