mirror of https://github.com/milvus-io/milvus.git
Initialize the simd type when initialize an indexnode (#8276)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>pull/8310/head
parent
77e88144fc
commit
78fe530d87
|
@ -33,3 +33,4 @@ add_subdirectory( cache )
|
|||
add_subdirectory( query )
|
||||
add_subdirectory( common )
|
||||
add_subdirectory( indexbuilder )
|
||||
add_subdirectory( config )
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
# or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
set(CONFIG_SRC
|
||||
ConfigKnowhere.cpp
|
||||
)
|
||||
|
||||
add_library(milvus_config
|
||||
${CONFIG_SRC}
|
||||
)
|
||||
target_link_libraries(milvus_config
|
||||
milvus_proto
|
||||
milvus_utils
|
||||
knowhere
|
||||
)
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include <mutex>
|
||||
#include "exceptions/EasyAssert.h"
|
||||
#include "knowhere/archive/KnowhereConfig.h"
|
||||
#include "easyloggingpp/easylogging++.h"
|
||||
#include "ConfigKnowhere.h"
|
||||
|
||||
namespace milvus {
|
||||
namespace config {
|
||||
|
||||
std::once_flag init_knowhere_once_;
|
||||
|
||||
void
|
||||
KnowhereInitImpl() {
|
||||
auto init = []() {
|
||||
namespace eg = milvus::engine;
|
||||
eg::KnowhereConfig::SetSimdType(eg::KnowhereConfig::SimdType::AUTO);
|
||||
eg::KnowhereConfig::SetBlasThreshold(16384);
|
||||
eg::KnowhereConfig::SetEarlyStopThreshold(0);
|
||||
eg::KnowhereConfig::SetLogHandler();
|
||||
eg::KnowhereConfig::SetStatisticsLevel(0);
|
||||
el::Configurations el_conf;
|
||||
el_conf.setGlobally(el::ConfigurationType::Enabled, std::to_string(false));
|
||||
};
|
||||
|
||||
std::call_once(init_knowhere_once_, init);
|
||||
}
|
||||
|
||||
void
|
||||
KnowhereSetSimdType(const char* value) {
|
||||
milvus::engine::KnowhereConfig::SimdType simd_type;
|
||||
if (strcmp(value, "auto") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AUTO;
|
||||
} else if (strcmp(value, "avx512") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AVX512;
|
||||
} else if (strcmp(value, "avx2") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AVX2;
|
||||
} else if (strcmp(value, "sse") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::SSE;
|
||||
} else {
|
||||
PanicInfo("invalid SIMD type: " + std::string(value));
|
||||
}
|
||||
milvus::engine::KnowhereConfig::SetSimdType(simd_type);
|
||||
}
|
||||
|
||||
} // namespace config
|
||||
} // namespace milvus
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace milvus::config {
|
||||
|
||||
void
|
||||
KnowhereInitImpl();
|
||||
|
||||
void
|
||||
KnowhereSetSimdType(const char*);
|
||||
|
||||
} // namespace milvus::config
|
|
@ -12,15 +12,23 @@
|
|||
|
||||
set(INDEXBUILDER_FILES
|
||||
IndexWrapper.cpp
|
||||
index_c.cpp)
|
||||
index_c.cpp
|
||||
init_c.cpp
|
||||
)
|
||||
add_library(milvus_indexbuilder SHARED
|
||||
${INDEXBUILDER_FILES}
|
||||
)
|
||||
|
||||
# link order matters
|
||||
target_link_libraries(milvus_indexbuilder
|
||||
tbb milvus_utils pthread knowhere log milvus_proto
|
||||
dl
|
||||
milvus_config
|
||||
milvus_common
|
||||
milvus_query
|
||||
milvus_utils
|
||||
milvus_proto
|
||||
knowhere
|
||||
tbb
|
||||
log
|
||||
dl
|
||||
pthread
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include "config/ConfigKnowhere.h"
|
||||
#include "indexbuilder/init_c.h"
|
||||
|
||||
void
|
||||
IndexBuilderInit() {
|
||||
milvus::config::KnowhereInitImpl();
|
||||
}
|
||||
|
||||
void
|
||||
IndexBuilderSetSimdType(const char* value) {
|
||||
milvus::config::KnowhereSetSimdType(value);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
IndexBuilderInit();
|
||||
|
||||
void
|
||||
IndexBuilderSetSimdType(const char*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
|
@ -41,5 +41,6 @@ target_link_libraries(milvus_segcore
|
|||
milvus_query
|
||||
milvus_utils
|
||||
milvus_storage
|
||||
milvus_config
|
||||
)
|
||||
|
||||
|
|
|
@ -11,28 +11,15 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "exceptions/EasyAssert.h"
|
||||
#include "knowhere/archive/KnowhereConfig.h"
|
||||
#include "segcore/segcore_init_c.h"
|
||||
#include "segcore/SegcoreConfig.h"
|
||||
#include "utils/Log.h"
|
||||
#include "config/ConfigKnowhere.h"
|
||||
|
||||
namespace milvus::segcore {
|
||||
static void
|
||||
SegcoreInitImpl() {
|
||||
namespace eg = milvus::engine;
|
||||
eg::KnowhereConfig::SetSimdType(eg::KnowhereConfig::SimdType::AUTO);
|
||||
eg::KnowhereConfig::SetBlasThreshold(16384);
|
||||
eg::KnowhereConfig::SetEarlyStopThreshold(0);
|
||||
eg::KnowhereConfig::SetLogHandler();
|
||||
eg::KnowhereConfig::SetStatisticsLevel(0);
|
||||
el::Configurations el_conf;
|
||||
el_conf.setGlobally(el::ConfigurationType::Enabled, std::to_string(false));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
SegcoreInit() {
|
||||
milvus::segcore::SegcoreInitImpl();
|
||||
milvus::config::KnowhereInitImpl();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
|
@ -44,20 +31,8 @@ SegcoreSetChunkRows(const int64_t value) {
|
|||
|
||||
extern "C" void
|
||||
SegcoreSetSimdType(const char* value) {
|
||||
milvus::engine::KnowhereConfig::SimdType simd_type;
|
||||
if (strcmp(value, "auto") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AUTO;
|
||||
} else if (strcmp(value, "avx512") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AVX512;
|
||||
} else if (strcmp(value, "avx2") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::AVX2;
|
||||
} else if (strcmp(value, "sse") == 0) {
|
||||
simd_type = milvus::engine::KnowhereConfig::SimdType::SSE;
|
||||
} else {
|
||||
PanicInfo("invalid SIMD type: " + std::string(value));
|
||||
}
|
||||
milvus::engine::KnowhereConfig::SetSimdType(simd_type);
|
||||
LOG_SEGCORE_DEBUG_ << "set config simd_type: " << int(simd_type);
|
||||
milvus::config::KnowhereSetSimdType(value);
|
||||
LOG_SEGCORE_DEBUG_ << "set config simd_type: " << value;
|
||||
}
|
||||
|
||||
} // namespace milvus::segcore
|
||||
|
|
|
@ -11,6 +11,17 @@
|
|||
|
||||
package indexnode
|
||||
|
||||
/*
|
||||
|
||||
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
||||
|
||||
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_indexbuilder -Wl,-rpath=${SRCDIR}/../core/output/lib
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "indexbuilder/init_c.h"
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
@ -19,6 +30,7 @@ import (
|
|||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
||||
|
||||
|
@ -90,6 +102,15 @@ func (i *IndexNode) Register() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (i *IndexNode) initKnowhere() {
|
||||
C.IndexBuilderInit()
|
||||
|
||||
// override segcore SIMD type
|
||||
cSimdType := C.CString(Params.SimdType)
|
||||
C.IndexBuilderSetSimdType(cSimdType)
|
||||
C.free(unsafe.Pointer(cSimdType))
|
||||
}
|
||||
|
||||
func (i *IndexNode) Init() error {
|
||||
Params.Init()
|
||||
i.UpdateStateCode(internalpb.StateCode_Initializing)
|
||||
|
@ -121,6 +142,9 @@ func (i *IndexNode) Init() error {
|
|||
}
|
||||
log.Debug("IndexNode NewMinIOKV success")
|
||||
i.closer = trace.InitTracing("index_node")
|
||||
|
||||
i.initKnowhere()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/log"
|
||||
"github.com/milvus-io/milvus/internal/util/paramtable"
|
||||
)
|
||||
|
@ -45,6 +47,8 @@ type ParamTable struct {
|
|||
MinIOUseSSL bool
|
||||
MinioBucketName string
|
||||
|
||||
SimdType string
|
||||
|
||||
Log log.Config
|
||||
}
|
||||
|
||||
|
@ -58,8 +62,12 @@ func (pt *ParamTable) InitAlias(alias string) {
|
|||
func (pt *ParamTable) Init() {
|
||||
once.Do(func() {
|
||||
pt.BaseTable.Init()
|
||||
if err := pt.LoadYaml("advanced/knowhere.yaml"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pt.initLogCfg()
|
||||
pt.initParams()
|
||||
pt.initKnowhereSimdType()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -161,3 +169,18 @@ func (pt *ParamTable) initLogCfg() {
|
|||
pt.Log.File.Filename = ""
|
||||
}
|
||||
}
|
||||
|
||||
func (pt *ParamTable) initKnowhereSimdType() {
|
||||
simdType, err := pt.LoadWithDefault("knowhere.simdType", "auto")
|
||||
if err != nil {
|
||||
log.Error("failed to initialize the simd type",
|
||||
zap.Error(err))
|
||||
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pt.SimdType = simdType
|
||||
|
||||
log.Debug("initialize the knowhere simd type",
|
||||
zap.String("simd_type", pt.SimdType))
|
||||
}
|
||||
|
|
|
@ -65,6 +65,12 @@ func TestParamTable(t *testing.T) {
|
|||
t.Run("MinioBucketName", func(t *testing.T) {
|
||||
t.Logf("MinioBucketName: %v", Params.MinioBucketName)
|
||||
})
|
||||
|
||||
t.Run("SimdType", func(t *testing.T) {
|
||||
t.Logf("SimdType: %v", Params.SimdType)
|
||||
})
|
||||
|
||||
// FIXME(dragondriver): how to cover panic case? we use `LoadWithDefault` to initialize `SimdType`
|
||||
}
|
||||
|
||||
//TODO: Params Load should be return error when key does not exist.
|
||||
|
|
Loading…
Reference in New Issue