Commit 6c7bb57c authored by 余昆's avatar 余昆
Browse files

add unitteest


Former-commit-id: 9ad0fddedf0ace50845a7d516452b986162204f8
parent 03adffe2
Loading
Loading
Loading
Loading
+56 −56
Original line number Diff line number Diff line
@@ -15,59 +15,59 @@
// specific language governing permissions and limitations
// under the License.

#include "scheduler/optimizer/LargeSQ8HPass.h"
#include "cache/GpuCacheMgr.h"
#include "scheduler/SchedInst.h"
#include "scheduler/Utils.h"
#include "scheduler/task/SearchTask.h"
#include "scheduler/tasklabel/SpecResLabel.h"
#include "utils/Log.h"

namespace milvus {
namespace scheduler {

bool
LargeSQ8HPass::Run(const TaskPtr& task) {
    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());

    // TODO: future, Index::IVFSQ8H, if nq < threshold set cpu, else set gpu
    if (search_job->nq() < 100) {
        return false;
    }

    std::vector<uint64_t> gpus = scheduler::get_gpu_pool();
    std::vector<int64_t> all_free_mem;
    for (auto& gpu : gpus) {
        auto cache = cache::GpuCacheMgr::GetInstance(gpu);
        auto free_mem = cache->CacheCapacity() - cache->CacheUsage();
        all_free_mem.push_back(free_mem);
    }

    auto max_e = std::max_element(all_free_mem.begin(), all_free_mem.end());
    auto best_index = std::distance(all_free_mem.begin(), max_e);
    auto best_device_id = gpus[best_index];

    ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
    if (not res_ptr) {
        SERVER_LOG_ERROR << "GpuResource " << best_device_id << " invalid.";
        // TODO: throw critical error and exit
        return false;
    }

    auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
    task->label() = label;

    return true;
}

}  // namespace scheduler
}  // namespace milvus
//#include "scheduler/optimizer/LargeSQ8HPass.h"
//#include "cache/GpuCacheMgr.h"
//#include "scheduler/SchedInst.h"
//#include "scheduler/Utils.h"
//#include "scheduler/task/SearchTask.h"
//#include "scheduler/tasklabel/SpecResLabel.h"
//#include "utils/Log.h"
//
//namespace milvus {
//namespace scheduler {
//
//bool
//LargeSQ8HPass::Run(const TaskPtr& task) {
//    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());
//
//    // TODO: future, Index::IVFSQ8H, if nq < threshold set cpu, else set gpu
//    if (search_job->nq() < 100) {
//        return false;
//    }
//
//    std::vector<uint64_t> gpus = scheduler::get_gpu_pool();
//    std::vector<int64_t> all_free_mem;
//    for (auto& gpu : gpus) {
//        auto cache = cache::GpuCacheMgr::GetInstance(gpu);
//        auto free_mem = cache->CacheCapacity() - cache->CacheUsage();
//        all_free_mem.push_back(free_mem);
//    }
//
//    auto max_e = std::max_element(all_free_mem.begin(), all_free_mem.end());
//    auto best_index = std::distance(all_free_mem.begin(), max_e);
//    auto best_device_id = gpus[best_index];
//
//    ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, best_device_id);
//    if (not res_ptr) {
//        SERVER_LOG_ERROR << "GpuResource " << best_device_id << " invalid.";
//        // TODO: throw critical error and exit
//        return false;
//    }
//
//    auto label = std::make_shared<SpecResLabel>(std::weak_ptr<Resource>(res_ptr));
//    task->label() = label;
//
//    return true;
//}
//
//}  // namespace scheduler
//}  // namespace milvus
+31 −31
Original line number Diff line number Diff line
@@ -14,34 +14,34 @@
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
#pragma once

#include <condition_variable>
#include <deque>
#include <list>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>

#include "Pass.h"

namespace milvus {
namespace scheduler {

class LargeSQ8HPass : public Pass {
 public:
    LargeSQ8HPass() = default;

 public:
    bool
    Run(const TaskPtr& task) override;
};

using LargeSQ8HPassPtr = std::shared_ptr<LargeSQ8HPass>;

}  // namespace scheduler
}  // namespace milvus
//#pragma once
//
//#include <condition_variable>
//#include <deque>
//#include <list>
//#include <memory>
//#include <mutex>
//#include <queue>
//#include <string>
//#include <thread>
//#include <unordered_map>
//#include <vector>
//
//#include "Pass.h"
//
//namespace milvus {
//namespace scheduler {
//
//class LargeSQ8HPass : public Pass {
// public:
//    LargeSQ8HPass() = default;
//
// public:
//    bool
//    Run(const TaskPtr& task) override;
//};
//
//using LargeSQ8HPassPtr = std::shared_ptr<LargeSQ8HPass>;
//
//}  // namespace scheduler
//}  // namespace milvus
+6 −6
Original line number Diff line number Diff line
@@ -20,12 +20,12 @@
namespace milvus {
namespace scheduler {

void
Optimizer::Init() {
    for (auto& pass : pass_list_) {
        pass->Init();
    }
}
//void
//Optimizer::Init() {
//    for (auto& pass : pass_list_) {
//        pass->Init();
//    }
//}

bool
Optimizer::Run(const TaskPtr& task) {
+2 −2
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ class Optimizer {
    explicit Optimizer(std::vector<PassPtr> pass_list) : pass_list_(std::move(pass_list)) {
    }

    void
    Init();
//    void
//    Init();

    bool
    Run(const TaskPtr& task);
+3 −3
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@ namespace scheduler {

class Pass {
 public:
    virtual void
    Init() {
    }
//    virtual void
//    Init() {
//    }

    virtual bool
    Run(const TaskPtr& task) = 0;
Loading