Skip to content

Commit bf38c2e

Browse files
Parallelize make to reduce build time (#2006)
1 parent bbaaaf9 commit bf38c2e

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

.github/workflows/CI.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ jobs:
7676
if lscpu | grep -i avx2
7777
then
7878
echo "avx2 available on system"
79-
su `id -un 1000` -c "whoami && java -version && ./gradlew build"
79+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dnproc.count=`nproc`"
8080
else
8181
echo "avx2 not available on system"
82-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dsimd.enabled=false"
82+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dsimd.enabled=false -Dnproc.count=`nproc`"
8383
fi
8484
8585
@@ -117,15 +117,16 @@ jobs:
117117
brew reinstall gcc
118118
export FC=/usr/local/Cellar/gcc/12.2.0/bin/gfortran
119119
120+
# TODO: Detect processor count and set the value of nproc.count
120121
- name: Run build
121122
run: |
122123
if sysctl -n machdep.cpu.features machdep.cpu.leaf7_features | grep -i AVX2
123124
then
124125
echo "avx2 available on system"
125-
./gradlew build
126+
./gradlew build -Dnproc.count=3
126127
else
127128
echo "avx2 not available on system"
128-
./gradlew build -Dsimd.enabled=false
129+
./gradlew build -Dsimd.enabled=false -Dnproc.count=3
129130
fi
130131
131132
Build-k-NN-Windows:
@@ -183,6 +184,7 @@ jobs:
183184
rm .\OpenBLAS-0.3.21-x64.zip
184185
rm -r .\OpenBLAS\
185186
187+
# TODO: Detect processor count and set the value of nproc.count
186188
- name: Run build
187189
run: |
188-
./gradlew.bat build -D'simd.enabled=false'
190+
./gradlew.bat build -D'simd.enabled=false' -D'nproc.count=4'

.github/workflows/test_security.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
# switching the user, as OpenSearch cluster can only be started as root/Administrator on linux-deb/linux-rpm/windows-zip.
7171
run: |
7272
chown -R 1000:1000 `pwd`
73-
su `id -un 1000` -c "whoami && java -version && ./gradlew integTest -Dsecurity.enabled=true -Dsimd.enabled=true"
73+
su `id -un 1000` -c "whoami && java -version && ./gradlew integTest -Dsecurity.enabled=true -Dsimd.enabled=true -Dnproc.count=`nproc`"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2727
* Fix graph merge stats size calculation [#1844](https://github.com/opensearch-project/k-NN/pull/1844)
2828
* Disallow a vector field to have an invalid character for a physical file name. [#1936](https://github.com/opensearch-project/k-NN/pull/1936)
2929
### Infrastructure
30+
* Parallelize make to reduce build time [#2006] (https://github.com/opensearch-project/k-NN/pull/2006)
3031
### Documentation
3132
### Maintenance
3233
* Fix a flaky unit test:testMultiFieldsKnnIndex, which was failing due to inconsistent merge behaviors [#1924](https://github.com/opensearch-project/k-NN/pull/1924)

DEVELOPER_GUIDE.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Build](#build)
1212
- [JNI Library](#jni-library)
1313
- [JNI Library Artifacts](#jni-library-artifacts)
14+
- [Parallelize make](#parallelize-make)
1415
- [Enable SIMD Optimization](#enable-simd-optimization)
1516
- [Run OpenSearch k-NN](#run-opensearch-k-nn)
1617
- [Run Single-node Cluster Locally](#run-single-node-cluster-locally)
@@ -215,7 +216,7 @@ To build the JNI Library manually, follow these steps:
215216
cd jni
216217
cmake .
217218
218-
# To build everything, including tests
219+
# To build everything, including tests. If your computer has multiple cores you can speed it up by building in parallel using make -j 2 (or a higher number for more parallelism)
219220
make
220221
221222
# To just build the libraries
@@ -263,6 +264,23 @@ these in your environment, you can disable committing the changes to the library
263264
not committed, then the full library build process will run each time `cmake` is invoked. In a development environment,
264265
it is recommended to setup the user git configuration to avoid this cost.
265266
267+
### Parallelize make
268+
When we are building the plugin for the first time, it takes some time to build the JNI libraries. We can parallelize make and speed up the build time by setting and passing
269+
this flag to gradle, `nproc.count` if your computer has more number of cores (greater than or equal to 2).
270+
```
271+
# While building OpenSearch k-NN
272+
./gradlew build -Dnproc.count=4
273+
274+
# While running OpenSearch k-NN
275+
./gradlew run -Dnproc.count=4
276+
277+
# When building the JNI library manually
278+
cd jni
279+
cmake .
280+
# Pass the processor count with make using `-j`
281+
make -j 4
282+
```
283+
266284
### Enable SIMD Optimization
267285
SIMD(Single Instruction/Multiple Data) Optimization is enabled by default on Linux and Mac which boosts the performance
268286
by enabling `AVX2` on `x86 architecture` and `NEON` on `ARM64 architecture` while building the Faiss library. But to enable SIMD, the underlying processor

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ buildscript {
1818
opensearch_group = "org.opensearch"
1919
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
2020
simd_enabled = System.getProperty("simd.enabled", "true")
21+
nproc_count = System.getProperty("nproc.count", "1")
2122
// This flag determines whether the CMake build system should apply a custom patch. It prevents build failures
2223
// when the cmakeJniLib task is run multiple times. If the build.lib.commit_patches is true, the CMake build
2324
// system skips applying the patch if the patches have been applied already. If build.lib.commit_patches is
@@ -331,7 +332,7 @@ task cmakeJniLib(type:Exec) {
331332
task buildJniLib(type:Exec) {
332333
dependsOn cmakeJniLib
333334
workingDir 'jni'
334-
commandLine 'make', 'opensearchknn_nmslib', 'opensearchknn_faiss', 'opensearchknn_common'
335+
commandLine 'make', 'opensearchknn_nmslib', 'opensearchknn_faiss', 'opensearchknn_common', '-j', "${nproc_count}"
335336
}
336337

337338
test {

0 commit comments

Comments
 (0)