-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[GPU] Optimize merge memory usage #136411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ldematte
wants to merge
14
commits into
elastic:main
Choose a base branch
from
ldematte:gpu/optimize-merge-space
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c56c707
Use the internal raw vector data during merge, avoid additional tmp file
ldematte 0819dbd
Fix access
ldematte 48a3f7c
Expose vector values from Int7SQVectorScorerSupplier
ldematte 7cede4c
Merge branch 'main' into gpu/optimize-merge-space
ldematte 1fc9ff1
PR feedback
ldematte b4bad58
Merge remote-tracking branch 'upstream/main' into gpu/optimize-merge-…
ldematte a904598
[CI] Auto commit changes from spotless
3622f30
Merge remote-tracking branch 'upstream/main' into gpu/optimize-merge-…
ldematte de1f42a
Fix
ldematte 9da8566
Merge branch 'main' into gpu/optimize-merge-space
ldematte 0e62c56
Merge remote-tracking branch 'upstream/main' into gpu/optimize-merge-…
ldematte 982a3a4
Avoid using deviceBuilder due to cuVS bug; update comment
ldematte 2d6ca1d
Rever log level change (see https://github.com/elastic/elasticsearch/…
ldematte b8f1ef9
Merge remote-tracking branch 'upstream/main' into gpu/optimize-merge-…
ldematte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
libs/simdvec/src/main/java/org/elasticsearch/simdvec/QuantizedByteVectorValuesAccess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.simdvec; | ||
|
||
import org.apache.lucene.util.quantization.QuantizedByteVectorValues; | ||
|
||
public interface QuantizedByteVectorValuesAccess { | ||
ldematte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
QuantizedByteVectorValues get(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...main/java/org/elasticsearch/index/codec/vectors/reflect/VectorsFormatReflectionUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.codec.vectors.reflect; | ||
|
||
import org.apache.lucene.codecs.lucene95.HasIndexSlice; | ||
import org.apache.lucene.index.FloatVectorValues; | ||
import org.apache.lucene.util.hnsw.CloseableRandomVectorScorerSupplier; | ||
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier; | ||
import org.elasticsearch.simdvec.QuantizedByteVectorValuesAccess; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
|
||
public class VectorsFormatReflectionUtils { | ||
ldematte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final VarHandle FLOAT_SUPPLIER_HANDLE; | ||
private static final VarHandle BYTE_SUPPLIER_HANDLE; | ||
private static final VarHandle FLOAT_VECTORS_HANDLE; | ||
|
||
private static final Class<?> FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS; | ||
private static final Class<?> SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS; | ||
private static final Class<?> FLOAT_SCORING_SUPPLIER_CLASS; | ||
static { | ||
try { | ||
FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS = Class.forName( | ||
"org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsWriter$FlatCloseableRandomVectorScorerSupplier" | ||
); | ||
var lookup = MethodHandles.privateLookupIn(FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS, MethodHandles.lookup()); | ||
FLOAT_SUPPLIER_HANDLE = lookup.findVarHandle( | ||
FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS, | ||
"supplier", | ||
RandomVectorScorerSupplier.class | ||
); | ||
|
||
FLOAT_SCORING_SUPPLIER_CLASS = Class.forName( | ||
"org.apache.lucene.internal.vectorization.Lucene99MemorySegmentFloatVectorScorerSupplier" | ||
); | ||
lookup = MethodHandles.privateLookupIn(FLOAT_SCORING_SUPPLIER_CLASS, MethodHandles.lookup()); | ||
FLOAT_VECTORS_HANDLE = lookup.findVarHandle(FLOAT_SCORING_SUPPLIER_CLASS, "values", FloatVectorValues.class); | ||
|
||
SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS = Class.forName( | ||
"org.apache.lucene.codecs.lucene99.Lucene99ScalarQuantizedVectorsWriter$ScalarQuantizedCloseableRandomVectorScorerSupplier" | ||
ldematte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
); | ||
lookup = MethodHandles.privateLookupIn(SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS, MethodHandles.lookup()); | ||
BYTE_SUPPLIER_HANDLE = lookup.findVarHandle( | ||
SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS, | ||
"supplier", | ||
RandomVectorScorerSupplier.class | ||
); | ||
|
||
} catch (IllegalAccessException e) { | ||
throw new AssertionError("should not happen, check opens", e); | ||
} catch (ReflectiveOperationException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
|
||
public static RandomVectorScorerSupplier getFlatRandomVectorScorerInnerSupplier(CloseableRandomVectorScorerSupplier scorerSupplier) { | ||
if (scorerSupplier.getClass().equals(FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS)) { | ||
return (RandomVectorScorerSupplier) FLOAT_SUPPLIER_HANDLE.get(scorerSupplier); | ||
} | ||
return null; | ||
} | ||
|
||
public static RandomVectorScorerSupplier getScalarQuantizedRandomVectorScorerInnerSupplier( | ||
CloseableRandomVectorScorerSupplier scorerSupplier | ||
) { | ||
if (scorerSupplier.getClass().equals(SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS)) { | ||
return (RandomVectorScorerSupplier) BYTE_SUPPLIER_HANDLE.get(scorerSupplier); | ||
} | ||
return null; | ||
} | ||
|
||
public static HasIndexSlice getFloatScoringSupplierVectorOrNull(RandomVectorScorerSupplier scorerSupplier) { | ||
if (FLOAT_SCORING_SUPPLIER_CLASS.isAssignableFrom(scorerSupplier.getClass())) { | ||
var vectorValues = FLOAT_VECTORS_HANDLE.get(scorerSupplier); | ||
if (vectorValues instanceof HasIndexSlice indexSlice) { | ||
return indexSlice; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static HasIndexSlice getByteScoringSupplierVectorOrNull(RandomVectorScorerSupplier scorerSupplier) { | ||
if (scorerSupplier instanceof QuantizedByteVectorValuesAccess quantizedByteVectorValuesAccess) { | ||
ldematte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return quantizedByteVectorValuesAccess.get(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.