Skip to content

Commit 7a5c55c

Browse files
authored
Driver DDI Handles Extension (#277)
* Driver DDI Handles Extension * Have single ze_handle_t and update .rst docs * Add flag for checking if a ddiTable is valid Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 054d7b5 commit 7a5c55c

File tree

7 files changed

+205
-0
lines changed

7 files changed

+205
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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_driver_ddi_handles:
12+
13+
==========================================
14+
Driver Direct Device Interface (DDI) Handles Extension
15+
==========================================
16+
17+
API
18+
----
19+
20+
* Enumerations
21+
* ${x}_driver_ddi_handles_ext_version_t
22+
23+
* Structures
24+
* ${x}_driver_ddi_handle_ext_flags_t
25+
* ${x}_driver_ddi_handles_ext_properties_t
26+
* ze_handle_t
27+
* ze_dditable_driver_t
28+
* zet_dditable_driver_t
29+
* zes_dditable_driver_t
30+
31+
See `ze*_ddi.h` for definitions of `ze_dditable_driver_t`, `zet_dditable_driver_t`, `zes_dditable_driver_t`.
32+
`ze_handle_t` is defined in ze_ddi_common.h. To use it, include `ze_ddi_common.h`.
33+
34+
Handle Structures:
35+
~~~~~~~~~~~~~~~~~
36+
37+
/// @brief Handle with pointer to Dispatch Container allocated by the driver at the beginning of every L0 Core handle
38+
typedef struct _ze_handle_t
39+
{
40+
ze_dditable_driver_t *pCore; // [in] pointer to _ze_dditable_t_ object related to this handle
41+
zet_dditable_driver_t *pTools; // [in] pointer to _zet_dditable_t_ object related to this handle
42+
zes_dditable_driver_t *pSysman; // [in] pointer to _zes_dditable_t_ object related to this handle
43+
} ze_handle_t;
44+
45+
DDI Handles Extension:
46+
~~~~~~~~~~~~~~~~~~~~~
47+
48+
Nowadays there are many possible scenarios of multiple Level Zero runtimes in the system (GPU + NPU, dGPU + iGPU on Windows, mainstream GPU + legacy GPU on Linux).
49+
Our current handling of multi runtime scenario in Loader has many issues:
50+
- performance degradation
51+
- Level Zero API handles are stored in per-type maps, accessing these maps costs, especially in hot paths
52+
- putting and removing entries from map needs additional mutex to ensure thread-safety
53+
- there is significant perfomance difference between runing application when there is only one runtime active and many runtimes active, even if only one is really used by application.
54+
As initialization overhead is acceptable, any further API calls should not cause performance degradation. E.g. when running [`SetKernelArgSvmPointer`](https://github.com/intel/compute-benchmarks/blob/master/source/benchmarks/api_overhead_benchmark/implementations/l0/set_kernel_arg_svm_pointer_l0.cpp) test from [`api_overhead_benchmark`](https://github.com/intel/compute-benchmarks/tree/master/source/benchmarks/api_overhead_benchmark) there is degradation from 0.817us to 2.724us caused only by presence of second runtime on the system.
55+
- when using driver extensions, application bypasses Level Zero loader and calls runtime functions directly
56+
- handles that application got from loader is wrapped by loader's handle type and can't be passed to runtime directly, therefore translation is required;
57+
translation could be applied on two sides - app side / runtime side. How to detect double translation?
58+
- extension may create ze_event_t object that can be then used in core API - loader cannot recognize it
59+
60+
The solution which solves this problem is to define a base layout of every handle type directly in L0 spec ensuring that all L0 API handles contain a header with pointers to appropriate driver ddi tables.
61+
Backward compatibility is covered as new loader will still support runtimes that do not support this extension.
62+
Loader should verify the support based on extension property queried from zeDriverGetExtensionProperties.
63+
64+
Example Implementation of L0 Loader functions:
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
67+
.. parsed-literal::
68+
ZE_APIEXPORT ze_result_t ZE_APICALL zeContextCreate(
69+
ze_driver_handle_t hDriver,
70+
const ze_context_desc_t *desc,
71+
ze_context_handle_t *phContext) {
72+
return hDriver->pCore->pContext->pfnCreate(hDriver, desc, phContext);
73+
}

scripts/core/common.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ etors:
587587
desc: $x_external_semaphore_wait_params_ext_t
588588
version: "1.12"
589589
value: "0x00020026"
590+
- name: DRIVER_DDI_HANDLES_EXT_PROPERTIES
591+
desc: $x_driver_ddi_handles_ext_properties_t
592+
version: "1.12"
593+
value: "0x00020027"
590594
- name: COMMAND_GRAPH_EXP_DESC
591595
desc: $x_command_graph_exp_desc_t
592596
version: "2.0"

scripts/core/driverDDIHandles.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 Driver Direct Device Interface (DDI) Handles"
11+
version: "1.12"
12+
--- #--------------------------------------------------------------------------
13+
type: macro
14+
desc: "Driver Direct Device Interface (DDI) Handles Extension Name"
15+
version: "1.12"
16+
name: $X_DRIVER_DDI_HANDLES_EXT_NAME
17+
value: '"$X_extension_driver_ddi_handles"'
18+
--- #--------------------------------------------------------------------------
19+
type: enum
20+
desc: "Driver Direct Device Interface (DDI) Handles Extension Version(s)"
21+
version: "1.12"
22+
name: $x_driver_ddi_handles_ext_version_t
23+
etors:
24+
- name: "1_0"
25+
value: "$X_MAKE_VERSION( 1, 0 )"
26+
desc: "version 1.0"
27+
--- #--------------------------------------------------------------------------
28+
type: enum
29+
desc: "Driver Direct Device Interface (DDI) Handle Extension Flags"
30+
class: $xDriver
31+
name: $x_driver_ddi_handle_ext_flags_t
32+
etors:
33+
- name: DDI_HANDLE_EXT_SUPPORTED
34+
desc: "Driver Supports DDI Handles Extension"
35+
--- #--------------------------------------------------------------------------
36+
type: struct
37+
desc: "Driver DDI Handles properties queried using $xDriverGetProperties"
38+
version: "1.12"
39+
class: $xDriver
40+
name: $x_driver_ddi_handles_ext_properties_t
41+
base: $x_base_properties_t
42+
members:
43+
- type: $x_driver_ddi_handle_ext_flags_t
44+
name: flags
45+
desc: |
46+
[out] 0 (none) or a valid combination of ::ze_driver_ddi_handle_ext_flags_t
47+
details:
48+
- "This structure may be returned from $xDriverGetProperties, via the `pNext` member of $x_driver_properties_t."

scripts/generate_code.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ def _mako_ddi_h(path, namespace, tags, version, revision, specs, meta):
6868
specs=specs,
6969
meta=meta)
7070

71+
"""
72+
generates ddi_common header
73+
"""
74+
def _mako_ddi_common_h(path, namespace, tags, version, revision, specs, meta):
75+
template = "ddi_common.h.mako"
76+
fin = os.path.join("templates", template)
77+
78+
filename = "%s_ddi_common.h"%(namespace)
79+
fout = os.path.join(path, filename)
80+
81+
print("Generating %s..."%fout)
82+
return util.makoWrite(
83+
fin, fout,
84+
ver=version,
85+
rev=revision,
86+
namespace=namespace,
87+
tags=tags,
88+
specs=specs,
89+
meta=meta)
90+
7191
"""
7292
generates python files from the specification documents
7393
"""
@@ -95,6 +115,8 @@ def _generate_api_cpp(incpath, srcpath, namespace, tags, version, revision, spec
95115
loc = _mako_api_h(incpath, namespace, tags, version, revision, specs, meta)
96116
loc += _mako_api_cpp(srcpath, namespace, tags, version, revision, specs, meta)
97117
loc += _mako_ddi_h(incpath, namespace, tags, version, revision, specs, meta)
118+
if namespace == "ze":
119+
loc += _mako_ddi_common_h(incpath, namespace, tags, version, revision, specs, meta)
98120

99121
return loc
100122

scripts/templates/ddi.h.mako

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ typedef struct _${n}_dditable_t
9595
${th.append_ws(tbl['type'], 35)} ${tbl['name']};
9696
%endfor
9797
} ${n}_dditable_t;
98+
/// @brief Container for all DDI tables with version and tables set by the Driver
99+
typedef struct _${n}_dditable_driver_t
100+
{
101+
ze_api_version_t version;
102+
uint8_t isValidFlag;
103+
%for tbl in th.get_pfntables(specs, meta, n, tags):
104+
${th.append_ws(tbl['ptype'], 35)} ${tbl['name']};
105+
%endfor
106+
} ${n}_dditable_driver_t;
98107

99108
#if defined(__cplusplus)
100109
} // extern "C"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<%
2+
import re
3+
from templates import helper as th
4+
%><%
5+
n=namespace
6+
N=n.upper()
7+
8+
x=tags['$x']
9+
X=x.upper()
10+
%>/*
11+
*
12+
* Copyright (C) 2024 Intel Corporation
13+
*
14+
* SPDX-License-Identifier: MIT
15+
*
16+
* @file ${n}_ddi_common.h
17+
* @version v${ver}-r${rev}
18+
*
19+
*/
20+
#ifndef _${N}_DDI_COMMON_H
21+
#define _${N}_DDI_COMMON_H
22+
#if defined(__cplusplus)
23+
#pragma once
24+
#endif
25+
#include "ze_ddi.h"
26+
#include "zet_ddi.h"
27+
#include "zes_ddi.h"
28+
29+
#if defined(__cplusplus)
30+
extern "C" {
31+
#endif
32+
33+
/// @brief Handle with pointers to Dispatch Tables allocated by the driver at the beginning of every L0 object handle.
34+
typedef struct _${n}_handle_t
35+
{
36+
ze_dditable_driver_t *pCore; // [in] pointer to _ze_dditable_t_ object related to this handle
37+
zet_dditable_driver_t *pTools; // [in] pointer to _zet_dditable_t_ object related to this handle
38+
zes_dditable_driver_t *pSysman; // [in] pointer to _zes_dditable_t_ object related to this handle
39+
} ${n}_handle_t;
40+
41+
#if defined(__cplusplus)
42+
} // extern "C"
43+
#endif
44+
45+
#endif // _${N}_DDI_COMMON_H

scripts/templates/helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def get_pfntables(specs, meta, namespace, tags):
922922
if len(objs) > 0:
923923
name = get_table_name(namespace, tags, objs[0])
924924
table = "%s_%s_dditable_t"%(namespace, _camel_to_snake(name))
925+
pTable = "%s_%s_dditable_t *"%(namespace, _camel_to_snake(name))
925926

926927
params = []
927928
params.append({
@@ -944,13 +945,15 @@ def get_pfntables(specs, meta, namespace, tags):
944945
tables.append({
945946
'name': name,
946947
'type': table,
948+
'ptype': pTable,
947949
'export': export,
948950
'pfn': pfn,
949951
'functions': objs
950952
})
951953
if len(exp_objs) > 0:
952954
name = get_table_name(namespace, tags, exp_objs[0])
953955
table = "%s_%s_dditable_t"%(namespace, _camel_to_snake(name))
956+
pTable = "%s_%s_dditable_t *"%(namespace, _camel_to_snake(name))
954957

955958
params = []
956959
params.append({
@@ -973,6 +976,7 @@ def get_pfntables(specs, meta, namespace, tags):
973976
tables.append({
974977
'name': name,
975978
'type': table,
979+
'ptype': pTable,
976980
'export': export,
977981
'pfn': pfn,
978982
'functions': exp_objs

0 commit comments

Comments
 (0)