diff --git a/projects/clr/opencl/amdocl/cl_icd.cpp b/projects/clr/opencl/amdocl/cl_icd.cpp index 4fce08b06c..1d9638f624 100644 --- a/projects/clr/opencl/amdocl/cl_icd.cpp +++ b/projects/clr/opencl/amdocl/cl_icd.cpp @@ -132,134 +132,6 @@ cl_icd_dispatch amd::ICDDispatchedObject::icdVendorDispatch_[] = { clSetProgramReleaseCallback, clSetProgramSpecializationConstant }}; -#if defined(_WIN32) -#include - -#pragma comment(lib, "shlwapi.lib") - -static bool ShouldLoadPlatform() { - // Get the OpenCL ICD registry values - HKEY platformsKey = NULL; - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Khronos\\OpenCL\\Vendors", 0, KEY_READ, - &platformsKey) != ERROR_SUCCESS) - return true; - - std::vector registryValues; - DWORD dwIndex = 0; - while (true) { - char cszLibraryName[1024] = {0}; - DWORD dwLibraryNameSize = sizeof(cszLibraryName); - DWORD dwLibraryNameType = 0; - DWORD dwValue = 0; - DWORD dwValueSize = sizeof(dwValue); - - if (RegEnumValueA(platformsKey, dwIndex++, cszLibraryName, &dwLibraryNameSize, NULL, - &dwLibraryNameType, (LPBYTE)&dwValue, &dwValueSize) != ERROR_SUCCESS) - break; - // Require that the value be a DWORD and equal zero - if (dwLibraryNameType != REG_DWORD || dwValue != 0) { - continue; - } - registryValues.push_back(cszLibraryName); - } - RegCloseKey(platformsKey); - - HMODULE hm = NULL; - if (!GetModuleHandleExA( - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - (LPCSTR)&ShouldLoadPlatform, &hm)) - return true; - - char cszDllPath[1024] = {0}; - if (!GetModuleFileNameA(hm, cszDllPath, sizeof(cszDllPath))) return true; - - // If we are loaded from the DriverStore, then there should be a registry - // value matching our current module absolute path. - if (std::find(registryValues.begin(), registryValues.end(), cszDllPath) == registryValues.end()) - return true; - - LPSTR cszFileName; - char buffer[1024] = {0}; - if (!GetFullPathNameA(cszDllPath, sizeof(buffer), buffer, &cszFileName)) return true; - - // We found an absolute path in the registry that matched this DLL, now - // check if there is also an entry with the same filename. - if (std::find(registryValues.begin(), registryValues.end(), cszFileName) == registryValues.end()) - return true; - - // Lastly, check if there is a DLL with the same name in the System folder. - char cszSystemPath[1024] = {0}; -#if defined(ATI_BITS_32) - if (!GetSystemWow64DirectoryA(cszSystemPath, sizeof(cszSystemPath))) -#endif // defined(ATI_BITS_32) - if (!GetSystemDirectoryA(cszSystemPath, sizeof(cszSystemPath))) return true; - - std::string systemDllPath; - systemDllPath.append(cszSystemPath).append("\\").append(cszFileName); - if (!PathFileExistsA(systemDllPath.c_str())) { - return true; - } - - // If we get here, then all 3 conditions are true: - // - An entry in the registry with an absolute path matches the current DLL - // - An entry in the registry with a relative path matches the current DLL - // - A DLL with the same name was found in the system directory - // - // We should not load this platform! - - return false; -} - -#else - -#include - -// If there is only one platform, load it. -// If there is more than one platform, only load platforms that have visible devices -// If all platforms have no devices available, only load the PAL platform -static bool ShouldLoadPlatform() { - bool shouldLoad = true; - - if (!amd::Runtime::initialized()) { - amd::Runtime::init(); - } - const int numDevices = amd::Device::numDevices(CL_DEVICE_TYPE_GPU, false); - - void *otherPlatform = nullptr; - if (amd::IS_LEGACY) { - otherPlatform = dlopen("libamdocl64.so", RTLD_LAZY); - if (otherPlatform != nullptr) { // Present platform exists - shouldLoad = numDevices > 0; - } - } else { - otherPlatform = dlopen("libamdocl-orca64.so", RTLD_LAZY); - if (otherPlatform != nullptr) { // Legacy platform exists - // gcc4.8 doesn't support casting void* to a function pointer - // Work around this by creating a typedef untill we upgrade the compiler - typedef void*(*clGetFunctionAddress_t)(const char *); - typedef cl_int(*clIcdGetPlatformIDs_t)(cl_uint, cl_platform_id *, cl_uint *); - - clGetFunctionAddress_t legacyGetFunctionAddress = - reinterpret_cast(dlsym(otherPlatform, "clGetExtensionFunctionAddress")); - clIcdGetPlatformIDs_t legacyGetPlatformIDs = - reinterpret_cast(legacyGetFunctionAddress("clIcdGetPlatformIDsKHR")); - - cl_uint numLegacyPlatforms = 0; - legacyGetPlatformIDs(0, nullptr, &numLegacyPlatforms); - - shouldLoad = (numDevices > 0) || (numLegacyPlatforms == 0); - } - } - - if (otherPlatform != nullptr) { - dlclose(otherPlatform); - } - - return shouldLoad; -} - -#endif // defined(_WIN32) - CL_API_ENTRY cl_int CL_API_CALL clIcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id* platforms, cl_uint* num_platforms) { @@ -268,16 +140,6 @@ CL_API_ENTRY cl_int CL_API_CALL clIcdGetPlatformIDsKHR(cl_uint num_entries, return CL_INVALID_VALUE; } - static bool shouldLoad = true; - - static std::once_flag initOnce; - std::call_once(initOnce, [](){ shouldLoad = ShouldLoadPlatform(); }); - - if (!shouldLoad) { - *not_null(num_platforms) = 0; - return CL_SUCCESS; - } - if (!amd::Runtime::initialized()) { amd::Runtime::init(); } diff --git a/projects/clr/rocclr/utils/flags.cpp b/projects/clr/rocclr/utils/flags.cpp index f19d26a6cf..9ac9421b8f 100644 --- a/projects/clr/rocclr/utils/flags.cpp +++ b/projects/clr/rocclr/utils/flags.cpp @@ -84,12 +84,6 @@ namespace amd { bool IS_HIP = false; -#if !defined(_WIN32) && defined(WITH_PAL_DEVICE) -bool IS_LEGACY = true; -#else -bool IS_LEGACY = false; -#endif - // static char* Flag::envstr_;