-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the Streaming Feature to stream vectors from Java to JNI …
…layer to enable creation of larger segments for vector indices (#1604) Changes include: 1. Add the interface for streaming the vectors from java to jni layer with initial capacity (#1586) 2. Integrating storeVectors interfaces with createIndex and createIndexTemplate functions. (#1588) 3. Update KNN80BinaryDocValues reader count live docs and use live docs as initial capacity to initialize vector address(#1595) 4. Move free vectorAddress from Java to JNI layer to reduce the memory footprint for Nmslib (#1602) Signed-off-by: Navneet Verma <[email protected]>
- Loading branch information
Showing
42 changed files
with
971 additions
and
368 deletions.
There are no files selected for viewing
This file contains 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 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 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,37 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
#include "jni_util.h" | ||
#include <jni.h> | ||
namespace knn_jni { | ||
namespace commons { | ||
/** | ||
* This is utility function that can be used to store data in native memory. This function will allocate memory for | ||
* the data(rows*columns) with initialCapacity and return the memory address where the data is stored. | ||
* If you are using this function for first time use memoryAddress = 0 to ensure that a new memory location is created. | ||
* For subsequent calls you can pass the same memoryAddress. If the data cannot be stored in the memory location | ||
* will throw Exception. | ||
* | ||
* @param memoryAddress The address of the memory location where data will be stored. | ||
* @param data 2D float array containing data to be stored in native memory. | ||
* @param initialCapacity The initial capacity of the memory location. | ||
* @return memory address where the data is stored. | ||
*/ | ||
jlong storeVectorData(knn_jni::JNIUtilInterface *, JNIEnv *, jlong , jobjectArray, jlong); | ||
|
||
/** | ||
* Free up the memory allocated for the data stored in memory address. This function should be used with the memory | ||
* address returned by {@link JNICommons#storeVectorData(long, float[][], long, long)} | ||
* | ||
* @param memoryAddress address to be freed. | ||
*/ | ||
void freeVectorData(jlong); | ||
} | ||
} |
This file contains 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 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 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 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 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,40 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* DO NOT EDIT THIS FILE - it is machine generated */ | ||
#include <jni.h> | ||
/* Header for class org_opensearch_knn_jni_JNICommons */ | ||
|
||
#ifndef _Included_org_opensearch_knn_jni_JNICommons | ||
#define _Included_org_opensearch_knn_jni_JNICommons | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
/* | ||
* Class: org_opensearch_knn_jni_JNICommons | ||
* Method: storeVectorData | ||
* Signature: (J[[FJJ) | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_org_opensearch_knn_jni_JNICommons_storeVectorData | ||
(JNIEnv *, jclass, jlong, jobjectArray, jlong); | ||
|
||
/* | ||
* Class: org_opensearch_knn_jni_JNICommons | ||
* Method: freeVectorData | ||
* Signature: (J)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_org_opensearch_knn_jni_JNICommons_freeVectorData | ||
(JNIEnv *, jclass, jlong); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains 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 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,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
#ifndef OPENSEARCH_KNN_COMMONS_H | ||
#define OPENSEARCH_KNN_COMMONS_H | ||
#include <jni.h> | ||
|
||
#include <vector> | ||
|
||
#include "jni_util.h" | ||
#include "commons.h" | ||
|
||
jlong knn_jni::commons::storeVectorData(knn_jni::JNIUtilInterface *jniUtil, JNIEnv *env, jlong memoryAddressJ, | ||
jobjectArray dataJ, jlong initialCapacityJ) { | ||
std::vector<float> *vect; | ||
if ((long) memoryAddressJ == 0) { | ||
vect = new std::vector<float>(); | ||
vect->reserve((long)initialCapacityJ); | ||
} else { | ||
vect = reinterpret_cast<std::vector<float>*>(memoryAddressJ); | ||
} | ||
int dim = jniUtil->GetInnerDimensionOf2dJavaFloatArray(env, dataJ); | ||
jniUtil->Convert2dJavaObjectArrayAndStoreToFloatVector(env, dataJ, dim, vect); | ||
|
||
return (jlong) vect; | ||
} | ||
|
||
void knn_jni::commons::freeVectorData(jlong memoryAddressJ) { | ||
if (memoryAddressJ != 0) { | ||
auto *vect = reinterpret_cast<std::vector<float>*>(memoryAddressJ); | ||
delete vect; | ||
} | ||
} | ||
#endif //OPENSEARCH_KNN_COMMONS_H |
This file contains 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.