1 //
2 //  ImagePool.hpp
3 //  MNN
4 //
5 //  Created by MNN on 2019/02/28.
6 //  Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #ifndef ImagePool_hpp
10 #define ImagePool_hpp
11 
12 #include <list>
13 #include <map>
14 #include "core/NonCopyable.hpp"
15 #include "backend/opencl/core/runtime/OpenCLWrapper.hpp"
16 namespace MNN {
17 namespace OpenCL {
18 
19 class ImagePool : public NonCopyable {
20 public:
ImagePool(cl::Context & context)21     ImagePool(cl::Context& context) : mContext(context) {
22     }
23 
24     cl::Image* alloc(int w, int h, cl_channel_type type, bool seperate = false);
25     void recycle(cl::Image* image, bool release = false);
26     void clear();
27 
28     struct Node {
29         int w;
30         int h;
31         std::shared_ptr<cl::Image> image;
32     };
33 
34 private:
35     std::map<cl::Image*, std::shared_ptr<Node>> mAllImage;
36     std::list<std::shared_ptr<Node>> mFreeList;
37 
38     cl::Context& mContext;
39 };
40 
41 } // namespace OpenCL
42 } // namespace MNN
43 #endif /* ImagePool_hpp */
44