diff --git a/Makefile b/Makefile index 34d04590c5..86dee2acfe 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,13 @@ milvus: build-cpp print-build-info GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \ ${AARCH64_FLAG} -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null +milvus-gpu: build-cpp-gpu print-build-info + @echo "Building Milvus-gpu ..." + @source $(PWD)/scripts/setenv.sh && \ + mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \ + GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \ + ${AARCH64_FLAG} -o $(INSTALL_PATH)/milvus-gpu $(PWD)/cmd/main.go 1>/dev/null + get-build-deps: @(env bash $(PWD)/scripts/install_deps.sh) @@ -155,6 +162,10 @@ build-cpp: download-milvus-proto @echo "Building Milvus cpp library ..." @(env bash $(PWD)/scripts/core_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index}) +build-cpp-gpu: download-milvus-proto + @echo "Building Milvus cpp gpu library ..." + @(env bash $(PWD)/scripts/core_build.sh -t ${mode} -g -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index}) + build-cpp-embd: download-milvus-proto @echo "Building **Embedded** Milvus cpp library ..." @(env bash $(PWD)/scripts/core_build.sh -b -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index}) diff --git a/internal/core/CMakeLists.txt b/internal/core/CMakeLists.txt index 3fa1eb2006..7de3328fd8 100644 --- a/internal/core/CMakeLists.txt +++ b/internal/core/CMakeLists.txt @@ -25,6 +25,10 @@ add_definitions(-DELPP_THREAD_SAFE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) message( STATUS "Building using CMake version: ${CMAKE_VERSION}" ) +if ( MILVUS_GPU_VERSION ) + add_definitions(-DMILVUS_GPU_VERSION) +endif () + project(core) include(CheckCXXCompilerFlag) if ( APPLE ) diff --git a/internal/core/src/config/ConfigKnowhere.cpp b/internal/core/src/config/ConfigKnowhere.cpp index b069edeb2e..6974997c8b 100644 --- a/internal/core/src/config/ConfigKnowhere.cpp +++ b/internal/core/src/config/ConfigKnowhere.cpp @@ -77,6 +77,13 @@ KnowhereSetSimdType(const char* value) { } } +void +KnowhereInitGPU(const int32_t gpu_id, const int32_t res_num) { +#ifdef MILVUS_GPU_VERSION + knowhere::KnowhereConfig::InitGPUResource(gpu_id, res_num); +#endif +} + void KnowhereInitThreadPool(const uint32_t num_threads) { knowhere::ThreadPool::InitGlobalThreadPool(num_threads); diff --git a/internal/core/src/config/ConfigKnowhere.h b/internal/core/src/config/ConfigKnowhere.h index 1a45646ea6..c5c906222b 100644 --- a/internal/core/src/config/ConfigKnowhere.h +++ b/internal/core/src/config/ConfigKnowhere.h @@ -25,6 +25,9 @@ KnowhereInitImpl(const char*); std::string KnowhereSetSimdType(const char*); +void +KnowhereInitGPU(const int32_t, const int32_t); + void KnowhereInitThreadPool(const uint32_t); diff --git a/internal/core/src/indexbuilder/init_c.cpp b/internal/core/src/indexbuilder/init_c.cpp index 0ed371dc47..42ef166363 100644 --- a/internal/core/src/indexbuilder/init_c.cpp +++ b/internal/core/src/indexbuilder/init_c.cpp @@ -27,3 +27,8 @@ IndexBuilderSetSimdType(const char* value) { ret[real_type.length()] = 0; return ret; } + +void +IndexBuilderInitGPU(const int32_t gpu_id, const int32_t res_num) { + milvus::config::KnowhereInitGPU(gpu_id, res_num); +} \ No newline at end of file diff --git a/internal/core/src/indexbuilder/init_c.h b/internal/core/src/indexbuilder/init_c.h index b22f1ca04f..e66699f803 100644 --- a/internal/core/src/indexbuilder/init_c.h +++ b/internal/core/src/indexbuilder/init_c.h @@ -22,6 +22,9 @@ IndexBuilderInit(const char*); char* IndexBuilderSetSimdType(const char*); +void +IndexBuilderInitGPU(const int32_t, const int32_t); + #ifdef __cplusplus }; #endif diff --git a/internal/core/src/segcore/segcore_init_c.cpp b/internal/core/src/segcore/segcore_init_c.cpp index b79c247bb5..c3eed68eea 100644 --- a/internal/core/src/segcore/segcore_init_c.cpp +++ b/internal/core/src/segcore/segcore_init_c.cpp @@ -58,4 +58,9 @@ SegcoreSetSimdType(const char* value) { return ret; } +extern "C" void +SegcoreInitGPU(const int32_t gpu_id, const int32_t res_num) { + milvus::config::KnowhereInitGPU(gpu_id, res_num); +} + } // namespace milvus::segcore diff --git a/internal/core/src/segcore/segcore_init_c.h b/internal/core/src/segcore/segcore_init_c.h index b16daf8a0c..79a6a2a5d8 100644 --- a/internal/core/src/segcore/segcore_init_c.h +++ b/internal/core/src/segcore/segcore_init_c.h @@ -31,6 +31,9 @@ SegcoreSetNprobe(const int64_t); char* SegcoreSetSimdType(const char*); +void +SegcoreInitGPU(const int32_t, const int32_t); + void SegcoreSetThreadPoolNum(const uint32_t num_threads); diff --git a/internal/core/thirdparty/CMakeLists.txt b/internal/core/thirdparty/CMakeLists.txt index b9b708a9ff..a82dec0d54 100644 --- a/internal/core/thirdparty/CMakeLists.txt +++ b/internal/core/thirdparty/CMakeLists.txt @@ -12,7 +12,7 @@ #------------------------------------------------------------------------------- # Using default c and cxx compiler in our build tree # Thirdpart cxx and c flags -add_compile_options(-O3 -fPIC -Wno-error -fopenmp) +append_flags(CMAKE_CXX_FLAGS FLAGS "-O3 -fPIC -Wno-error -fopenmp") if (NOT KNOWHERE_VERBOSE_THIRDPARTY_BUILD) set(EP_LOG_OPTIONS LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 LOG_DOWNLOAD 1) diff --git a/internal/core/thirdparty/knowhere/CMakeLists.txt b/internal/core/thirdparty/knowhere/CMakeLists.txt index 04d8bf0460..3d3563816c 100644 --- a/internal/core/thirdparty/knowhere/CMakeLists.txt +++ b/internal/core/thirdparty/knowhere/CMakeLists.txt @@ -22,6 +22,10 @@ else () set(WITH_DISKANN OFF CACHE BOOL "" FORCE ) endif () +if ( MILVUS_GPU_VERSION STREQUAL "ON" ) + set(USE_CUDA ON CACHE BOOL "" FORCE ) +endif () + set( CMAKE_PREFIX_PATH ${CONAN_BOOST_ROOT} ) FetchContent_Declare( knowhere diff --git a/internal/core/unittest/test_utils/indexbuilder_test_utils.h b/internal/core/unittest/test_utils/indexbuilder_test_utils.h index 598b47eaa7..146320381c 100644 --- a/internal/core/unittest/test_utils/indexbuilder_test_utils.h +++ b/internal/core/unittest/test_utils/indexbuilder_test_utils.h @@ -32,9 +32,6 @@ constexpr int64_t DIM = 16; constexpr int64_t NQ = 10; constexpr int64_t K = 4; -#ifdef MILVUS_GPU_VERSION -int DEVICEID = 0; -#endif namespace indexcgo = milvus::proto::indexcgo; namespace schemapb = milvus::proto::schema; diff --git a/internal/indexnode/indexnode.go b/internal/indexnode/indexnode.go index 8d0b98fa3c..ce55ca1b4a 100644 --- a/internal/indexnode/indexnode.go +++ b/internal/indexnode/indexnode.go @@ -156,6 +156,11 @@ func (i *IndexNode) initKnowhere() { cCPUNum := C.int(hardware.GetCPUNum()) C.InitCpuNum(cCPUNum) + // init GPU resource + cGpuId := C.int32_t(0) + cResNum := C.int32_t(1) + C.IndexBuilderInitGPU(cGpuId, cResNum) + initcore.InitLocalStorageConfig(Params) } diff --git a/internal/querynode/query_node.go b/internal/querynode/query_node.go index 4d55127832..55b86d560f 100644 --- a/internal/querynode/query_node.go +++ b/internal/querynode/query_node.go @@ -232,6 +232,11 @@ func (node *QueryNode) InitSegcore() { cCPUNum := C.int(hardware.GetCPUNum()) C.InitCpuNum(cCPUNum) + // init GPU resource + cGpuId := C.int32_t(0) + cResNum := C.int32_t(1) + C.SegcoreInitGPU(cGpuId, cResNum) + initcore.InitLocalStorageConfig(Params) mmapDirPath := paramtable.Get().QueryNodeCfg.MmapDirPath.GetValue() diff --git a/internal/util/indexparamcheck/conf_adapter_mgr.go b/internal/util/indexparamcheck/conf_adapter_mgr.go index 8776c32fee..c415d5ba02 100644 --- a/internal/util/indexparamcheck/conf_adapter_mgr.go +++ b/internal/util/indexparamcheck/conf_adapter_mgr.go @@ -46,6 +46,12 @@ func (mgr *ConfAdapterMgrImpl) GetAdapter(indexType string) (ConfAdapter, error) } func (mgr *ConfAdapterMgrImpl) registerConfAdapter() { + mgr.adapters[IndexFaissGPUIDMap] = newBaseConfAdapter() + mgr.adapters[IndexFaissGPUIvfFlat] = newIVFConfAdapter() + mgr.adapters[IndexFaissGPUIvfPQ] = newIVFPQConfAdapter() + mgr.adapters[IndexFaissGPUIvfSQ8] = newIVFSQConfAdapter() + mgr.adapters[IndexRaftIvfFlat] = newIVFConfAdapter() + mgr.adapters[IndexRaftIvfPQ] = newIVFPQConfAdapter() mgr.adapters[IndexFaissIDMap] = newBaseConfAdapter() mgr.adapters[IndexFaissIvfFlat] = newIVFConfAdapter() mgr.adapters[IndexFaissIvfPQ] = newIVFPQConfAdapter() diff --git a/internal/util/indexparamcheck/index_type.go b/internal/util/indexparamcheck/index_type.go index d71b2594f4..a4c747541a 100644 --- a/internal/util/indexparamcheck/index_type.go +++ b/internal/util/indexparamcheck/index_type.go @@ -16,6 +16,12 @@ type IndexType = string // IndexType definitions const ( + IndexFaissGPUIDMap IndexType = "GPU_FLAT" // no index is built. + IndexFaissGPUIvfFlat IndexType = "GPU_IVF_FLAT" + IndexFaissGPUIvfPQ IndexType = "GPU_IVF_PQ" + IndexFaissGPUIvfSQ8 IndexType = "GPU_IVF_SQ8" + IndexRaftIvfFlat IndexType = "RAFT_IVF_FLAT" + IndexRaftIvfPQ IndexType = "RAFT_IVF_PQ" IndexFaissIDMap IndexType = "FLAT" // no index is built. IndexFaissIvfFlat IndexType = "IVF_FLAT" IndexFaissIvfPQ IndexType = "IVF_PQ"