FaissIVFSQ8HPass.cpp 2.6 KB
Newer Older
S
starlord 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.
17
#ifdef MILVUS_GPU_VERSION
F
fishpenguin 已提交
18
#include "scheduler/optimizer/FaissIVFSQ8HPass.h"
Y
Yu Kun 已提交
19 20 21 22 23
#include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h"
#include "scheduler/Utils.h"
#include "scheduler/task/SearchTask.h"
#include "scheduler/tasklabel/SpecResLabel.h"
W
wxyu 已提交
24
#include "server/Config.h"
Y
Yu Kun 已提交
25 26 27 28 29
#include "utils/Log.h"

namespace milvus {
namespace scheduler {

30
void
F
fishpenguin 已提交
31
FaissIVFSQ8HPass::Init() {
32
#ifdef CUSTOMIZATION
W
wxyu 已提交
33
    server::Config& config = server::Config::GetInstance();
34
    Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
W
wxyu 已提交
35
    if (!s.ok()) {
Y
yudong.cai 已提交
36
        threshold_ = std::numeric_limits<int64_t>::max();
W
wxyu 已提交
37
    }
38
    s = config.GetGpuResourceConfigSearchResources(gpus);
G
groot 已提交
39
#endif
W
wxyu 已提交
40 41
}

X
xiaojun.lin 已提交
42
bool
F
fishpenguin 已提交
43
FaissIVFSQ8HPass::Run(const TaskPtr& task) {
44
#ifdef CUSTOMIZATION
X
xiaojun.lin 已提交
45 46 47 48 49 50 51 52 53 54
    if (task->Type() != TaskType::SearchTask) {
        return false;
    }

    auto search_task = std::static_pointer_cast<XSearchTask>(task);
    if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8H) {
        return false;
    }

    auto search_job = std::static_pointer_cast<SearchJob>(search_task->job_.lock());
F
fishpenguin 已提交
55
    ResourcePtr res_ptr;
W
wxyu 已提交
56
    if (search_job->nq() < threshold_) {
F
fishpenguin 已提交
57
        SERVER_LOG_DEBUG << "FaissIVFSQ8HPass: nq < gpu_search_threshold, specify cpu to search!";
F
fishpenguin 已提交
58 59 60
        res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
    } else {
        auto best_device_id = count_ % gpus.size();
F
fishpenguin 已提交
61 62
        SERVER_LOG_DEBUG << "FaissIVFSQ8HPass: nq > gpu_search_threshold, specify gpu" << best_device_id
                         << " to search!";
63
        ++count_;
F
fishpenguin 已提交
64
        res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, gpus[best_device_id]);
X
xiaojun.lin 已提交
65
    }
F
fishpenguin 已提交
66
    auto label = std::make_shared<SpecResLabel>(res_ptr);
X
xiaojun.lin 已提交
67 68
    task->label() = label;
    return true;
69
#endif
X
xiaojun.lin 已提交
70
}
Y
Yu Kun 已提交
71 72 73

}  // namespace scheduler
}  // namespace milvus
74
#endif