MCPcopy Create free account
hub / github.com/alibaba/MNN / alloc

Method alloc

source/backend/opencl/core/ImagePool.cpp:12–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace MNN {
11namespace OpenCL {
12cl::Image* ImagePool::alloc(int w, int h, cl_channel_type type, bool separate) {
13 if (!separate) {
14 int minWaste = 0;
15 auto findIter = mFreeList.end();
16 for (auto iterP = mFreeList.begin(); iterP != mFreeList.end(); iterP++) {
17 auto& iter = *iterP;
18 if (iter->w >= w && iter->h >= h && iter->type == type) {
19 int waste = iter->w * iter->h - w * h;
20 if (minWaste == 0 || waste < minWaste) {
21 findIter = iterP;
22 minWaste = waste;
23 }
24 }
25 }
26 if (findIter != mFreeList.end()) {
27 auto image = (*findIter)->image.get();
28 mFreeList.erase(findIter);
29 return image;
30 }
31 }
32 std::shared_ptr<Node> node(new Node);
33 cl_int ret = CL_SUCCESS;
34 node->w = w;
35 node->h = h;
36 node->type = type;
37 node->image.reset(
38 new cl::Image2D(mContext, CL_MEM_READ_WRITE, cl::ImageFormat(CL_RGBA, type), w, h, 0, nullptr, &ret));
39 if (nullptr == node->image.get() || ret != CL_SUCCESS) {
40 MNN_ERROR("Alloc Image %d x %d error, code:%d \n", w, h, ret);
41 return nullptr;
42 }
43 mAllImage.insert(std::make_pair(node->image.get(), node));
44 return node->image.get();
45}
46
47void ImagePool::recycle(cl::Image* image, bool release) {
48 auto iter = mAllImage.find(image);

Callers 12

onAcquireMethod · 0.45
onEncodeMethod · 0.45
onEncodeMethod · 0.45
onEncodeMethod · 0.45
onEncodeMethod · 0.45
allocMemoryMethod · 0.45
onAcquireMethod · 0.45
onEncodeMethod · 0.45
onExcuteMethod · 0.45
onEncodeMethod · 0.45
onEncodeMethod · 0.45

Calls 7

ImageFormatEnum · 0.50
endMethod · 0.45
beginMethod · 0.45
getMethod · 0.45
eraseMethod · 0.45
resetMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected