Unverified Commit 316a5383 authored by Jin Hai's avatar Jin Hai Committed by GitHub
Browse files

Merge pull request #381 from tinkerlin/issue-247

fix by reduce knng size
parents a47b7284 82cb637c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -88,14 +88,14 @@ endif ()
include(ThirdPartyPackagesCore)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp -mavx -mf16c -msse4 -mpopcnt")
    if (KNOWHERE_GPU_VERSION)
        set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3")
    endif ()
else ()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE -fopenmp")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -fPIC -DELPP_THREAD_SAFE -fopenmp -mavx -mf16c -msse4 -mpopcnt")
    if (KNOWHERE_GPU_VERSION)
        set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O0 -g")
        set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3 -g")
    endif ()
endif ()

+14 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#pragma once

#include <memory>
#include <sstream>
#include "Log.h"

namespace knowhere {

@@ -50,6 +52,18 @@ struct Cfg {
    CheckValid() {
        return true;
    }

    void
    Dump() {
        KNOWHERE_LOG_DEBUG << DumpImpl().str();
    }

    virtual std::stringstream
    DumpImpl() {
        std::stringstream ss;
        ss << "dim: " << d << ", metric: " << int(metric_type) << ", gpuid: " << gpu_id << ", k: " << k;
        return ss;
    }
};
using Config = std::shared_ptr<Cfg>;

+22 −0
Original line number Diff line number Diff line
@@ -34,4 +34,26 @@ GetMetricType(METRICTYPE& type) {
    KNOWHERE_THROW_MSG("Metric type is invalid");
}

std::stringstream
IVFCfg::DumpImpl() {
    auto ss = Cfg::DumpImpl();
    ss << ", nlist: " << nlist << ", nprobe: " << nprobe;
    return ss;
}

std::stringstream
IVFSQCfg::DumpImpl() {
    auto ss = IVFCfg::DumpImpl();
    ss << ", nbits: " << nbits;
    return ss;
}

std::stringstream
NSGCfg::DumpImpl() {
    auto ss = IVFCfg::DumpImpl();
    ss << ", knng: " << knng << ", search_length: " << search_length << ", out_degree: " << out_degree
       << ", candidate: " << candidate_pool_size;
    return ss;
}

}  // namespace knowhere
+9 −0
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@ struct IVFCfg : public Cfg {

    IVFCfg() = default;

    std::stringstream
    DumpImpl() override;

    bool
    CheckValid() override {
        return true;
@@ -69,6 +72,9 @@ struct IVFSQCfg : public IVFCfg {
        : IVFCfg(dim, k, gpu_id, nlist, nprobe, type), nbits(nbits) {
    }

    std::stringstream
    DumpImpl() override;

    IVFSQCfg() = default;

    bool
@@ -119,6 +125,9 @@ struct NSGCfg : public IVFCfg {

    NSGCfg() = default;

    std::stringstream
    DumpImpl() override;

    bool
    CheckValid() override {
        return true;
+12 −15
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ ConfAdapter::Match(const TempMetaConf& metaconf) {
    auto conf = std::make_shared<knowhere::Cfg>();
    conf->d = metaconf.dim;
    conf->metric_type = metaconf.metric_type;
    conf->gpu_id = conf->gpu_id;
    conf->gpu_id = metaconf.gpu_id;
    conf->k = metaconf.k;
    MatchBase(conf);
    return conf;
}
@@ -65,7 +66,7 @@ IVFConfAdapter::Match(const TempMetaConf& metaconf) {
    conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
    conf->d = metaconf.dim;
    conf->metric_type = metaconf.metric_type;
    conf->gpu_id = conf->gpu_id;
    conf->gpu_id = metaconf.gpu_id;
    MatchBase(conf);
    return conf;
}
@@ -114,7 +115,7 @@ IVFSQConfAdapter::Match(const TempMetaConf& metaconf) {
    conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
    conf->d = metaconf.dim;
    conf->metric_type = metaconf.metric_type;
    conf->gpu_id = conf->gpu_id;
    conf->gpu_id = metaconf.gpu_id;
    conf->nbits = 8;
    MatchBase(conf);
    return conf;
@@ -126,7 +127,7 @@ IVFPQConfAdapter::Match(const TempMetaConf& metaconf) {
    conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
    conf->d = metaconf.dim;
    conf->metric_type = metaconf.metric_type;
    conf->gpu_id = conf->gpu_id;
    conf->gpu_id = metaconf.gpu_id;
    conf->nbits = 8;

    if (!(conf->d % 4))
@@ -175,21 +176,17 @@ NSGConfAdapter::Match(const TempMetaConf& metaconf) {
    conf->nlist = MatchNlist(metaconf.size, metaconf.nlist);
    conf->d = metaconf.dim;
    conf->metric_type = metaconf.metric_type;
    conf->gpu_id = conf->gpu_id;
    conf->gpu_id = metaconf.gpu_id;
    conf->k = metaconf.k;

    double factor = metaconf.size / TYPICAL_COUNT;
    auto scale_factor = round(metaconf.dim / 128.0);
    scale_factor = scale_factor >= 4 ? 4 : scale_factor;
    conf->nprobe = conf->nlist > 10000 ? conf->nlist * 0.02 : conf->nlist * 0.1;
    conf->knng = (100 + 100 * scale_factor) * factor;
    conf->search_length = (40 + 5 * scale_factor) * factor;
    conf->out_degree = (50 + 5 * scale_factor) * factor;
    conf->candidate_pool_size = (200 + 100 * scale_factor) * factor;
    conf->nprobe = int64_t(conf->nlist * 0.01);
    conf->knng = 40 + 10 * scale_factor;  // the size of knng
    conf->search_length = 40 + 5 * scale_factor;
    conf->out_degree = 50 + 5 * scale_factor;
    conf->candidate_pool_size = 200 + 100 * scale_factor;
    MatchBase(conf);

    //    WRAPPER_LOG_DEBUG << "nlist: " << conf->nlist
    //    << ", gpu_id: " << conf->gpu_id << ", d: " << conf->d
    //    << ", nprobe: " << conf->nprobe << ", knng: " << conf->knng;
    return conf;
}

Loading