2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// ImagePool.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/02/28.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ImagePool_hpp
|
|
|
|
#define ImagePool_hpp
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
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 ImagePool : public NonCopyable {
|
|
|
|
public:
|
2020-11-05 16:41:56 +08:00
|
|
|
ImagePool(cl::Context& context) : mContext(context) {
|
2019-04-17 10:49:11 +08:00
|
|
|
}
|
|
|
|
|
2022-05-27 23:46:44 +08:00
|
|
|
cl::Image* alloc(int w, int h, cl_channel_type type, bool separate = false);
|
2019-04-17 10:49:11 +08:00
|
|
|
void recycle(cl::Image* image, 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 w;
|
|
|
|
int h;
|
2024-04-19 11:58:21 +08:00
|
|
|
cl_channel_type type;
|
2019-04-17 10:49:11 +08:00
|
|
|
std::shared_ptr<cl::Image> image;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<cl::Image*, std::shared_ptr<Node>> mAllImage;
|
|
|
|
std::list<std::shared_ptr<Node>> mFreeList;
|
|
|
|
|
|
|
|
cl::Context& mContext;
|
|
|
|
};
|
2019-11-15 14:22:45 +08:00
|
|
|
|
2019-04-17 10:49:11 +08:00
|
|
|
} // namespace OpenCL
|
|
|
|
} // namespace MNN
|
|
|
|
#endif /* ImagePool_hpp */
|