SchedInst.cpp 3.2 KB
Newer Older
J
jinhai 已提交
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.

S
starlord 已提交
18
#include "scheduler/SchedInst.h"
W
wxyu 已提交
19
#include "ResourceFactory.h"
W
wxyu 已提交
20
#include "Utils.h"
S
starlord 已提交
21 22
#include "knowhere/index/vector_index/IndexGPUIVF.h"
#include "server/Config.h"
W
wxyu 已提交
23

S
starlord 已提交
24 25
#include <set>
#include <string>
S
starlord 已提交
26 27
#include <utility>
#include <vector>
28 29

namespace milvus {
W
wxyu 已提交
30
namespace scheduler {
31 32 33 34 35 36 37

ResourceMgrPtr ResMgrInst::instance = nullptr;
std::mutex ResMgrInst::mutex_;

SchedulerPtr SchedInst::instance = nullptr;
std::mutex SchedInst::mutex_;

W
wxyu 已提交
38 39 40
scheduler::JobMgrPtr JobMgrInst::instance = nullptr;
std::mutex JobMgrInst::mutex_;

41 42 43
OptimizerPtr OptimizerInst::instance = nullptr;
std::mutex OptimizerInst::mutex_;

44 45 46
BuildMgrPtr BuildMgrInst::instance = nullptr;
std::mutex BuildMgrInst::mutex_;

W
wxyu 已提交
47
void
W
wxyu 已提交
48
load_simple_config() {
S
starlord 已提交
49
    server::Config& config = server::Config::GetInstance();
50 51 52
    std::string mode;
    config.GetResourceConfigMode(mode);
    std::vector<std::string> pool;
53
    config.GetResourceConfigSearchResources(pool);
54

55 56
    // get resources
    auto gpu_ids = get_gpu_pool();
W
wxyu 已提交
57

F
fishpenguin 已提交
58 59
    int32_t index_build_device_id;
    config.GetResourceConfigIndexBuildDevice(index_build_device_id);
60

61
    // create and connect
W
wxyu 已提交
62
    ResMgrInst::GetInstance()->Add(ResourceFactory::Create("disk", "DISK", 0, true, false));
63

W
wxyu 已提交
64
    auto io = Connection("io", 500);
65
    ResMgrInst::GetInstance()->Add(ResourceFactory::Create("cpu", "CPU", 0, true, true));
66
    ResMgrInst::GetInstance()->Connect("disk", "cpu", io);
W
wxyu 已提交
67

68
    auto pcie = Connection("pcie", 12000);
69
    bool find_build_gpu_id = false;
70 71 72
    for (auto& gpu_id : gpu_ids) {
        ResMgrInst::GetInstance()->Add(ResourceFactory::Create(std::to_string(gpu_id), "GPU", gpu_id, true, true));
        ResMgrInst::GetInstance()->Connect("cpu", std::to_string(gpu_id), pcie);
F
fishpenguin 已提交
73
        if (index_build_device_id == gpu_id) {
74 75 76 77
            find_build_gpu_id = true;
        }
    }

F
fishpenguin 已提交
78
    if (not find_build_gpu_id && index_build_device_id != server::CPU_DEVICE_ID) {
79
        ResMgrInst::GetInstance()->Add(
F
fishpenguin 已提交
80 81
            ResourceFactory::Create(std::to_string(index_build_device_id), "GPU", index_build_device_id, true, true));
        ResMgrInst::GetInstance()->Connect("cpu", std::to_string(index_build_device_id), pcie);
W
wxyu 已提交
82 83
    }
}
84

W
wxyu 已提交
85 86 87
void
StartSchedulerService() {
    load_simple_config();
W
wxyu 已提交
88 89
    ResMgrInst::GetInstance()->Start();
    SchedInst::GetInstance()->Start();
W
wxyu 已提交
90
    JobMgrInst::GetInstance()->Start();
W
wxyu 已提交
91 92
}

S
starlord 已提交
93 94
void
StopSchedulerService() {
W
wxyu 已提交
95
    JobMgrInst::GetInstance()->Stop();
S
starlord 已提交
96
    SchedInst::GetInstance()->Stop();
W
wxyu 已提交
97
    ResMgrInst::GetInstance()->Stop();
S
starlord 已提交
98
}
S
starlord 已提交
99

S
starlord 已提交
100 101
}  // namespace scheduler
}  // namespace milvus