26 #include "../Framework.h"
29 #ifndef ARM_COMPUTE_CL
30 #error "You can't use OpenCLMemoryUsage without OpenCL"
43 return "OpenCLMemoryUsage";
47 : real_clCreateBuffer(
CLSymbols::get().clCreateBuffer_ptr), real_clRetainMemObject(
CLSymbols::get().clRetainMemObject_ptr), real_clReleaseMemObject(
CLSymbols::get().clReleaseMemObject_ptr),
48 real_clSVMAlloc(
CLSymbols::get().clSVMAlloc_ptr), real_clSVMFree(
CLSymbols::get().clSVMFree_ptr), _allocations(), _svm_allocations(), _start(), _end(), _now()
61 _scale_factor = 1000000;
81 cl_mem
retval = this->real_clCreateBuffer(
context, flags, size, host_ptr, errcode_ret);
82 if(host_ptr !=
nullptr)
89 _now.num_allocations++;
91 _now.total_allocated += size;
92 if(_now.in_use > _now.max_in_use)
94 _now.max_in_use = _now.in_use;
97 this->_allocations[
retval] = Allocation(size);
103 cl_int
retval = this->real_clRetainMemObject(memobj);
104 this->_allocations[memobj].refcount++;
110 cl_int
retval = this->real_clRetainMemObject(memobj);
111 Allocation &alloc = this->_allocations[memobj];
112 if(--alloc.refcount == 0)
114 _now.in_use -= alloc.size;
124 void *
retval = this->real_clSVMAlloc(
context, flags, size, alignment);
127 _svm_allocations[
retval] = size;
128 _now.num_allocations++;
130 _now.total_allocated += size;
131 if(_now.in_use > _now.max_in_use)
133 _now.max_in_use = _now.in_use;
145 this->real_clSVMFree(
context, svm_pointer);
146 auto iterator = _svm_allocations.find(svm_pointer);
147 if(iterator != _svm_allocations.end())
149 size_t size = iterator->second;
150 _svm_allocations.erase(iterator);
179 measurements.emplace(
"Num buffers allocated per run",
Measurement(_end.num_allocations - _start.num_allocations,
""));
180 measurements.emplace(
"Total memory allocated per run",
Measurement((_end.total_allocated - _start.total_allocated) / _scale_factor, _unit));
194 size_t total_size = 0;
197 std::vector<size_t> binary_sizes = it.second.getInfo<CL_PROGRAM_BINARY_SIZES>();
198 total_size =
std::accumulate(binary_sizes.begin(), binary_sizes.end(), total_size);