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

68 lines
1.5 KiB
C++
Raw Normal View History

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:
ImagePool(cl::Context& context, cl_channel_type type) : mContext(context), mType(type) {
}
cl::Image* alloc(int w, int h, bool seperate = false);
void recycle(cl::Image* image, bool release = false);
void clear();
struct Node {
int w;
int h;
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;
cl_channel_type mType;
};
class ImagePoolInt8 : public NonCopyable {
public:
ImagePoolInt8(cl::Context& context) : mContext(context), mType(CL_SIGNED_INT8) {
}
cl::Image* alloc(int w, int h, bool seperate = false);
void recycle(cl::Image* image, bool release = false);
void clear();
struct Node {
int w;
int h;
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;
cl_channel_type mType;
};
2019-04-17 10:49:11 +08:00
} // namespace OpenCL
} // namespace MNN
#endif /* ImagePool_hpp */