SchedInst.cpp 3.4 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() {
48
    // create and connect
W
wxyu 已提交
49
    ResMgrInst::GetInstance()->Add(ResourceFactory::Create("disk", "DISK", 0, true, false));
50

W
wxyu 已提交
51
    auto io = Connection("io", 500);
52
    ResMgrInst::GetInstance()->Add(ResourceFactory::Create("cpu", "CPU", 0, true, true));
53
    ResMgrInst::GetInstance()->Connect("disk", "cpu", io);
W
wxyu 已提交
54

55 56 57
    // get resources
#ifdef MILVUS_GPU_VERSION
    server::Config& config = server::Config::GetInstance();
Y
yudong.cai 已提交
58
    std::vector<int64_t> gpu_ids;
59
    config.GetGpuResourceConfigSearchResources(gpu_ids);
Y
yudong.cai 已提交
60
    std::vector<int64_t> build_gpu_ids;
61
    config.GetGpuResourceConfigBuildIndexResources(build_gpu_ids);
62
    auto pcie = Connection("pcie", 12000);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    std::vector<int64_t> not_find_build_ids;
    for (auto& build_id : build_gpu_ids) {
        bool find_gpu_id = false;
        for (auto& gpu_id : gpu_ids) {
            if (gpu_id == build_id) {
                find_gpu_id = true;
                break;
            }
        }
        if (not find_gpu_id) {
            not_find_build_ids.emplace_back(build_id);
        }
    }

78 79 80
    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);
81 82
    }

83
    for (auto& not_find_id : not_find_build_ids) {
84
        ResMgrInst::GetInstance()->Add(
85 86
            ResourceFactory::Create(std::to_string(not_find_id), "GPU", not_find_id, true, true));
        ResMgrInst::GetInstance()->Connect("cpu", std::to_string(not_find_id), pcie);
W
wxyu 已提交
87
    }
88
#endif
W
wxyu 已提交
89
}
90

W
wxyu 已提交
91 92 93
void
StartSchedulerService() {
    load_simple_config();
94
    OptimizerInst::GetInstance()->Init();
W
wxyu 已提交
95 96
    ResMgrInst::GetInstance()->Start();
    SchedInst::GetInstance()->Start();
W
wxyu 已提交
97
    JobMgrInst::GetInstance()->Start();
W
wxyu 已提交
98 99
}

S
starlord 已提交
100 101
void
StopSchedulerService() {
W
wxyu 已提交
102
    JobMgrInst::GetInstance()->Stop();
S
starlord 已提交
103
    SchedInst::GetInstance()->Stop();
W
wxyu 已提交
104
    ResMgrInst::GetInstance()->Stop();
S
starlord 已提交
105
}
S
starlord 已提交
106

S
starlord 已提交
107 108
}  // namespace scheduler
}  // namespace milvus