Fix vendors enumeration on 32-bit Windows OS (#28)
authorOfir Cohen <ofircohenn@gmail.com>
Thu, 26 Apr 2018 14:44:05 +0000 (17:44 +0300)
committerKedar Patil <kepatil@nvidia.com>
Thu, 26 Apr 2018 14:44:05 +0000 (20:14 +0530)
When running 32-bit OpenCL applications on a 32-bit OS, we need to
use the registry keys without the "Wow" suffix. On 64-bit OSes and
32-bit applications, OTOH, we must use the Wow suffix.

icd_windows_hkr.c

index 076b60f..1e1f766 100644 (file)
@@ -63,11 +63,30 @@ typedef enum
         mem = NULL;                 \
     } while (0)
 
-#ifdef _WIN64
 static const char OPENCL_REG_SUB_KEY[] = "OpenCLDriverName";
+
+#ifndef _WIN64
+static const char OPENCL_REG_SUB_KEY_WOW[] = "OpenCLDriverNameWow";
+#endif
+
+// Do not free the memory returned by this function.
+static const char* GetOpenCLRegKeyName(void)
+{
+#ifdef _WIN64
+    return OPENCL_REG_SUB_KEY;
 #else
-static const char OPENCL_REG_SUB_KEY[] = "OpenCLDriverNameWow";
+    // The suffix/substring "WoW" is meaningful only when a 32-bit
+    // application is running on a 64-bit Windows OS. A 32-bit application
+    // running on a 32-bit OS uses non-WoW names.
+    BOOL is_wow64;
+    if (IsWow64Process(GetCurrentProcess(), &is_wow64) && is_wow64)
+    {
+        return OPENCL_REG_SUB_KEY_WOW;
+    }
+
+    return OPENCL_REG_SUB_KEY;
 #endif
+}
 
 static bool ReadOpenCLKey(DEVINST dnDevNode)
 {
@@ -96,7 +115,7 @@ static bool ReadOpenCLKey(DEVINST dnDevNode)
     {
         result = RegQueryValueExA(
             hkey,
-            OPENCL_REG_SUB_KEY,
+            GetOpenCLRegKeyName(),
             NULL,
             &dwLibraryNameType,
             NULL,
@@ -168,7 +187,6 @@ static DeviceProbeResult ProbeDevice(DEVINST devnode)
         devnode,
         0);
 
-    // TODO: consider extracting warning messages out of this function
     if (CR_SUCCESS != ret)
     {
         KHR_ICD_TRACE("    WARNING: failed to probe the status of the device 0x%x\n", ret);
@@ -341,8 +359,6 @@ bool khrIcdOsVendorsEnumerateHKR(void)
                     &szGuid,
                     0);
 
-                KHR_ICD_ASSERT(devpropType == DEVPROP_TYPE_GUID);
-
                 if (CR_SUCCESS != ret ||
                     !IsEqualGUID(&OCL_GUID_DEVCLASS_SOFTWARECOMPONENT, &guid))
                 {