SchedInst.cpp 3.1 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
#include "server/Config.h"
W
wxyu 已提交
22

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

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

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

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

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

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

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

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

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

Y
youny626 已提交
57 58
    int32_t build_gpu_id;
    config.GetResourceConfigIndexBuildDevice(build_gpu_id);
59

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

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

67
    auto pcie = Connection("pcie", 12000);
68
    bool find_build_gpu_id = false;
69 70 71
    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);
Y
youny626 已提交
72
        if (build_gpu_id == gpu_id) {
73 74 75 76
            find_build_gpu_id = true;
        }
    }

Y
youny626 已提交
77
    if (not find_build_gpu_id) {
78
        ResMgrInst::GetInstance()->Add(
Y
youny626 已提交
79 80
            ResourceFactory::Create(std::to_string(build_gpu_id), "GPU", build_gpu_id, true, true));
        ResMgrInst::GetInstance()->Connect("cpu", std::to_string(build_gpu_id), pcie);
W
wxyu 已提交
81 82
    }
}
83

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

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

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