MNN/source/backend/opencl/core/BufferPool.hpp

48 lines
1008 B
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// BufferPool.hpp
// MNN
//
// Created by MNN on 2019/02/28.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef BufferPool_hpp
#define BufferPool_hpp
#include <map>
#include <memory>
#include <vector>
2019-12-27 22:16:57 +08:00
#include "core/NonCopyable.hpp"
#include "backend/opencl/core/runtime/OpenCLWrapper.hpp"
2019-04-17 10:49:11 +08:00
namespace MNN {
namespace OpenCL {
class BufferPool : public NonCopyable {
public:
BufferPool(cl::Context& context, cl_mem_flags flags) : mContext(context) {
mFlag = flags;
}
2022-05-27 23:46:44 +08:00
cl::Buffer* alloc(int size, bool separate = false);
2019-04-17 10:49:11 +08:00
void recycle(cl::Buffer* buffer, bool release = false);
void clear();
2023-12-04 11:12:20 +08:00
void releaseFreeList();
2019-04-17 10:49:11 +08:00
struct Node {
int size;
std::shared_ptr<cl::Buffer> buffer;
};
private:
std::map<cl::Buffer*, std::shared_ptr<Node>> mAllBuffer;
std::multimap<int, std::shared_ptr<Node>> mFreeList;
cl::Context& mContext;
cl_mem_flags mFlag;
};
2019-04-17 10:49:11 +08:00
} // namespace OpenCL
} // namespace MNN
#endif /* BufferPool_hpp */