Skip to content

Commit

Permalink
Merge pull request oneapi-src#1816 from nrspruit/l0_intel_driver_version
Browse files Browse the repository at this point in the history
[L0] Use Intel Level Zero Driver String extension
  • Loading branch information
kbenzie committed Jul 10, 2024
2 parents 6b33a1b + 5dc794c commit 529e8b9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
3 changes: 0 additions & 3 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
for (uint32_t I = 0; I < ZeDriverCount; ++I) {
auto platform = std::make_unique<ur_platform_handle_t_>(ZeDrivers[I]);
UR_CALL(platform->initialize());
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_DRIVER, platform->ZeDriver,
(void **)&platform->ZeDriverHandleExpTranslated));

// Save a copy in the cache for future uses.
platforms.push_back(std::move(platform));
Expand Down
16 changes: 16 additions & 0 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,22 @@ const bool ExposeCSliceInAffinityPartitioning = [] {
const std::pair<int, int>
getRangeOfAllowedCopyEngines(const ur_device_handle_t &Device);

class ZeDriverVersionStringExtension {
// Pointer to function for Intel Driver Version String
ze_result_t (*zeIntelGetDriverVersionStringPointer)(
ze_driver_handle_t hDriver, char *, size_t *) = nullptr;

public:
// Whether platform supports Intel Driver Version String.
bool Supported;

ZeDriverVersionStringExtension() : Supported{false} {}

void setZeDriverVersionString(ur_platform_handle_t_ *Platform);
void getDriverVersionString(ze_driver_handle_t DriverHandle,
char *pDriverVersion, size_t *pVersionSize);
};

class ZeUSMImportExtension {
// Pointers to functions that import/release host memory into USM
ze_result_t (*zexDriverImportExternalPointer)(ze_driver_handle_t hDriver,
Expand Down
26 changes: 26 additions & 0 deletions source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,32 @@ ur_result_t urDeviceRelease(ur_device_handle_t Device) {
return UR_RESULT_SUCCESS;
}

void ZeDriverVersionStringExtension::setZeDriverVersionString(
ur_platform_handle_t_ *Platform) {
// Check if Intel Driver Version String is available. If yes, save the API
// pointer. The pointer will be used when reading the Driver Version for
// users.
ze_driver_handle_t DriverHandle = Platform->ZeDriver;
if (auto extension = Platform->zeDriverExtensionMap.find(
"ZE_intel_get_driver_version_string");
extension != Platform->zeDriverExtensionMap.end()) {
if (ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
(DriverHandle, "zeIntelGetDriverVersionString",
reinterpret_cast<void **>(
&zeIntelGetDriverVersionStringPointer))) == 0) {
// Intel Driver Version String is Supported by this Driver.
Supported = true;
}
}
}

void ZeDriverVersionStringExtension::getDriverVersionString(
ze_driver_handle_t DriverHandle, char *pDriverVersion,
size_t *pVersionSize) {
ZE_CALL_NOCHECK(zeIntelGetDriverVersionStringPointer,
(DriverHandle, pDriverVersion, pVersionSize));
}

void ZeUSMImportExtension::setZeUSMImport(ur_platform_handle_t_ *Platform) {
// Check if USM hostptr import feature is available. If yes, save the API
// pointers. The pointers will be used for both import/release of SYCL buffer
Expand Down
39 changes: 27 additions & 12 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
}

ur_result_t ur_platform_handle_t_::initialize() {
// Cache driver properties
ZeStruct<ze_driver_properties_t> ZeDriverProperties;
ZE2UR_CALL(zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
uint32_t DriverVersion = ZeDriverProperties.driverVersion;
// Intel Level-Zero GPU driver stores version as:
// | 31 - 24 | 23 - 16 | 15 - 0 |
// | Major | Minor | Build |
auto VersionMajor = std::to_string((DriverVersion & 0xFF000000) >> 24);
auto VersionMinor = std::to_string((DriverVersion & 0x00FF0000) >> 16);
auto VersionBuild = std::to_string(DriverVersion & 0x0000FFFF);
ZeDriverVersion = VersionMajor + "." + VersionMinor + "." + VersionBuild;

ZE2UR_CALL(zeDriverGetApiVersion, (ZeDriver, &ZeApiVersion));
ZeDriverApiVersion = std::to_string(ZE_MAJOR_VERSION(ZeApiVersion)) + "." +
std::to_string(ZE_MINOR_VERSION(ZeApiVersion));
Expand Down Expand Up @@ -211,6 +199,33 @@ ur_result_t ur_platform_handle_t_::initialize() {
zeDriverExtensionMap[extension.name] = extension.version;
}

ZE2UR_CALL(zelLoaderTranslateHandle, (ZEL_HANDLE_DRIVER, ZeDriver,
(void **)&ZeDriverHandleExpTranslated));

// Check if intel Driver Version Extension is supported.
ZeDriverVersionString.setZeDriverVersionString(this);
// Cache driver properties
ZeStruct<ze_driver_properties_t> ZeDriverProperties;
ZE2UR_CALL(zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
if (!ZeDriverVersionString.Supported) {
uint32_t DriverVersion = ZeDriverProperties.driverVersion;
// Intel Level-Zero GPU driver stores version as:
// | 31 - 24 | 23 - 16 | 15 - 0 |
// | Major | Minor | Build |
auto VersionMajor = std::to_string((DriverVersion & 0xFF000000) >> 24);
auto VersionMinor = std::to_string((DriverVersion & 0x00FF0000) >> 16);
auto VersionBuild = std::to_string(DriverVersion & 0x0000FFFF);
ZeDriverVersion = VersionMajor + "." + VersionMinor + "." + VersionBuild;
} else {
size_t sizeOfDriverString = 0;
ZeDriverVersionString.getDriverVersionString(ZeDriverHandleExpTranslated,
nullptr, &sizeOfDriverString);
ZeDriverVersion.resize(sizeOfDriverString);
ZeDriverVersionString.getDriverVersionString(ZeDriverHandleExpTranslated,
ZeDriverVersion.data(),
&sizeOfDriverString);
}

// Check if import user ptr into USM feature has been requested.
// If yes, then set up L0 API pointers if the platform supports it.
ZeUSMImport.setZeUSMImport(this);
Expand Down
4 changes: 4 additions & 0 deletions source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ struct ur_platform_handle_t_ : public _ur_platform {
// internal driver handle to allow calls to driver experimental apis.
ze_driver_handle_t ZeDriverHandleExpTranslated;

// Helper wrapper for working with Driver Version String extension in Level
// Zero.
ZeDriverVersionStringExtension ZeDriverVersionString;

// Cache versions info from zeDriverGetProperties.
std::string ZeDriverVersion;
std::string ZeDriverApiVersion;
Expand Down

0 comments on commit 529e8b9

Please sign in to comment.