test_algorithm.cpp 3.5 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed 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
J
jinhai 已提交
5
//
6 7 8 9 10
// 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.
J
jinhai 已提交
11

12 13
#include <gtest/gtest.h>

Y
youny626 已提交
14 15
#include "scheduler/Algorithm.h"
#include "scheduler/ResourceFactory.h"
16 17
#include "scheduler/ResourceMgr.h"
#include "scheduler/resource/CpuResource.h"
Y
youny626 已提交
18
#include "scheduler/resource/Resource.h"
S
starlord 已提交
19

20
namespace milvus {
W
wxyu 已提交
21
namespace scheduler {
22 23 24 25 26

class AlgorithmTest : public testing::Test {
 protected:
    void
    SetUp() override {
W
Wang XiangYu 已提交
27 28
        ResourcePtr disk = ResourceFactory::Create("disk", "DISK", 0, false);
        ResourcePtr cpu0 = ResourceFactory::Create("cpu0", "CPU", 0);
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        ResourcePtr cpu1 = ResourceFactory::Create("cpu1", "CPU", 1);
        ResourcePtr cpu2 = ResourceFactory::Create("cpu2", "CPU", 2);
        ResourcePtr gpu0 = ResourceFactory::Create("gpu0", "GPU", 0);
        ResourcePtr gpu1 = ResourceFactory::Create("gpu1", "GPU", 1);

        res_mgr_ = std::make_shared<ResourceMgr>();
        disk_ = res_mgr_->Add(std::move(disk));
        cpu_0_ = res_mgr_->Add(std::move(cpu0));
        cpu_1_ = res_mgr_->Add(std::move(cpu1));
        cpu_2_ = res_mgr_->Add(std::move(cpu2));
        gpu_0_ = res_mgr_->Add(std::move(gpu0));
        gpu_1_ = res_mgr_->Add(std::move(gpu1));
        auto IO = Connection("IO", 5.0);
        auto PCIE = Connection("PCIE", 11.0);
        res_mgr_->Connect("disk", "cpu0", IO);
        res_mgr_->Connect("cpu0", "cpu1", IO);
        res_mgr_->Connect("cpu1", "cpu2", IO);
        res_mgr_->Connect("cpu0", "cpu2", IO);
        res_mgr_->Connect("cpu1", "gpu0", PCIE);
        res_mgr_->Connect("cpu2", "gpu1", PCIE);
    }

    ResourceWPtr disk_;
    ResourceWPtr cpu_0_;
    ResourceWPtr cpu_1_;
    ResourceWPtr cpu_2_;
    ResourceWPtr gpu_0_;
    ResourceWPtr gpu_1_;
    ResourceMgrPtr res_mgr_;
};

S
starlord 已提交
60
TEST_F(AlgorithmTest, SHORTESTPATH_TEST) {
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    std::vector<std::string> sp;
    uint64_t cost;
    cost = ShortestPath(disk_.lock(), gpu_0_.lock(), res_mgr_, sp);
    while (!sp.empty()) {
        std::cout << sp[sp.size() - 1] << std::endl;
        sp.pop_back();
    }

    std::cout << "************************************\n";
    cost = ShortestPath(cpu_0_.lock(), gpu_0_.lock(), res_mgr_, sp);
    while (!sp.empty()) {
        std::cout << sp[sp.size() - 1] << std::endl;
        sp.pop_back();
    }

    std::cout << "************************************\n";
    cost = ShortestPath(disk_.lock(), disk_.lock(), res_mgr_, sp);
    while (!sp.empty()) {
        std::cout << sp[sp.size() - 1] << std::endl;
        sp.pop_back();
    }

    std::cout << "************************************\n";
    cost = ShortestPath(cpu_0_.lock(), disk_.lock(), res_mgr_, sp);
    while (!sp.empty()) {
        std::cout << sp[sp.size() - 1] << std::endl;
        sp.pop_back();
    }

    std::cout << "************************************\n";
    cost = ShortestPath(cpu_2_.lock(), gpu_0_.lock(), res_mgr_, sp);
    while (!sp.empty()) {
        std::cout << sp[sp.size() - 1] << std::endl;
        sp.pop_back();
    }
}

Y
youny626 已提交
98 99
}  // namespace scheduler
}  // namespace milvus