Skip to content

Commit 7c71fb9

Browse files
authored
Update documentation on Init and add deprecation comments for init changes (#264)
* Update documentation on Init and add deprecation comments for init changes Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 94859b1 commit 7c71fb9

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

scripts/core/PROG.rst

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ Drivers
3232

3333
A driver object represents a collection of physical devices in the system accessed by the same Level-Zero driver.
3434

35-
- The application may query the number of Level-Zero drivers installed on the system, and their respective handles, using ${x}DriverGet.
36-
- More than one driver may be available in the system. For example, one driver may support two GPUs from one vendor, another driver supports a GPU from a different vendor, and finally a different driver may support an FPGA.
37-
- Driver objects are read-only, global constructs. i.e. Multiple calls to ${x}DriverGet will return identical driver handles.
35+
- The application may query the number of Level-Zero drivers installed on the system, and their respective handles, using zeInitDrivers, NOTE zeDriverGet is deprecated as of v1.10 of the L0 Spec.
36+
- zeInitDrivers replaces both zeInit and zeDriverGet as of v1.10 of the L0 Spec to both initialize the driver and query the number of drivers.
37+
- Usage of zeInitDrivers and zeDriverGet is mutually exclusive and should not be used together. Usage of them together will result in undefined behavior.
38+
- More than one driver may be available in the system. For example, one driver may support two GPUs from one vendor, another driver supports a GPU from a different vendor, and finally a different driver may support an NPU.
39+
- Driver objects are read-only, global constructs. i.e. Multiple calls to zeInitDrivers with the same flags will return identical driver handles.
3840
- A driver handle is primarily used during device discovery and during creation and management of contexts.
3941

4042
Device
@@ -63,40 +65,45 @@ The definition of what a root-device and a sub-device is for a specific device i
6365
Initialization and Discovery
6466
----------------------------
6567

66-
The Level-Zero API must be initialized by calling ${x}Init before calling any other API function.
67-
This function will load all Level-Zero driver(s) in the system into memory for the current process, for use by all Host threads.
68-
Simultaneous calls to ${x}Init are thread-safe and only one instance of each driver will be loaded.
68+
The Level-Zero API must be initialized by calling zeInitDrivers before calling any other API function. NOTE: zeInit is deprecated as of v1.10 of the L0 Spec.
69+
These functions will load all Level-Zero driver(s) in the system into memory for the current process, for use by all Host threads.
70+
Simultaneous calls to zeInitDrivers are thread-safe and only one instance of each driver will be loaded.
6971

70-
The following pseudo-code demonstrates a basic initialization and device discovery sequence:
72+
The following pseudo-code demonstrates a basic initialization and device discovery sequence for Core Drivers:
7173

7274
.. parsed-literal::
73-
74-
// Initialize the driver
75-
${x}Init(0);
76-
7775
// Discover all the driver instances
76+
ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC};
77+
desc.pNext = nullptr;
78+
desc.driverType = UINT32_MAX; // all driver types requested
7879
uint32_t driverCount = 0;
79-
${x}DriverGet(&driverCount, nullptr);
80+
ze_result_t result = zeInitDrivers(&driverCount, nullptr, &desc); // Query the number of drivers
81+
if (result != ZE_RESULT_SUCCESS) {
82+
return result; // no drivers found
83+
}
8084
81-
${x}_driver_handle_t* allDrivers = allocate(driverCount * sizeof(${x}_driver_handle_t));
82-
${x}DriverGet(&driverCount, allDrivers);
85+
ze_driver_handle_t* allDrivers = allocate(driverCount * sizeof(ze_driver_handle_t));
86+
result = zeInitDrivers(&driverCount, allDrivers, &desc); // Read the driver handles
87+
if (result != ZE_RESULT_SUCCESS) {
88+
return result; // no driver handles found
89+
}
8390
84-
// Find a driver instance with a GPU device
85-
${x}_driver_handle_t hDriver = nullptr;
86-
${x}_device_handle_t hDevice = nullptr;
91+
// Find a driver Handle that supports a GPU device type
92+
ze_driver_handle_t hDriver = nullptr;
93+
ze_device_handle_t hDevice = nullptr;
8794
for(i = 0; i < driverCount; ++i) {
8895
uint32_t deviceCount = 0;
89-
${x}DeviceGet(allDrivers[i], &deviceCount, nullptr);
96+
zeDeviceGet(allDrivers[i], &deviceCount, nullptr);
9097
91-
${x}_device_handle_t* allDevices = allocate(deviceCount * sizeof(${x}_device_handle_t));
92-
${x}DeviceGet(allDrivers[i], &deviceCount, allDevices);
98+
ze_device_handle_t* allDevices = allocate(deviceCount * sizeof(ze_device_handle_t));
99+
zeDeviceGet(allDrivers[i], &deviceCount, allDevices);
93100
94101
for(d = 0; d < deviceCount; ++d) {
95-
${x}_device_properties_t device_properties {};
96-
device_properties.stype = ${X}_STRUCTURE_TYPE_DEVICE_PROPERTIES;
97-
${x}DeviceGetProperties(allDevices[d], &device_properties);
102+
ze_device_properties_t device_properties {};
103+
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
104+
zeDeviceGetProperties(allDevices[d], &device_properties);
98105
99-
if(${X}_DEVICE_TYPE_GPU == device_properties.type) {
106+
if(ZE_DEVICE_TYPE_GPU == device_properties.type) {
100107
hDriver = allDrivers[i];
101108
hDevice = allDevices[d];
102109
break;

scripts/core/driver.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class: $x
2626
name: Init
2727
decl: static
2828
ordinal: "0"
29-
details:
30-
- "The application must call this function before calling any other function."
29+
details:
30+
- "@deprecated since 1.10. Please use zeInitDrivers()"
31+
- "The application must call this function or zeInitDrivers before calling any other function."
3132
- "If this function is not called then all other functions will return $X_RESULT_ERROR_UNINITIALIZED."
3233
- "Only one instance of each driver will be initialized per process."
3334
- "The application may call this function multiple times with different flags or environment variables enabled."
@@ -51,6 +52,8 @@ ordinal: "0"
5152
analogue:
5253
- clGetPlatformIDs
5354
details:
55+
- "@deprecated since 1.10. Please use zeInitDrivers()"
56+
- "Usage of zeInitDrivers and zeDriverGet is mutually exclusive and should not be used together. Usage of them together will result in undefined behavior."
5457
- "A driver represents a collection of physical devices."
5558
- "Multiple calls to this function will return identical driver handles, in the same order."
5659
- "The application may pass nullptr for pDrivers when only querying the number of drivers."
@@ -111,14 +114,13 @@ version: "1.10"
111114
decl: static
112115
ordinal: "0"
113116
details:
114-
- "The application must call this function or zeInit before calling any other function."
115-
- "The application can call InitDrivers or zeInit to init the drivers on the system."
116-
- "Calls to zeInit or InitDrivers will not alter the drivers retrieved thru either api."
117-
- "Drivers init thru zeInit or InitDrivers will not be reInitialized once init in an application.
117+
- "The application must call this function or zeInit before calling any other function. (zeInit is [Deprecated] and is replaced by zeInitDrivers)"
118+
- "Calls to zeInit[Deprecated] or InitDrivers will not alter the drivers retrieved thru either api."
119+
- "Drivers init thru zeInit[Deprecated] or InitDrivers will not be reInitialized once init in an application.
118120
The Loader will determine if the already init driver needs to be delivered to the user thru the init type flags."
119121
- "Already init Drivers will not be uninitialized if the call to InitDrivers does not include that driver's type.
120122
Those init drivers which don't match the init flags will not have their driver handles returned to the user in that InitDrivers call."
121-
- "If this function or zeInit is not called, then all other functions will return $X_RESULT_ERROR_UNINITIALIZED."
123+
- "If this function or zeInit[Deprecated] is not called, then all other functions will return $X_RESULT_ERROR_UNINITIALIZED."
122124
- "Only one instance of each driver will be initialized per process."
123125
- "A driver represents a collection of physical devices."
124126
- "Multiple calls to this function will return identical driver handles, in the same order."

0 commit comments

Comments
 (0)