Skip to content

Commit e02d78b

Browse files
Merge pull request #1933 from nrspruit/fix_driver_version_check
[L0] Fix Driver Version check to use extension and tuple check
2 parents e50a4dd + c12957b commit e02d78b

File tree

6 files changed

+70
-33
lines changed

6 files changed

+70
-33
lines changed

source/adapters/level_zero/command_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ ur_result_t createMainCommandList(ur_context_handle_t Context,
610610
bool canBeInOrder(ur_context_handle_t Context,
611611
const ur_exp_command_buffer_desc_t *CommandBufferDesc) {
612612
// In-order command-lists are not available in old driver version.
613-
bool CompatibleDriver = isDriverVersionNewerOrSimilar(
614-
Context->getPlatform()->ZeDriver, 1, 3, L0_DRIVER_INORDER_MIN_VERSION);
613+
bool CompatibleDriver = Context->getPlatform()->isDriverVersionNewerOrSimilar(
614+
1, 3, L0_DRIVER_INORDER_MIN_VERSION);
615615
return CompatibleDriver
616616
? (CommandBufferDesc ? CommandBufferDesc->isInOrder : false)
617617
: false;

source/adapters/level_zero/common.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,6 @@ ur_result_t ze2urResult(ze_result_t ZeResult) {
6767
}
6868
}
6969

70-
/// Checks the version of the level-zero driver.
71-
/// @param ZeDriver Level Zero Driver handle
72-
/// @param VersionMajor Major verion number to compare to.
73-
/// @param VersionMinor Minor verion number to compare to.
74-
/// @param VersionBuild Build verion number to compare to.
75-
/// @return true is the version of the driver is higher than or equal to the
76-
/// compared version
77-
bool isDriverVersionNewerOrSimilar(ze_driver_handle_t ZeDriver,
78-
uint32_t VersionMajor, uint32_t VersionMinor,
79-
uint32_t VersionBuild) {
80-
ZeStruct<ze_driver_properties_t> ZeDriverProperties;
81-
ZE2UR_CALL(zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
82-
uint32_t DriverVersion = ZeDriverProperties.driverVersion;
83-
auto DriverVersionMajor = (DriverVersion & 0xFF000000) >> 24;
84-
auto DriverVersionMinor = (DriverVersion & 0x00FF0000) >> 16;
85-
auto DriverVersionBuild = DriverVersion & 0x0000FFFF;
86-
87-
return ((DriverVersionMajor >= VersionMajor) &&
88-
(DriverVersionMinor >= VersionMinor) &&
89-
(DriverVersionBuild >= VersionBuild));
90-
}
91-
9270
// This function will ensure compatibility with both Linux and Windows for
9371
// setting environment variables.
9472
bool setEnvVar(const char *name, const char *value) {

source/adapters/level_zero/common.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@ bool setEnvVar(const char *name, const char *value);
317317
// Map Level Zero runtime error code to UR error code.
318318
ur_result_t ze2urResult(ze_result_t ZeResult);
319319

320-
/// Checks the version of the level-zero driver.
321-
bool isDriverVersionNewerOrSimilar(ze_driver_handle_t ZeDriver,
322-
uint32_t VersionMajor, uint32_t VersionMinor,
323-
uint32_t VersionBuild);
324-
325320
// Trace a call to Level-Zero RT
326321
#define ZE2UR_CALL(ZeName, ZeArgs) \
327322
{ \

source/adapters/level_zero/device.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,10 @@ bool ur_device_handle_t_::useDriverInOrderLists() {
11731173
// Use in-order lists implementation from L0 driver instead
11741174
// of adapter's implementation.
11751175

1176-
ze_driver_handle_t ZeDriver = this->Platform->ZeDriver;
1177-
11781176
static const bool UseDriverInOrderLists = [&] {
11791177
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
1180-
bool CompatibleDriver = isDriverVersionNewerOrSimilar(
1181-
ZeDriver, 1, 3, L0_DRIVER_INORDER_MIN_VERSION);
1178+
bool CompatibleDriver = this->Platform->isDriverVersionNewerOrSimilar(
1179+
1, 3, L0_DRIVER_INORDER_MIN_VERSION);
11821180
if (!UrRet)
11831181
return CompatibleDriver;
11841182
return std::atoi(UrRet) != 0;

source/adapters/level_zero/platform.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,67 @@ ur_result_t ur_platform_handle_t_::initialize() {
266266
return UR_RESULT_SUCCESS;
267267
}
268268

269+
/// Checks the version of the level-zero driver.
270+
/// @param VersionMajor Major verion number to compare to.
271+
/// @param VersionMinor Minor verion number to compare to.
272+
/// @param VersionBuild Build verion number to compare to.
273+
/// @return true is the version of the driver is higher than or equal to the
274+
/// compared version
275+
bool ur_platform_handle_t_::isDriverVersionNewerOrSimilar(
276+
uint32_t VersionMajor, uint32_t VersionMinor, uint32_t VersionBuild) {
277+
uint32_t DriverVersionMajor = 0;
278+
uint32_t DriverVersionMinor = 0;
279+
uint32_t DriverVersionBuild = 0;
280+
if (!ZeDriverVersionString.Supported) {
281+
ZeStruct<ze_driver_properties_t> ZeDriverProperties;
282+
ZE2UR_CALL(zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
283+
uint32_t DriverVersion = ZeDriverProperties.driverVersion;
284+
DriverVersionMajor = (DriverVersion & 0xFF000000) >> 24;
285+
DriverVersionMinor = (DriverVersion & 0x00FF0000) >> 16;
286+
DriverVersionBuild = DriverVersion & 0x0000FFFF;
287+
} else {
288+
std::string ZeDriverVersion;
289+
size_t sizeOfDriverString = 0;
290+
ZeDriverVersionString.getDriverVersionString(ZeDriverHandleExpTranslated,
291+
nullptr, &sizeOfDriverString);
292+
ZeDriverVersion.resize(sizeOfDriverString);
293+
ZeDriverVersionString.getDriverVersionString(ZeDriverHandleExpTranslated,
294+
ZeDriverVersion.data(),
295+
&sizeOfDriverString);
296+
297+
// Intel driver version string is in the format:
298+
// Major.Minor.Build+Hotfix where hotfix is optional.
299+
std::stringstream VersionString(ZeDriverVersion);
300+
301+
std::string VersionValue;
302+
std::vector<std::string> VersionValues;
303+
char VersionDelim = '.';
304+
char HotfixDelim = '+';
305+
306+
while (getline(VersionString, VersionValue, VersionDelim)) {
307+
VersionValues.push_back(VersionValue);
308+
}
309+
// If the extension exists, but the string value comes by empty or
310+
// malformed, assume this is a developer driver.
311+
if (VersionValues.size() >= 3) {
312+
DriverVersionMajor = atoi(VersionValues[0].c_str());
313+
DriverVersionMinor = atoi(VersionValues[1].c_str());
314+
std::stringstream HotfixString(VersionValues[2]);
315+
std::vector<std::string> BuildHotfixVersionValues;
316+
// Check to see if there is a hotfix value and strip it off.
317+
while (getline(HotfixString, VersionValue, HotfixDelim)) {
318+
BuildHotfixVersionValues.push_back(VersionValue);
319+
}
320+
DriverVersionBuild = atoi(BuildHotfixVersionValues[0].c_str());
321+
} else {
322+
return true;
323+
}
324+
}
325+
return std::make_tuple(DriverVersionMajor, DriverVersionMinor,
326+
DriverVersionBuild) >=
327+
std::make_tuple(VersionMajor, VersionMinor, VersionBuild);
328+
}
329+
269330
// Get the cached PI device created for the L0 device handle.
270331
// Return NULL if no such PI device found.
271332
ur_device_handle_t

source/adapters/level_zero/platform.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct ur_platform_handle_t_ : public _ur_platform {
6262
// If not found, then nullptr is returned.
6363
ur_device_handle_t getDeviceFromNativeHandle(ze_device_handle_t);
6464

65+
/// Checks the version of the level-zero driver.
66+
bool isDriverVersionNewerOrSimilar(uint32_t VersionMajor,
67+
uint32_t VersionMinor,
68+
uint32_t VersionBuild);
69+
6570
// Keep track of all contexts in the platform. This is needed to manage
6671
// a lifetime of memory allocations in each context when there are kernels
6772
// with indirect access.

0 commit comments

Comments
 (0)