Skip to content

Commit 90fdad4

Browse files
mulugetamassanedinaveentatikonda
authored
Add a FAISS_OPT_LEVEL=avx512_spr build mode. (#2404)
* Add avx512_spr option to FAISS_OPT_LEVEL. - avx512_spr enables advanced avx512 instructions available since Intel(R) Sapphire Rapids. Signed-off-by: Mulugeta Mammo <[email protected]> * Fix documentation. Signed-off-by: Assane Diop <[email protected]> * Update scripts/build.sh Co-authored-by: Naveen Tatikonda <[email protected]> Signed-off-by: mulugetam <[email protected]> * Update scripts/build.sh Co-authored-by: Naveen Tatikonda <[email protected]> Signed-off-by: mulugetam <[email protected]> * Fix formatting issues. Signed-off-by: Mulugeta Mammo <[email protected]> * Update CHANGELOG.md for avx512_spr build mode. Signed-off-by: Mulugeta Mammo <[email protected]> * Fix bugs in build options and avx512_spr flag testing. Signed-off-by: Mulugeta Mammo <[email protected]> * Upgrade gcc version to 12.4. Signed-off-by: Mulugeta Mammo <[email protected]> --------- Signed-off-by: Mulugeta Mammo <[email protected]> Signed-off-by: Assane Diop <[email protected]> Signed-off-by: mulugetam <[email protected]> Signed-off-by: Naveen Tatikonda <[email protected]> Co-authored-by: Assane Diop <[email protected]> Co-authored-by: Naveen Tatikonda <[email protected]>
1 parent d58d133 commit 90fdad4

File tree

14 files changed

+182
-33
lines changed

14 files changed

+182
-33
lines changed

.github/workflows/CI.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,21 @@ jobs:
7575
chown -R 1000:1000 `pwd`
7676
if lscpu | grep -i avx512f | grep -i avx512cd | grep -i avx512vl | grep -i avx512dq | grep -i avx512bw
7777
then
78-
echo "avx512 available on system"
79-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dnproc.count=`nproc`"
78+
if lscpu | grep -q "GenuineIntel" && lscpu | grep -i avx512_fp16 | grep -i avx512_bf16 | grep -i avx512_vpopcntdq
79+
then
80+
echo "the system is an Intel(R) Sapphire Rapids or a newer-generation processor"
81+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512_spr.enabled=true -Dnproc.count=`nproc`"
82+
else
83+
echo "avx512 available on system"
84+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
85+
fi
8086
elif lscpu | grep -i avx2
8187
then
8288
echo "avx2 available on system"
83-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dnproc.count=`nproc` -Davx512.enabled=false"
89+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512.enabled=false -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
8490
else
8591
echo "avx512 and avx2 not available on system"
86-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx2.enabled=false -Davx512.enabled=false -Dnproc.count=`nproc`"
92+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx2.enabled=false -Davx512.enabled=false -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
8793
fi
8894
8995

.github/workflows/backwards_compatibility_tests_workflow.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,21 @@ jobs:
108108
echo "Running restart-upgrade backwards compatibility tests ..."
109109
if lscpu | grep -i avx512f | grep -i avx512cd | grep -i avx512vl | grep -i avx512dq | grep -i avx512bw
110110
then
111+
if lscpu | grep -q "GenuineIntel" && lscpu | grep -i avx512_fp16 | grep -i avx512_bf16 | grep -i avx512_vpopcntdq
112+
then
113+
echo "the system is an Intel(R) Sapphire Rapids or a newer-generation processor"
114+
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Dnproc.count=`nproc` -Davx512_spr.enabled=true
115+
else
111116
echo "avx512 available on system"
112-
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Dnproc.count=`nproc`
117+
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Dnproc.count=`nproc` -Davx512_spr.enabled=false
118+
fi
113119
elif lscpu | grep -i avx2
114120
then
115121
echo "avx2 available on system"
116-
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Dnproc.count=`nproc` -Davx512.enabled=false
122+
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Davx512.enabled=false -Davx512_spr.enabled=false -Dnproc.count=`nproc`
117123
else
118124
echo "avx512 and avx2 not available on system"
119-
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Davx2.enabled=false -Davx512.enabled=false -Dsimd.enabled=false -Dnproc.count=`nproc`
125+
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Davx2.enabled=false -Davx512.enabled=false -Davx512_spr.enabled=false -Dsimd.enabled=false -Dnproc.count=`nproc`
120126
fi
121127
122128
Rolling-Upgrade-BWCTests-k-NN:

.github/workflows/test_security.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ jobs:
7373
chown -R 1000:1000 `pwd`
7474
if lscpu | grep -i avx512f | grep -i avx512cd | grep -i avx512vl | grep -i avx512dq | grep -i avx512bw
7575
then
76-
echo "avx512 available on system"
77-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dnproc.count=`nproc`"
76+
if lscpu | grep -q "GenuineIntel" && lscpu | grep -i avx512_fp16 | grep -i avx512_bf16 | grep -i avx512_vpopcntdq
77+
then
78+
echo "the system is an Intel(R) Sapphire Rapids or a newer-generation processor"
79+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512_spr.enabled=true -Dnproc.count=`nproc`"
80+
else
81+
echo "avx512 available on system"
82+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
83+
fi
7884
elif lscpu | grep -i avx2
7985
then
8086
echo "avx2 available on system"
81-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dnproc.count=`nproc` -Davx512.enabled=false"
87+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx512.enabled=false -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
8288
else
8389
echo "avx512 and avx2 not available on system"
84-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx2.enabled=false -Davx512.enabled=false -Dnproc.count=`nproc`"
90+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Davx2.enabled=false -Davx512.enabled=false -Davx512_spr.enabled=false -Dnproc.count=`nproc`"
8591
fi

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2020
- Add Support for Multi Values in innerHit for Nested k-NN Fields in Lucene and FAISS (#2283)[https://github.com/opensearch-project/k-NN/pull/2283]
2121
- Add binary index support for Lucene engine. (#2292)[https://github.com/opensearch-project/k-NN/pull/2292]
2222
- Add expand_nested_docs Parameter support to NMSLIB engine (#2331)[https://github.com/opensearch-project/k-NN/pull/2331]
23+
- Add a new build mode, `FAISS_OPT_LEVEL=avx512_spr`, which enables the use of advanced AVX-512 instructions introduced with Intel(R) Sapphire Rapids (#2404)[https://github.com/opensearch-project/k-NN/pull/2404]
2324
- Add cosine similarity support for faiss engine (#2376)[https://github.com/opensearch-project/k-NN/pull/2376]
2425
### Enhancements
2526
- Introduced a writing layer in native engines where relies on the writing interface to process IO. (#2241)[https://github.com/opensearch-project/k-NN/pull/2241]

DEVELOPER_GUIDE.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,38 @@ make -j 4
297297
### Enable SIMD Optimization
298298
SIMD(Single Instruction/Multiple Data) Optimization is enabled by default on Linux and Mac which boosts the performance
299299
by enabling `AVX2` and `AVX512` on `x86 architecture` and `NEON` on `ARM64 architecture` where applicable while building the Faiss library. But to enable SIMD,
300-
the underlying processor should support these capabilities (AVX512, AVX2 or NEON). It can be disabled by setting the parameter `avx2.enabled` to `false` and
301-
`avx512.enabled` to `false`. If your processor supports `AVX512` or `AVX2`, they can be set by enabling the setting . By default, these values are enabled on
302-
OpenSearch. Some exceptions: As of now, SIMD support is not supported on Windows OS, and AVX512 is not present on MAC systems due to hardware not supporting the
303-
feature.
300+
the underlying processor should support these capabilities (AVX512, AVX2 or NEON). It can be disabled by setting the parameter `avx2.enabled`, `avx512.enabled`,
301+
and `avx512_spr.enabled` to `false`. If your processor supports `AVX512` or `AVX2`, they can be set by enabling the setting. On Intel(R) Sapphire Rapids and
302+
newer-generation systems, enabling `avx512_spr` offers support for `AVX512-FP16` and other features. By default, these values are enabled on OpenSearch.
303+
Some exceptions: As of now, SIMD support is not supported on Windows OS, and AVX512 is not present on MAC systems due to hardware not supporting the feature.
304304
305305
```
306-
# While building OpenSearch k-NN
307-
./gradlew build -Davx2.enabled=true -Davx512.enabled=true
306+
# if (system_supports_avx512_spr) generate_avx512_spr_binaries()
307+
# else if (system_supports_avx512) generate_avx512_binaries()
308+
# else if (system_supports_ avx2) generate_avx2_binaries()
309+
# else() generate_generic_binaries()
308310
309-
# While running OpenSearch k-NN
310-
./gradlew run -Davx2.enabled=true -Davx512.enabled=true
311+
# generate avx2 binaries
312+
./gradlew build -Davx2.enabled=true -Davx512.enabled=false -Davx512_spr.enabled=false
313+
314+
# if (system_supports_avx512_spr) generate_avx512_spr_binaries()
315+
# else if (system_supports_avx512) generate_avx512_binaries()
316+
# else() generate_generic_binaries()
317+
./gradlew build -Davx2.enabled=false -Davx512.enabled=true
318+
319+
# if (system_supports_avx512_spr) generate_avx512_spr_binaries()
320+
# else if (system_supports_avx2) generate_avx2_binaries()
321+
# else() generate_generic_binaries()
322+
./gradlew build -Davx512.enabled=false -Davx512_spr.enabled=true
323+
324+
# if (system_supports_avx512) generate_avx512_binaries()
325+
# else if (system_supports_avx2) generate_avx2_binaries()
326+
# else() generate_generic_binaries()
327+
./gradlew build -Davx512.enabled=true -Davx512_spr.enabled=false
311328
312-
# While building the JNI libraries
329+
# similar logic applies for jni
313330
cd jni
314-
cmake . -DAVX2_ENABLED=true -DAVX512_ENABLED=true
331+
cmake . -DAVX2_ENABLED=true -DAVX512_ENABLED=true -DAVX512_SPR_ENABLED=true
315332
```
316333
317334
## Run OpenSearch k-NN

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ buildscript {
2222
avx2_enabled = System.getProperty("avx2.enabled", "true")
2323
nproc_count = System.getProperty("nproc.count", "1")
2424
avx512_enabled = System.getProperty("avx512.enabled", "true")
25+
avx512_spr_enabled = System.getProperty("avx512_spr.enabled", "true")
2526
// This flag determines whether the CMake build system should apply a custom patch. It prevents build failures
2627
// when the cmakeJniLib task is run multiple times. If the build.lib.commit_patches is true, the CMake build
2728
// system skips applying the patch if the patches have been applied already. If build.lib.commit_patches is
@@ -336,6 +337,7 @@ task cmakeJniLib(type:Exec) {
336337
args.add("-DKNN_PLUGIN_VERSION=${opensearch_version}")
337338
args.add("-DAVX2_ENABLED=${avx2_enabled}")
338339
args.add("-DAVX512_ENABLED=${avx512_enabled}")
340+
args.add("-DAVX512_SPR_ENABLED=${avx512_spr_enabled}")
339341
args.add("-DCOMMIT_LIB_PATCHES=${commit_lib_patches}")
340342
args.add("-DAPPLY_LIB_PATCHES=${apply_lib_patches}")
341343
def javaHome = Jvm.current().getJavaHome()

jni/cmake/init-faiss.cmake

+15-1
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,23 @@ if(NOT DEFINED AVX512_ENABLED)
108108
set(AVX512_ENABLED true) # set default value as true if the argument is not set
109109
endif()
110110

111-
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ( NOT AVX2_ENABLED AND NOT AVX512_ENABLED))
111+
if(NOT DEFINED AVX512_SPR_ENABLED)
112+
# Check if the system is Intel(R) Sapphire Rapids or a newer-generation processor
113+
execute_process(COMMAND bash -c "lscpu | grep -q 'GenuineIntel' && lscpu | grep -i 'avx512_fp16' | grep -i 'avx512_bf16' | grep -i 'avx512_vpopcntdq'" OUTPUT_VARIABLE SPR_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
114+
if (AND NOT "${SPR_FLAGS}" STREQUAL "")
115+
set(AVX512_SPR_ENABLED true)
116+
else()
117+
set(AVX512_SPR_ENABLED false)
118+
endif()
119+
endif()
120+
121+
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ( NOT AVX2_ENABLED AND NOT AVX512_ENABLED AND NOT AVX512_SPR_ENABLED))
112122
set(FAISS_OPT_LEVEL generic) # Keep optimization level as generic on Windows OS as it is not supported due to MINGW64 compiler issue. Also, on aarch64 avx2 is not supported.
113123
set(TARGET_LINK_FAISS_LIB faiss)
124+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux AND AVX512_SPR_ENABLED)
125+
set(FAISS_OPT_LEVEL avx512_spr)
126+
set(TARGET_LINK_FAISS_LIB faiss_avx512_spr)
127+
string(PREPEND LIB_EXT "_avx512_spr")
114128
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux AND AVX512_ENABLED)
115129
set(FAISS_OPT_LEVEL avx512) # Keep optimization level as avx512 to improve performance on Linux. This is not present on mac systems, and presently not supported on Windows OS.
116130
set(TARGET_LINK_FAISS_LIB faiss_avx512)

scripts/build.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fi
112112
# https://github.com/opensearch-project/k-NN/issues/1138
113113
# https://github.com/opensearch-project/opensearch-build/issues/4386
114114
GCC_VERSION=`gcc --version | head -n 1 | cut -d ' ' -f3`
115-
GCC_REQUIRED_VERSION=9.0.0
115+
GCC_REQUIRED_VERSION=12.4
116116
COMPARE_VERSION=`echo $GCC_REQUIRED_VERSION $GCC_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1`
117117
if [ "$COMPARE_VERSION" != "$GCC_REQUIRED_VERSION" ]; then
118118
echo "gcc version on this env is older than $GCC_REQUIRED_VERSION, exit 1"
@@ -122,16 +122,19 @@ fi
122122
# Build k-NN lib and plugin through gradle tasks
123123
cd $work_dir
124124
./gradlew build --no-daemon --refresh-dependencies -x integTest -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER -Dbuild.lib.commit_patches=false
125-
./gradlew :buildJniLib -Davx512.enabled=false -Davx2.enabled=false -Dbuild.lib.commit_patches=false -Dnproc.count=${NPROC_COUNT:-1}
125+
./gradlew :buildJniLib -Davx512.enabled=false -Davx512_spr.enabled=false -Davx2.enabled=false -Dbuild.lib.commit_patches=false -Dnproc.count=${NPROC_COUNT:-1}
126126

127127
if [ "$PLATFORM" != "windows" ] && [ "$ARCHITECTURE" = "x64" ]; then
128128
echo "Building k-NN library after enabling AVX2"
129129
# Skip applying patches as patches were applied already from previous :buildJniLib task
130130
# If we apply patches again, it fails with conflict
131-
./gradlew :buildJniLib -Davx2.enabled=true -Davx512.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
131+
./gradlew :buildJniLib -Davx2.enabled=true -Davx512.enabled=false -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
132132

133133
echo "Building k-NN library after enabling AVX512"
134-
./gradlew :buildJniLib -Davx512.enabled=true -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
134+
./gradlew :buildJniLib -Davx512.enabled=true -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
135+
136+
echo "Building k-NN library after enabling AVX512_SPR"
137+
./gradlew :buildJniLib -Davx512_spr.enabled=true -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
135138
fi
136139

137140
./gradlew publishPluginZipPublicationToZipStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

src/main/java/org/opensearch/knn/common/KNNConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class KNNConstants {
142142
public static final String FAISS_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + FAISS_NAME;
143143
public static final String FAISS_AVX2_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + FAISS_NAME + "_avx2";
144144
public static final String FAISS_AVX512_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + FAISS_NAME + "_avx512";
145+
public static final String FAISS_AVX512_SPR_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + FAISS_NAME + "_avx512_spr";
145146
public static final String NMSLIB_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + NMSLIB_NAME;
146147

147148
public static final String COMMON_JNI_LIBRARY_NAME = JNI_LIBRARY_PREFIX + COMMONS_NAME;

src/main/java/org/opensearch/knn/index/KNNSettings.java

+22
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class KNNSettings {
9090
public static final String QUANTIZATION_STATE_CACHE_SIZE_LIMIT = "knn.quantization.cache.size.limit";
9191
public static final String QUANTIZATION_STATE_CACHE_EXPIRY_TIME_MINUTES = "knn.quantization.cache.expiry.minutes";
9292
public static final String KNN_FAISS_AVX512_DISABLED = "knn.faiss.avx512.disabled";
93+
public static final String KNN_FAISS_AVX512_SPR_DISABLED = "knn.faiss.avx512_spr.disabled";
9394
public static final String KNN_DISK_VECTOR_SHARD_LEVEL_RESCORING_DISABLED = "index.knn.disk.vector.shard_level_rescoring_disabled";
9495

9596
/**
@@ -98,6 +99,7 @@ public class KNNSettings {
9899
*/
99100
public static final boolean KNN_DEFAULT_FAISS_AVX2_DISABLED_VALUE = false;
100101
public static final boolean KNN_DEFAULT_FAISS_AVX512_DISABLED_VALUE = false;
102+
public static final boolean KNN_DEFAULT_FAISS_AVX512_SPR_DISABLED_VALUE = false;
101103
public static final String INDEX_KNN_DEFAULT_SPACE_TYPE = "l2";
102104
public static final Integer INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD_DEFAULT_VALUE = 15_000;
103105
public static final Integer INDEX_KNN_BUILD_VECTOR_DATA_STRUCTURE_THRESHOLD_MIN = -1;
@@ -353,6 +355,12 @@ public class KNNSettings {
353355
NodeScope
354356
);
355357

358+
public static final Setting<Boolean> KNN_FAISS_AVX512_SPR_DISABLED_SETTING = Setting.boolSetting(
359+
KNN_FAISS_AVX512_SPR_DISABLED,
360+
KNN_DEFAULT_FAISS_AVX512_SPR_DISABLED_VALUE,
361+
NodeScope
362+
);
363+
356364
/**
357365
* Dynamic settings
358366
*/
@@ -484,6 +492,10 @@ private Setting<?> getSetting(String key) {
484492
return KNN_FAISS_AVX512_DISABLED_SETTING;
485493
}
486494

495+
if (KNN_FAISS_AVX512_SPR_DISABLED.equals(key)) {
496+
return KNN_FAISS_AVX512_SPR_DISABLED_SETTING;
497+
}
498+
487499
if (KNN_VECTOR_STREAMING_MEMORY_LIMIT_IN_MB.equals(key)) {
488500
return KNN_VECTOR_STREAMING_MEMORY_LIMIT_PCT_SETTING;
489501
}
@@ -521,6 +533,7 @@ public List<Setting<?>> getSettings() {
521533
KNN_FAISS_AVX2_DISABLED_SETTING,
522534
KNN_VECTOR_STREAMING_MEMORY_LIMIT_PCT_SETTING,
523535
KNN_FAISS_AVX512_DISABLED_SETTING,
536+
KNN_FAISS_AVX512_SPR_DISABLED_SETTING,
524537
QUANTIZATION_STATE_CACHE_SIZE_LIMIT_SETTING,
525538
QUANTIZATION_STATE_CACHE_EXPIRY_TIME_MINUTES_SETTING,
526539
KNN_DISK_VECTOR_SHARD_LEVEL_RESCORING_DISABLED_SETTING
@@ -570,6 +583,15 @@ public static boolean isFaissAVX512Disabled() {
570583
);
571584
}
572585

586+
public static boolean isFaissAVX512SPRDisabled() {
587+
return Booleans.parseBoolean(
588+
Objects.requireNonNullElse(
589+
KNNSettings.state().getSettingValue(KNNSettings.KNN_FAISS_AVX512_SPR_DISABLED),
590+
KNN_DEFAULT_FAISS_AVX512_SPR_DISABLED_VALUE
591+
).toString()
592+
);
593+
}
594+
573595
public static Integer getFilteredExactSearchThreshold(final String indexName) {
574596
return KNNSettings.state().clusterService.state()
575597
.getMetadata()

src/main/java/org/opensearch/knn/jni/FaissService.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323

2424
import static org.opensearch.knn.index.KNNSettings.isFaissAVX2Disabled;
2525
import static org.opensearch.knn.index.KNNSettings.isFaissAVX512Disabled;
26+
import static org.opensearch.knn.index.KNNSettings.isFaissAVX512SPRDisabled;
2627
import static org.opensearch.knn.jni.PlatformUtils.isAVX2SupportedBySystem;
2728
import static org.opensearch.knn.jni.PlatformUtils.isAVX512SupportedBySystem;
29+
import static org.opensearch.knn.jni.PlatformUtils.isAVX512SPRSupportedBySystem;
2830

2931
/**
3032
* Service to interact with faiss jni layer. Class dependencies should be minimal
@@ -40,8 +42,11 @@ class FaissService {
4042
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
4143

4244
// Even if the underlying system supports AVX512 and AVX2, users can override and disable it by setting
43-
// 'knn.faiss.avx2.disabled' or 'knn.faiss.avx512.disabled' to true in the opensearch.yml configuration
44-
if (!isFaissAVX512Disabled() && isAVX512SupportedBySystem()) {
45+
// 'knn.faiss.avx2.disabled', 'knn.faiss.avx512.disabled', or 'knn.faiss.avx512_spr.disabled' to true in the opensearch.yml
46+
// configuration
47+
if (!isFaissAVX512SPRDisabled() && isAVX512SPRSupportedBySystem()) {
48+
System.loadLibrary(KNNConstants.FAISS_AVX512_SPR_JNI_LIBRARY_NAME);
49+
} else if (!isFaissAVX512Disabled() && isAVX512SupportedBySystem()) {
4550
System.loadLibrary(KNNConstants.FAISS_AVX512_JNI_LIBRARY_NAME);
4651
} else if (!isFaissAVX2Disabled() && isAVX2SupportedBySystem()) {
4752
System.loadLibrary(KNNConstants.FAISS_AVX2_JNI_LIBRARY_NAME);

0 commit comments

Comments
 (0)