GpuCacheMgr.h 1.4 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////

#include "CacheMgr.h"
Y
Yu Kun 已提交
8
#include <unordered_map>
Y
Yu Kun 已提交
9
#include <memory>
G
groot 已提交
10 11

namespace zilliz {
J
jinhai 已提交
12
namespace milvus {
G
groot 已提交
13 14
namespace cache {

Y
Yu Kun 已提交
15 16 17
class GpuCacheMgr;
using GpuCacheMgrPtr = std::shared_ptr<GpuCacheMgr>;

G
groot 已提交
18
class GpuCacheMgr : public CacheMgr {
Y
Yu Kun 已提交
19
public:
G
groot 已提交
20 21
    GpuCacheMgr();

Y
Yu Kun 已提交
22 23
    static bool GpuIdInConfig(uint64_t gpu_id);

Y
Yu Kun 已提交
24
    static CacheMgr* GetInstance(uint64_t gpu_id) {
Y
Yu Kun 已提交
25
        if (instance_.find(gpu_id) == instance_.end()) {
Y
Yu Kun 已提交
26
            std::lock_guard<std::mutex> lock(mutex_);
Y
Yu Kun 已提交
27 28 29 30 31 32 33
            if (instance_.find(gpu_id) == instance_.end()) {
                if (GpuIdInConfig(gpu_id)) {
                    instance_.insert(std::pair<uint64_t, GpuCacheMgrPtr>(gpu_id, std::make_shared<GpuCacheMgr>()));
                } else {
                    return nullptr;
                }
            }
Y
Yu Kun 已提交
34
        }
Y
Yu Kun 已提交
35
        return instance_[gpu_id].get();
G
groot 已提交
36 37 38
    }

    void InsertItem(const std::string& key, const DataObjPtr& data) override;
Y
Yu Kun 已提交
39 40 41

private:
    static std::mutex mutex_;
Y
Yu Kun 已提交
42
    static std::unordered_map<uint64_t, GpuCacheMgrPtr> instance_;
G
groot 已提交
43 44 45 46 47
};

}
}
}