|
| 1 | += cl_intel_kernel_allocations_info |
| 2 | + |
| 3 | +// This section needs to be after the document title. |
| 4 | +:doctype: book |
| 5 | +:toc2: |
| 6 | +:toc: left |
| 7 | +:encoding: utf-8 |
| 8 | +:lang: en |
| 9 | + |
| 10 | +:blank: pass:[ +] |
| 11 | + |
| 12 | +// Set the default source code type in this document to C++, |
| 13 | +// for syntax highlighting purposes. This is needed because |
| 14 | +// docbook uses c++ and html5 uses cpp. |
| 15 | +:language: {basebackend@docbook:c++:cpp} |
| 16 | + |
| 17 | +== Name Strings |
| 18 | + |
| 19 | +`cl_intel_kernel_allocations_info` |
| 20 | + |
| 21 | +== Contact |
| 22 | + |
| 23 | +Igor Venevtsev, Intel (igor 'dot' venevtsev 'at' intel 'dot' com) |
| 24 | + |
| 25 | +== Contributors |
| 26 | + |
| 27 | +// spell-checker: disable |
| 28 | +Ben Ashbaugh, Intel + |
| 29 | +Igor Venevtsev, Intel + |
| 30 | +// spell-checker: enable |
| 31 | + |
| 32 | +== Notice |
| 33 | + |
| 34 | +Copyright (c) 2026 Intel Corporation. All rights reserved. |
| 35 | + |
| 36 | +== Status |
| 37 | + |
| 38 | +Shipping |
| 39 | + |
| 40 | +== Version |
| 41 | + |
| 42 | +Built On: {docdate} + |
| 43 | +Revision: 1.0.0 |
| 44 | + |
| 45 | +== Dependencies |
| 46 | + |
| 47 | +This extension is written against the OpenCL API Specification Version 3.0.19 |
| 48 | + |
| 49 | +This extension requires `cl_intel_unified_shared_memory` extension |
| 50 | +for `cl_unified_shared_memory_type_intel` memory types enum. |
| 51 | + |
| 52 | +== Overview |
| 53 | + |
| 54 | +The goal of the extension is to report in unified form GPU memory ranges used by kernel, |
| 55 | +both explicit like kernel arguments and implicit ones made by driver like printf surface, |
| 56 | +scratch surface, etc. This information later can be used for some kernel instrumentation |
| 57 | +to detect out-of-bound accesses, kernel profiling and so on. |
| 58 | +There is a 2-step process to obtain this information. The first step is to find the count |
| 59 | +of memory allocations owned by kernel, so the buffer is large enough to store this number |
| 60 | +of `cl_kernel_allocation_info_intel` structs must be allocated later. |
| 61 | +This is done by providing an input allocation infos pointer with `nullptr` value. |
| 62 | +After allocating a storage array of this size, the user then provides the valid size |
| 63 | +and storage location to retrieve the data. |
| 64 | + |
| 65 | +Information about memory allocation owned by kernel returned in |
| 66 | +`cl_kernel_allocation_info_intel` struct. In case of internal allocation |
| 67 | +(not a kernel argument) `arg_index` will be set to -1. |
| 68 | + |
| 69 | +The following pseudo-code shows how to print information about kernel allocations: |
| 70 | + |
| 71 | +[source, c++] |
| 72 | +---- |
| 73 | +size_t sz = 0; |
| 74 | +clGetKernelWorkGroupInfo(kernel, device, |
| 75 | + CL_KERNEL_ALLOCATIONS_INFO_INTEL, |
| 76 | + 0, nullptr, &sz); |
| 77 | +
|
| 78 | +size_t numAllocs = sz / sizeof(cl_kernel_allocation_info_intel); |
| 79 | +std::vector<cl_kernel_allocation_info_intel> allocInfos(numAllocs); |
| 80 | +clGetKernelWorkGroupInfo(kernel, device, |
| 81 | + CL_KERNEL_ALLOCATIONS_INFO_INTEL, |
| 82 | + sz, allocInfos.data(), nullptr); |
| 83 | +
|
| 84 | +auto toStr = [](cl_unified_shared_memory_type_intel type) { |
| 85 | + switch (type) { |
| 86 | + default: return "CL_MEM_TYPE_UNKNOWN_INTEL"; |
| 87 | +#define CASE(_X_) case _X_ : return #_X_; |
| 88 | + CASE(CL_MEM_TYPE_UNKNOWN_INTEL); |
| 89 | + CASE(CL_MEM_TYPE_HOST_INTEL); |
| 90 | + CASE(CL_MEM_TYPE_DEVICE_INTEL); |
| 91 | + CASE(CL_MEM_TYPE_SHARED_INTEL); |
| 92 | +#undef CASE |
| 93 | + } |
| 94 | +}; |
| 95 | +
|
| 96 | +for (uint32_t i = 0; i < numAllocs; ++i) { |
| 97 | + std::cout << "Allocation " << i << ": " << std::hex << "0x" << allocInfos[i].base << ", size: " << std::dec << allocInfos[i].size |
| 98 | + << " arg_index: " << allocInfos[i].arg_index << " type: " << toStr(allocInfos[i].type) << "n"; |
| 99 | +} |
| 100 | +---- |
| 101 | + |
| 102 | +Possible output: |
| 103 | + |
| 104 | +[source, bash] |
| 105 | +---- |
| 106 | +Allocation 0: 0x14d9ff00000, size: 65536 arg_index: 0 type: CL_MEM_TYPE_SHARED_INTEL |
| 107 | +Allocation 1: 0x14d9fef0000, size: 65536 arg_index: 2 type: CL_MEM_TYPE_SHARED_INTEL |
| 108 | +Allocation 2: 0x14d9ff20000, size: 4194304 arg_index: -1 type: CL_MEM_TYPE_UNKNOWN_INTEL |
| 109 | +Allocation 3: 0xffff80010010b000, size: 4096 arg_index: -1 type: CL_MEM_TYPE_UNKNOWN_INTEL |
| 110 | +---- |
| 111 | + |
| 112 | +== New API Functions |
| 113 | + |
| 114 | +None. |
| 115 | + |
| 116 | +== New API Enums |
| 117 | + |
| 118 | +Accepted value for the _param_name_ parameter to |
| 119 | +*clGetKernelWorkGroupInfo* to query kernel allocationis information: |
| 120 | + |
| 121 | +[source,c] |
| 122 | +---- |
| 123 | +#define CL_KERNEL_ALLOCATIONS_INFO_INTEL 0x425A |
| 124 | +---- |
| 125 | + |
| 126 | +== New API Types |
| 127 | + |
| 128 | +Returned as the query result value *clGetKernelWorkGroupInfo* for `CL_KERNEL_ALLOCATIONS_INFO_INTEL`: |
| 129 | + |
| 130 | +[source] |
| 131 | +---- |
| 132 | +typedef struct _cl_kernel_allocation_info_intel { |
| 133 | + void* base; |
| 134 | + size_t size; |
| 135 | + cl_unified_shared_memory_type_intel type; |
| 136 | + cl_int arg_index; |
| 137 | +} cl_kernel_allocation_info_intel; |
| 138 | +---- |
| 139 | + |
| 140 | +== Modifications to the OpenCL API Specification |
| 141 | + |
| 142 | +=== Section 5.9.4 - Kernel Object Queries: |
| 143 | + |
| 144 | +Add to Table 29 - List of supported param_names by |
| 145 | +*clGetKernelWorkGroupInfo*: |
| 146 | + |
| 147 | +[caption="Table 29. "] |
| 148 | +.List of supported param_names by clGetKernelWorkGroupInfo |
| 149 | +[width="100%",cols="<30%,<20%,<50%",options="header"] |
| 150 | +|==== |
| 151 | +| *cl_kernel_info* | Return Type | Info. returned in _param_value_ |
| 152 | +| `CL_KERNEL_ALLOCATIONS_INFO_INTEL` |
| 153 | + | `cl_kernel_allocation_info_intel[]` |
| 154 | + | Returns an array of `cl_kernel_allocation_info_intel` structures describing kernel memory allocations information. |
| 155 | + Each structure consists of: |
| 156 | + |
| 157 | + `base`: Base address of the allocation. |
| 158 | + |
| 159 | + `size`: Size of allocation in bytes. |
| 160 | + |
| 161 | + `type`: Type of allocation as described in `cl_unified_shared_memory_type_intel` enum. |
| 162 | + In case of internal (not a kernel argument) allocation `CL_MEM_TYPE_UNKNOWN_INTEL` will be returned. |
| 163 | + |
| 164 | + `arg_index`: Kernel argument index corresponding to allocation. |
| 165 | + In case of internal (not a kernel argument) allocation `-1` will be returned. |
| 166 | +|==== |
| 167 | + |
| 168 | + |
| 169 | +== Revision History |
| 170 | + |
| 171 | +[cols="5,15,15,70"] |
| 172 | +[grid="rows"] |
| 173 | +[options="header"] |
| 174 | +|======================================== |
| 175 | +|Rev|Date|Author|Changes |
| 176 | +|1.0.0|2026-01-20|Igor Venevtsev|First public version |
| 177 | +|======================================== |
| 178 | + |
| 179 | +//************************************************************************ |
| 180 | +//Other formatting suggestions: |
| 181 | +// |
| 182 | +//* Use *bold* text for host APIs, or [source] syntax highlighting. |
| 183 | +//* Use `mono` text for device APIs, or [source] syntax highlighting. |
| 184 | +//* Use `mono` text for extension names, types, or enum values. |
| 185 | +//* Use _italics_ for parameters. |
| 186 | +//************************************************************************ |
0 commit comments