generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 169
[DRAFT] Flat Index Builder PoC Implementation for Removing Redundant Vector Transfer in Remote Index Building #2779
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
Draft
DNimmala5
wants to merge
17
commits into
opensearch-project:main
Choose a base branch
from
DNimmala5:flat-index-builder
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.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fdb3f7a
Flat Index Storage Builder working
DNimmala5 942f85c
Updated file chain formatting, functionality works
DNimmala5 c134ed5
put code into seperate function in RIBS.J to be cleaner
DNimmala5 6788b61
Merge branch 'main' of github.com:DNimmala5/k-NN---GPU-Optimization
DNimmala5 512c496
Merge branch 'main' into gpu-opt-dev
DNimmala5 ef1410f
removed byte support, added tests but running them isnt working, core…
DNimmala5 0c11c4c
added faiss wrapper tests, still dont run because illegal instruction…
DNimmala5 cb57d34
took some wrapper tests out
DNimmala5 301bf54
moved wrapper tests to wrapper unit tests
DNimmala5 bbeb45d
removed print debug stuff, good for draft pr?
DNimmala5 5e38d06
removed make and build file stuff/changes
DNimmala5 57e7133
removed googletest make and build stuff
DNimmala5 2b45341
removed google test download stuff
DNimmala5 bcc91b2
more changes to leave only my files
DNimmala5 d4b56f7
more diff changes
DNimmala5 1653d61
more changes diff
DNimmala5 852f325
more changes diff
DNimmala5 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,38 @@ void knn_jni::faiss_wrapper::InsertToIndex(knn_jni::JNIUtilInterface * jniUtil, | |
indexService->insertToIndex(dim, numIds, threadCount, vectorsAddress, ids, index_ptr); | ||
} | ||
|
||
jlong knn_jni::faiss_wrapper::BuildFlatIndexFromVectors(knn_jni::JNIUtilInterface *jniUtil, JNIEnv *env, jfloatArray vectorsJ, jint numVectors, | ||
jint dimJ, jstring metricTypeJ, IndexService *indexService) { | ||
|
||
if (vectorsJ == nullptr) { | ||
throw std::runtime_error("Vector data cannot be null"); | ||
} | ||
|
||
if (dimJ <= 0 || numVectors <= 0) { | ||
throw std::runtime_error("Invalid dimensions or number of vectors"); | ||
} | ||
|
||
const char *metricTypeC = env->GetStringUTFChars(metricTypeJ, nullptr); | ||
jsize totalLength = env->GetArrayLength(vectorsJ); | ||
|
||
if (totalLength != numVectors * dimJ) { | ||
env->ReleaseStringUTFChars(metricTypeJ, metricTypeC); | ||
throw std::runtime_error("Vector data length does not match numVectors * dimension"); | ||
} | ||
|
||
jfloat* vectors = env->GetFloatArrayElements(vectorsJ, nullptr); | ||
std::vector<float> cppVectors(vectors, vectors + totalLength); | ||
|
||
faiss::MetricType metric = (strcmp(metricTypeC, "IP") == 0) ? faiss::METRIC_INNER_PRODUCT : faiss::METRIC_L2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a helper in jni_util for this? |
||
|
||
jlong indexPtr = indexService->buildFlatIndexFromVectors(numVectors, dimJ, cppVectors, metric); | ||
|
||
env->ReleaseFloatArrayElements(vectorsJ, vectors, JNI_ABORT); | ||
env->ReleaseStringUTFChars(metricTypeJ, metricTypeC); | ||
|
||
return indexPtr; | ||
} | ||
|
||
void knn_jni::faiss_wrapper::WriteIndex(knn_jni::JNIUtilInterface * jniUtil, JNIEnv * env, | ||
jobject output, jlong index_ptr, IndexService* indexService) { | ||
|
||
|
@@ -597,7 +629,7 @@ jobjectArray knn_jni::faiss_wrapper::QueryIndex_WithFilter(knn_jni::JNIUtilInter | |
} else { | ||
auto ivfReader = dynamic_cast<const faiss::IndexIVF*>(indexReader->index); | ||
auto ivfFlatReader = dynamic_cast<const faiss::IndexIVFFlat*>(indexReader->index); | ||
|
||
if(ivfReader || ivfFlatReader) { | ||
int indexNprobe = ivfReader == nullptr ? ivfFlatReader->nprobe : ivfReader->nprobe; | ||
ivfParams.nprobe = commons::getIntegerMethodParameter(env, jniUtil, methodParams, NPROBES, indexNprobe); | ||
|
@@ -1228,4 +1260,4 @@ jobjectArray knn_jni::faiss_wrapper::RangeSearchWithFilter(knn_jni::JNIUtilInter | |
} | ||
|
||
return results; | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to call add_with_ids?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - lets try to use existing mechanisms. You might need the id mapping during reconstruction.