Skip to content

Commit 7ef52fa

Browse files
johntfalkpbg-intel
authored andcommitted
Add API specification to retrieve kernel binary program data
Signed-off-by: John Falkowski <[email protected]>
1 parent 71f952c commit 7ef52fa

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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;

scripts/core/kernelBinary.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
# See YaML.md for syntax definition
7+
#
8+
--- #--------------------------------------------------------------------------
9+
type: header
10+
desc: "Intel $OneApi Level-Zero Extension for retrieving kernel binary program data."
11+
version: "1.11"
12+
--- #--------------------------------------------------------------------------
13+
type: macro
14+
desc: "Get Kernel Binary Extension Name"
15+
version: "1.11"
16+
name: $X_GET_KERNEL_BINARY_EXP_NAME
17+
value: '"$X_extension_kernel_binary_exp"'
18+
--- #--------------------------------------------------------------------------
19+
type: function
20+
desc: "Retrieves kernel binary program data (ISA GEN format)."
21+
version: "1.11"
22+
class: $xKernel
23+
name: GetBinaryExp
24+
decl: static
25+
ordinal: "0"
26+
details:
27+
- "A valid kernel handle must be created with zeKernelCreate."
28+
- "Returns Intel Graphics Assembly (GEN ISA) format binary program data for kernel handle."
29+
- "The application may call this function from simultaneous threads."
30+
- "The implementation of this function must be thread-safe."
31+
params:
32+
- type: "$x_kernel_handle_t"
33+
name: hKernel
34+
desc: "[in] Kernel handle"
35+
- type: "size_t*"
36+
name: pSize
37+
desc: "[in, out] pointer to variable with size of GEN ISA binary"
38+
- type: "char*"
39+
name: pKernelBinary
40+
desc: [in,out] pointer to storage area for GEN ISA binary function

0 commit comments

Comments
 (0)