FaissIVFSQ8HPass.cpp 2.2 KB
Newer Older
S
starlord 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 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.

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() {
W
wxyu 已提交
32
    server::Config& config = server::Config::GetInstance();
33
    Status s = config.GetEngineConfigGpuSearchThreshold(threshold_);
W
wxyu 已提交
34
    if (!s.ok()) {
Y
yudong.cai 已提交
35
        threshold_ = std::numeric_limits<int64_t>::max();
W
wxyu 已提交
36
    }
37
    s = config.GetGpuResourceConfigSearchResources(gpus);
W
wxyu 已提交
38 39
}

X
xiaojun.lin 已提交
40
bool
F
fishpenguin 已提交
41
FaissIVFSQ8HPass::Run(const TaskPtr& task) {
X
xiaojun.lin 已提交
42 43 44 45 46 47 48 49 50 51
    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 已提交
52
    ResourcePtr res_ptr;
W
wxyu 已提交
53
    if (search_job->nq() < threshold_) {
F
fishpenguin 已提交
54 55 56 57 58
        res_ptr = ResMgrInst::GetInstance()->GetResource("cpu");
    } else {
        auto best_device_id = count_ % gpus.size();
        count_++;
        res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
X
xiaojun.lin 已提交
59
    }
F
fishpenguin 已提交
60
    auto label = std::make_shared<SpecResLabel>(res_ptr);
X
xiaojun.lin 已提交
61 62
    task->label() = label;
    return true;
X
xiaojun.lin 已提交
63
}
Y
Yu Kun 已提交
64 65 66

}  // namespace scheduler
}  // namespace milvus