mirror of https://github.com/milvus-io/milvus.git
Master codacy v3 (#3322)
* codacy fix Signed-off-by: cqy <yaya645@126.com> * codacy Signed-off-by: cqy <yaya645@126.com> * codacy Signed-off-by: cqy <yaya645@126.com> * codacy check Signed-off-by: cqy <yaya645@126.com> * codacy Signed-off-by: cqy <yaya645@126.com> * codacy Signed-off-by: cqy <yaya645@126.com>pull/3342/head
parent
68a2918c30
commit
17ad160e4c
|
@ -58,7 +58,7 @@ BinaryIDMAP::Query(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
auto ret_ds = std::make_shared<Dataset>();
|
auto ret_ds = std::make_shared<Dataset>();
|
||||||
if (index_->metric_type == faiss::METRIC_Hamming) {
|
if (index_->metric_type == faiss::METRIC_Hamming) {
|
||||||
auto pf_dist = (float*)malloc(p_dist_size);
|
auto pf_dist = (float*)malloc(p_dist_size);
|
||||||
int32_t* pi_dist = (int32_t*)p_dist;
|
int32_t* pi_dist = reinterpret_cast<int32_t*>(p_dist);
|
||||||
for (int i = 0; i < elems; i++) {
|
for (int i = 0; i < elems; i++) {
|
||||||
*(pf_dist + i) = (float)(*(pi_dist + i));
|
*(pf_dist + i) = (float)(*(pi_dist + i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ BinaryIVF::Query(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
auto ret_ds = std::make_shared<Dataset>();
|
auto ret_ds = std::make_shared<Dataset>();
|
||||||
if (index_->metric_type == faiss::METRIC_Hamming) {
|
if (index_->metric_type == faiss::METRIC_Hamming) {
|
||||||
auto pf_dist = (float*)malloc(p_dist_size);
|
auto pf_dist = (float*)malloc(p_dist_size);
|
||||||
int32_t* pi_dist = (int32_t*)p_dist;
|
int32_t* pi_dist = reinterpret_cast<int32_t*>(p_dist);
|
||||||
for (int i = 0; i < elems; i++) {
|
for (int i = 0; i < elems; i++) {
|
||||||
*(pf_dist + i) = (float)(*(pi_dist + i));
|
*(pf_dist + i) = (float)(*(pi_dist + i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,9 +114,9 @@ NSG::Train(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
idmap->AddWithoutIds(dataset_ptr, config);
|
idmap->AddWithoutIds(dataset_ptr, config);
|
||||||
impl::Graph knng;
|
impl::Graph knng;
|
||||||
const float* raw_data = idmap->GetRawVectors();
|
const float* raw_data = idmap->GetRawVectors();
|
||||||
const int64_t device_id = config[knowhere::meta::DEVICEID].get<int64_t>();
|
|
||||||
const int64_t k = config[IndexParams::knng].get<int64_t>();
|
const int64_t k = config[IndexParams::knng].get<int64_t>();
|
||||||
#ifdef MILVUS_GPU_VERSION
|
#ifdef MILVUS_GPU_VERSION
|
||||||
|
const int64_t device_id = config[knowhere::meta::DEVICEID].get<int64_t>();
|
||||||
if (device_id == -1) {
|
if (device_id == -1) {
|
||||||
auto preprocess_index = std::make_shared<IVF>();
|
auto preprocess_index = std::make_shared<IVF>();
|
||||||
preprocess_index->Train(dataset_ptr, config);
|
preprocess_index->Train(dataset_ptr, config);
|
||||||
|
|
|
@ -47,7 +47,9 @@ namespace knowhere {
|
||||||
|
|
||||||
VecIndexPtr
|
VecIndexPtr
|
||||||
VecIndexFactory::CreateVecIndex(const IndexType& type, const IndexMode mode) {
|
VecIndexFactory::CreateVecIndex(const IndexType& type, const IndexMode mode) {
|
||||||
|
#ifdef MILVUS_GPU_VERSION
|
||||||
auto gpu_device = -1; // TODO: remove hardcode here, get from invoker
|
auto gpu_device = -1; // TODO: remove hardcode here, get from invoker
|
||||||
|
#endif
|
||||||
if (type == IndexEnum::INDEX_FAISS_IDMAP) {
|
if (type == IndexEnum::INDEX_FAISS_IDMAP) {
|
||||||
return std::make_shared<knowhere::IDMAP>();
|
return std::make_shared<knowhere::IDMAP>();
|
||||||
} else if (type == IndexEnum::INDEX_FAISS_IVFFLAT) {
|
} else if (type == IndexEnum::INDEX_FAISS_IVFFLAT) {
|
||||||
|
|
|
@ -53,7 +53,8 @@ GPUIVF::Train(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
|
|
||||||
void
|
void
|
||||||
GPUIVF::Add(const DatasetPtr& dataset_ptr, const Config& config) {
|
GPUIVF::Add(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
if (auto spt = res_.lock()) {
|
auto spt = res_.lock();
|
||||||
|
if (spt != nullptr) {
|
||||||
ResScope rs(res_, gpu_id_);
|
ResScope rs(res_, gpu_id_);
|
||||||
IVF::Add(dataset_ptr, config);
|
IVF::Add(dataset_ptr, config);
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,7 +66,8 @@ VecIndexPtr
|
||||||
GPUIVF::CopyGpuToCpu(const Config& config) {
|
GPUIVF::CopyGpuToCpu(const Config& config) {
|
||||||
std::lock_guard<std::mutex> lk(mutex_);
|
std::lock_guard<std::mutex> lk(mutex_);
|
||||||
|
|
||||||
if (auto device_idx = std::dynamic_pointer_cast<faiss::gpu::GpuIndexIVF>(index_)) {
|
auto device_idx = std::dynamic_pointer_cast<faiss::gpu::GpuIndexIVF>(index_);
|
||||||
|
if (device_idx != nullptr) {
|
||||||
faiss::Index* device_index = index_.get();
|
faiss::Index* device_index = index_.get();
|
||||||
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu(device_index);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,8 @@ GPUIVF_NM::Train(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
|
|
||||||
void
|
void
|
||||||
GPUIVF_NM::Add(const DatasetPtr& dataset_ptr, const Config& config) {
|
GPUIVF_NM::Add(const DatasetPtr& dataset_ptr, const Config& config) {
|
||||||
if (auto spt = res_.lock()) {
|
auto spt = res_.lock();
|
||||||
|
if (spt != nullptr) {
|
||||||
ResScope rs(res_, gpu_id_);
|
ResScope rs(res_, gpu_id_);
|
||||||
IVF::Add(dataset_ptr, config);
|
IVF::Add(dataset_ptr, config);
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,7 +72,8 @@ VecIndexPtr
|
||||||
GPUIVF_NM::CopyGpuToCpu(const Config& config) {
|
GPUIVF_NM::CopyGpuToCpu(const Config& config) {
|
||||||
std::lock_guard<std::mutex> lk(mutex_);
|
std::lock_guard<std::mutex> lk(mutex_);
|
||||||
|
|
||||||
if (auto device_idx = std::dynamic_pointer_cast<faiss::gpu::GpuIndexIVF>(index_)) {
|
auto device_idx = std::dynamic_pointer_cast<faiss::gpu::GpuIndexIVF>(index_);
|
||||||
|
if (device_idx != nullptr) {
|
||||||
faiss::Index* device_index = index_.get();
|
faiss::Index* device_index = index_.get();
|
||||||
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu_without_codes(device_index);
|
faiss::Index* host_index = faiss::gpu::index_gpu_to_cpu_without_codes(device_index);
|
||||||
|
|
||||||
|
|
|
@ -346,11 +346,11 @@ test_with_nprobes(const std::string& ann_test_name, const std::string& index_key
|
||||||
std::unordered_map<int32_t, std::string> mode_str_map = {
|
std::unordered_map<int32_t, std::string> mode_str_map = {
|
||||||
{MODE_CPU, "MODE_CPU"}, {MODE_MIX, "MODE_MIX"}, {MODE_GPU, "MODE_GPU"}};
|
{MODE_CPU, "MODE_CPU"}, {MODE_MIX, "MODE_MIX"}, {MODE_GPU, "MODE_GPU"}};
|
||||||
|
|
||||||
double copy_time = 0.0;
|
|
||||||
faiss::Index *gpu_index = nullptr, *index = nullptr;
|
faiss::Index *gpu_index = nullptr, *index = nullptr;
|
||||||
if (query_mode != MODE_CPU) {
|
if (query_mode != MODE_CPU) {
|
||||||
faiss::gpu::GpuClonerOptions option;
|
faiss::gpu::GpuClonerOptions option;
|
||||||
option.allInGpu = true;
|
option.allInGpu = true;
|
||||||
|
double copy_time = 0.0;
|
||||||
|
|
||||||
faiss::IndexComposition index_composition;
|
faiss::IndexComposition index_composition;
|
||||||
index_composition.index = cpu_index;
|
index_composition.index = cpu_index;
|
||||||
|
|
Loading…
Reference in New Issue