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
cqy123456 2020-08-19 20:35:43 +08:00 committed by GitHub
parent 68a2918c30
commit 17ad160e4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 8 deletions

View File

@ -58,7 +58,7 @@ BinaryIDMAP::Query(const DatasetPtr& dataset_ptr, const Config& config) {
auto ret_ds = std::make_shared<Dataset>();
if (index_->metric_type == faiss::METRIC_Hamming) {
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++) {
*(pf_dist + i) = (float)(*(pi_dist + i));
}

View File

@ -64,7 +64,7 @@ BinaryIVF::Query(const DatasetPtr& dataset_ptr, const Config& config) {
auto ret_ds = std::make_shared<Dataset>();
if (index_->metric_type == faiss::METRIC_Hamming) {
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++) {
*(pf_dist + i) = (float)(*(pi_dist + i));
}

View File

@ -114,9 +114,9 @@ NSG::Train(const DatasetPtr& dataset_ptr, const Config& config) {
idmap->AddWithoutIds(dataset_ptr, config);
impl::Graph knng;
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>();
#ifdef MILVUS_GPU_VERSION
const int64_t device_id = config[knowhere::meta::DEVICEID].get<int64_t>();
if (device_id == -1) {
auto preprocess_index = std::make_shared<IVF>();
preprocess_index->Train(dataset_ptr, config);

View File

@ -47,7 +47,9 @@ namespace knowhere {
VecIndexPtr
VecIndexFactory::CreateVecIndex(const IndexType& type, const IndexMode mode) {
#ifdef MILVUS_GPU_VERSION
auto gpu_device = -1; // TODO: remove hardcode here, get from invoker
#endif
if (type == IndexEnum::INDEX_FAISS_IDMAP) {
return std::make_shared<knowhere::IDMAP>();
} else if (type == IndexEnum::INDEX_FAISS_IVFFLAT) {

View File

@ -53,7 +53,8 @@ GPUIVF::Train(const DatasetPtr& dataset_ptr, const Config& config) {
void
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_);
IVF::Add(dataset_ptr, config);
} else {
@ -65,7 +66,8 @@ VecIndexPtr
GPUIVF::CopyGpuToCpu(const Config& config) {
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* host_index = faiss::gpu::index_gpu_to_cpu(device_index);

View File

@ -54,7 +54,8 @@ GPUIVF_NM::Train(const DatasetPtr& dataset_ptr, const Config& config) {
void
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_);
IVF::Add(dataset_ptr, config);
} else {
@ -71,7 +72,8 @@ VecIndexPtr
GPUIVF_NM::CopyGpuToCpu(const Config& config) {
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* host_index = faiss::gpu::index_gpu_to_cpu_without_codes(device_index);

View File

@ -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 = {
{MODE_CPU, "MODE_CPU"}, {MODE_MIX, "MODE_MIX"}, {MODE_GPU, "MODE_GPU"}};
double copy_time = 0.0;
faiss::Index *gpu_index = nullptr, *index = nullptr;
if (query_mode != MODE_CPU) {
faiss::gpu::GpuClonerOptions option;
option.allInGpu = true;
double copy_time = 0.0;
faiss::IndexComposition index_composition;
index_composition.index = cpu_index;