| 75 | } |
| 76 | |
| 77 | void OpenCLMemoryUsage::test_start() |
| 78 | { |
| 79 | _now = Stats(); |
| 80 | |
| 81 | ARM_COMPUTE_ERROR_ON(CLSymbols::get().clCreateBuffer_ptr == nullptr); |
| 82 | CLSymbols::get().clCreateBuffer_ptr = |
| 83 | [this](cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret) |
| 84 | { |
| 85 | cl_mem retval = this->real_clCreateBuffer(context, flags, size, host_ptr, errcode_ret); |
| 86 | if (host_ptr != nullptr) |
| 87 | { |
| 88 | // If it's an SVM / external allocation; |
| 89 | size = 0; |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | _now.num_allocations++; |
| 94 | _now.in_use += size; |
| 95 | _now.total_allocated += size; |
| 96 | if (_now.in_use > _now.max_in_use) |
| 97 | { |
| 98 | _now.max_in_use = _now.in_use; |
| 99 | } |
| 100 | } |
| 101 | this->_allocations[retval] = Allocation(size); |
| 102 | return retval; |
| 103 | }; |
| 104 | ARM_COMPUTE_ERROR_ON(CLSymbols::get().clRetainMemObject_ptr == nullptr); |
| 105 | CLSymbols::get().clRetainMemObject_ptr = [this](cl_mem memobj) |
| 106 | { |
| 107 | cl_int retval = this->real_clRetainMemObject(memobj); |
| 108 | this->_allocations[memobj].refcount++; |
| 109 | return retval; |
| 110 | }; |
| 111 | ARM_COMPUTE_ERROR_ON(CLSymbols::get().clReleaseMemObject_ptr == nullptr); |
| 112 | CLSymbols::get().clReleaseMemObject_ptr = [this](cl_mem memobj) |
| 113 | { |
| 114 | cl_int retval = this->real_clRetainMemObject(memobj); |
| 115 | Allocation &alloc = this->_allocations[memobj]; |
| 116 | if (--alloc.refcount == 0) |
| 117 | { |
| 118 | _now.in_use -= alloc.size; |
| 119 | } |
| 120 | return retval; |
| 121 | }; |
| 122 | |
| 123 | //Only intercept the function if it exists: |
| 124 | if (CLSymbols::get().clSVMAlloc_ptr != nullptr) |
| 125 | { |
| 126 | CLSymbols::get().clSVMAlloc_ptr = |
| 127 | [this](cl_context context, cl_svm_mem_flags flags, size_t size, cl_uint alignment) |
| 128 | { |
| 129 | void *retval = this->real_clSVMAlloc(context, flags, size, alignment); |
| 130 | if (retval != nullptr) |
| 131 | { |
| 132 | _svm_allocations[retval] = size; |
| 133 | _now.num_allocations++; |
| 134 | _now.in_use += size; |
nothing calls this directly
no test coverage detected