|
| 1 | +<% |
| 2 | +import re |
| 3 | +from templates import helper as th |
| 4 | +%><% |
| 5 | + OneApi=tags['$OneApi'] |
| 6 | + x=tags['$x'] |
| 7 | + X=x.upper() |
| 8 | +%> |
| 9 | +:orphan: |
| 10 | + |
| 11 | +.. _ZE_extension_kernel_binary_exp: |
| 12 | + |
| 13 | +========================================= |
| 14 | + Get Kernel Binary Program Data Extension |
| 15 | +========================================= |
| 16 | + |
| 17 | +API |
| 18 | +---- |
| 19 | + |
| 20 | +* Functions |
| 21 | + |
| 22 | + * ${x}KernelGetBinaryExp |
| 23 | + |
| 24 | + |
| 25 | +=============================== |
| 26 | + Get Kernel Binary Program Data |
| 27 | +=============================== |
| 28 | + |
| 29 | +After a kernel is created with zeKernelCreate, the user will be able to retrieve the kernel |
| 30 | +binary program data, which is in GEN ISA format. Each valid kernel handle will provide the |
| 31 | +information required to retrieve such data. The user may then save this data to a file for |
| 32 | +disassembly and analysis. There is a 2-step process to obtain this data. The first step is |
| 33 | +to find the size of binary program data, so that memory may be allocated to store such data. |
| 34 | +This is done by providing an input storage pointer with nullptr value. After allocating a |
| 35 | +storage array of this size, the user then provides the valid size and storage location to |
| 36 | +retrieve the data. |
| 37 | + |
| 38 | +The following pseudo-code shows how to obtain the kernel binary program data save to a file: |
| 39 | + |
| 40 | +.. parsed-literal:: |
| 41 | +
|
| 42 | + #include <fstream> |
| 43 | + //hKernel = valid kernel handle |
| 44 | + size_t kBinarySize = 0; |
| 45 | + char *progArray; |
| 46 | + ${x}KernelGetBinaryExp(hKernel, &KBinarysize, nullptr); |
| 47 | + progArray = new char[kBinarySize]; |
| 48 | + ${x}KernelGetBinaryExp(hKernel, &kBinarySize, progArray); |
| 49 | + const std::string filePath = "program.bin"; |
| 50 | + std::ofstream stream(filePath, std::ios::out | std::ios::binary); |
| 51 | + stream.write(reinterpret_cast<const char *>(progArray), kBinarySize); |
| 52 | + stream.close(); |
| 53 | + delete[] progArray; |
0 commit comments