Skip to content

Commit

Permalink
Fix vendors enumeration on 32-bit Windows OS (#28)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ofirc authored and kepatil committed Apr 26, 2018
1 parent 35a592d commit b342ff7
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions icd_windows_hkr.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -96,7 +115,7 @@ static bool ReadOpenCLKey(DEVINST dnDevNode)
{
result = RegQueryValueExA(
hkey,
OPENCL_REG_SUB_KEY,
GetOpenCLRegKeyName(),
NULL,
&dwLibraryNameType,
NULL,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down

0 comments on commit b342ff7

Please sign in to comment.