From 39f42b20ba1e79cbdc16637a4de05f9e1b1225a6 Mon Sep 17 00:00:00 2001 From: Jaroslaw Chodor Date: Mon, 24 Aug 2020 01:55:47 +0200 Subject: [PATCH] Require OpenCLDriverName in DeviceRegistryPath Change-Id: I93a8ca95082f6ddb48adffe33145568f32d77418 Signed-off-by: Mateusz Jablonski --- .../os_interface/windows/driver_info_tests.cpp | 15 +++++++++++++-- .../unit_test/os_interface/windows/sys_calls.cpp | 9 +++++++++ .../os_interface/linux/settings_reader_create.cpp | 4 ++++ .../windows/debug_registry_reader.cpp | 5 +++++ .../os_interface/windows/driver_info_windows.cpp | 5 +++++ shared/source/os_interface/windows/sys_calls.cpp | 3 +++ shared/source/os_interface/windows/sys_calls.h | 1 + shared/source/os_interface/windows/wddm/wddm.cpp | 2 +- shared/source/utilities/debug_settings_reader.h | 2 +- 9 files changed, 42 insertions(+), 4 deletions(-) diff --git a/opencl/test/unit_test/os_interface/windows/driver_info_tests.cpp b/opencl/test/unit_test/os_interface/windows/driver_info_tests.cpp index c032276136..277e91695e 100644 --- a/opencl/test/unit_test/os_interface/windows/driver_info_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/driver_info_tests.cpp @@ -118,9 +118,10 @@ class MockRegistryReader : public SettingsReader { } else if (key == "UserModeDriverNameWOW") { properMediaSharingExtensions = true; return returnString; - } - if (key == "DriverStorePathForComputeRuntime") { + } else if (key == "DriverStorePathForComputeRuntime") { return driverStorePath; + } else if (key == "OpenCLDriverName") { + return openCLDriverName; } return value; } @@ -133,6 +134,7 @@ class MockRegistryReader : public SettingsReader { bool properNameKey = false; bool properVersionKey = false; std::string driverStorePath = "driverStore\\0x8086"; + std::string openCLDriverName = "igdrcl.dll"; bool properMediaSharingExtensions = false; bool using64bit = false; std::string returnString = ""; @@ -231,6 +233,15 @@ TEST(DriverInfo, givenInitializedOsInterfaceWhenCreateDriverInfoWindowsThenSetRe EXPECT_STREQ(driverInfo->getRegistryReaderRegKey(), driverInfo->reader->getRegKey()); }; +TEST_F(DriverInfoWindowsTest, whenThereIsNoOpenCLDriverNamePointedByDriverInfoThenItIsNotCompatible) { + VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); + currentLibraryPathBackup = L"driverStore\\0x8086\\myLib.dll"; + + static_cast(driverInfo->registryReader.get())->openCLDriverName = ""; + + EXPECT_FALSE(driverInfo->isCompatibleDriverStore()); +} + TEST_F(DriverInfoWindowsTest, whenCurrentLibraryIsLoadedFromDriverStorePointedByDriverInfoThenItIsCompatible) { VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); currentLibraryPathBackup = L"driverStore\\0x8086\\myLib.dll"; diff --git a/opencl/test/unit_test/os_interface/windows/sys_calls.cpp b/opencl/test/unit_test/os_interface/windows/sys_calls.cpp index 3d08a141ef..a36e95978a 100644 --- a/opencl/test/unit_test/os_interface/windows/sys_calls.cpp +++ b/opencl/test/unit_test/os_interface/windows/sys_calls.cpp @@ -45,6 +45,15 @@ DWORD getModuleFileName(HMODULE hModule, LPWSTR lpFilename, DWORD nSize) { lstrcpyW(lpFilename, currentLibraryPath); return TRUE; } + +char *openCLDriverName = "igdrcl.dll"; + +char *getenv(const char *variableName) { + if (strcmp(variableName, "OpenCLDriverName") == 0) { + return openCLDriverName; + } + return ::getenv(variableName); +} } // namespace SysCalls } // namespace NEO diff --git a/shared/source/os_interface/linux/settings_reader_create.cpp b/shared/source/os_interface/linux/settings_reader_create.cpp index 70073f6b25..e46c1501f6 100644 --- a/shared/source/os_interface/linux/settings_reader_create.cpp +++ b/shared/source/os_interface/linux/settings_reader_create.cpp @@ -12,4 +12,8 @@ namespace NEO { SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string ®Key) { return new EnvironmentVariableReader; } + +char *SettingsReader::getenv(const char *settingName) { + return ::getenv(settingName); +} } // namespace NEO diff --git a/shared/source/os_interface/windows/debug_registry_reader.cpp b/shared/source/os_interface/windows/debug_registry_reader.cpp index 936f7abab2..1a0e2e9661 100644 --- a/shared/source/os_interface/windows/debug_registry_reader.cpp +++ b/shared/source/os_interface/windows/debug_registry_reader.cpp @@ -8,6 +8,7 @@ #include "shared/source/os_interface/windows/debug_registry_reader.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/windows/sys_calls.h" #include "shared/source/os_interface/windows/windows_wrapper.h" #include "shared/source/utilities/debug_settings_reader.h" @@ -19,6 +20,10 @@ SettingsReader *SettingsReader::createOsReader(bool userScope, const std::string return new RegistryReader(userScope, regKey); } +char *SettingsReader::getenv(const char *settingName) { + return SysCalls::getenv(settingName); +} + RegistryReader::RegistryReader(bool userScope, const std::string ®Key) : registryReadRootKey(regKey) { hkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; setUpProcessName(); diff --git a/shared/source/os_interface/windows/driver_info_windows.cpp b/shared/source/os_interface/windows/driver_info_windows.cpp index 4501fb36c0..3d245d2a16 100644 --- a/shared/source/os_interface/windows/driver_info_windows.cpp +++ b/shared/source/os_interface/windows/driver_info_windows.cpp @@ -68,6 +68,11 @@ std::string DriverInfoWindows::getVersion(std::string defaultVersion) { bool DriverInfoWindows::isCompatibleDriverStore() const { auto currentLibraryPath = getCurrentLibraryPath(); + auto openclDriverName = registryReader.get()->getSetting("OpenCLDriverName", std::string{}); + if (openclDriverName.empty()) { + return false; + } + auto driverStorePath = registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath); return currentLibraryPath.find(driverStorePath.c_str()) == 0u; } diff --git a/shared/source/os_interface/windows/sys_calls.cpp b/shared/source/os_interface/windows/sys_calls.cpp index 0fffb91569..032988f231 100644 --- a/shared/source/os_interface/windows/sys_calls.cpp +++ b/shared/source/os_interface/windows/sys_calls.cpp @@ -28,6 +28,9 @@ BOOL getModuleHandle(DWORD dwFlags, LPCWSTR lpModuleName, HMODULE *phModule) { DWORD getModuleFileName(HMODULE hModule, LPWSTR lpFilename, DWORD nSize) { return GetModuleFileName(hModule, lpFilename, nSize); } +char *getenv(const char *variableName) { + return ::getenv(variableName); +} } // namespace SysCalls } // namespace NEO diff --git a/shared/source/os_interface/windows/sys_calls.h b/shared/source/os_interface/windows/sys_calls.h index 558707aea9..546c23efe7 100644 --- a/shared/source/os_interface/windows/sys_calls.h +++ b/shared/source/os_interface/windows/sys_calls.h @@ -17,6 +17,7 @@ BOOL closeHandle(HANDLE hObject); BOOL getSystemPowerStatus(LPSYSTEM_POWER_STATUS systemPowerStatusPtr); BOOL getModuleHandle(DWORD dwFlags, LPCWSTR lpModuleName, HMODULE *phModule); DWORD getModuleFileName(HMODULE hModule, LPWSTR lpFilename, DWORD nSize); +char *getenv(const char *variableName); } // namespace SysCalls diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index a6c0cf0bb9..f1d37872a5 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -144,7 +144,7 @@ bool Wddm::queryAdapterInfo() { memcpy_s(&gfxPartition, sizeof(gfxPartition), &adapterInfo.GfxPartition, sizeof(GMM_GFX_PARTITIONING)); memcpy_s(&adapterBDF, sizeof(adapterBDF), &adapterInfo.stAdapterBDF, sizeof(ADAPTER_BDF)); - deviceRegistryPath = adapterInfo.DeviceRegistryPath; + deviceRegistryPath = std::string(adapterInfo.DeviceRegistryPath, sizeof(adapterInfo.DeviceRegistryPath)).c_str(); systemSharedMemory = adapterInfo.SystemSharedMemory; dedicatedVideoMemory = adapterInfo.DedicatedVideoMemory; diff --git a/shared/source/utilities/debug_settings_reader.h b/shared/source/utilities/debug_settings_reader.h index 9491f9fff5..cc5ea29a06 100644 --- a/shared/source/utilities/debug_settings_reader.h +++ b/shared/source/utilities/debug_settings_reader.h @@ -30,6 +30,6 @@ class SettingsReader { virtual std::string getSetting(const char *settingName, const std::string &value) = 0; virtual const char *appSpecificLocation(const std::string &name) = 0; static const char *settingsFileName; - MOCKABLE_VIRTUAL char *getenv(const char *settingName) { return ::getenv(settingName); }; + MOCKABLE_VIRTUAL char *getenv(const char *settingName); }; }; // namespace NEO