Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ project (OPENCL_ICD_LOADER)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

set (OPENCL_ICD_LOADER_SOURCES icd.c icd_dispatch.c)
set (OPENCL_ICD_LOADER_SOURCES icd.c icd_dispatch.c icd_envvar.c)

if (WIN32)
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_windows.c icd_windows_hkr.c OpenCL.def OpenCL.rc)
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_windows.c icd_windows_hkr.c icd_windows_envvar.c OpenCL.def OpenCL.rc)
include_directories ($ENV{DXSDK_DIR}/Include)
else ()
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_linux.c icd_exports.map)
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_linux.c icd_linux_envvar.c icd_exports.map)
endif ()

# Change this to point to a directory containing OpenCL header directory "CL"
Expand Down
7 changes: 7 additions & 0 deletions icd.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ KHRicdVendor *khrIcdVendors = NULL;
// entrypoint to initialize the ICD and add all vendors
void khrIcdInitialize(void)
{
khrIcdOsGetOpenCLVisibleDevicesOnce();
// enumerate vendors present on the system
khrIcdOsVendorsEnumerateOnce();
}
Expand Down Expand Up @@ -134,6 +135,10 @@ void khrIcdVendorAdd(const char *libraryName)
{
continue;
}
if (!khrIcdCheckPlatformVisible(libraryName, i))
{
continue;
}
result = platforms[i]->dispatch->clGetPlatformInfo(
platforms[i],
CL_PLATFORM_ICD_SUFFIX_KHR,
Expand Down Expand Up @@ -191,6 +196,8 @@ void khrIcdVendorAdd(const char *libraryName)
*prevNextPointer = vendor;
}

khrIcdVisibilitySetPlatform(libraryName, i, platforms[i]);

KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix);

}
Expand Down
128 changes: 121 additions & 7 deletions icd_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "icd_dispatch.h"
#include "icd.h"
#include "icd_envvar.h"
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -116,15 +117,83 @@ clGetDeviceIDs(cl_platform_id platform,
cl_device_id * devices,
cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0
{
cl_uint num_all_devices = 0;
cl_device_id *all_devices = NULL;
cl_uint i;
cl_int result;

// initialize the platforms (in case they have not been already)
khrIcdInitialize();
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM);
return platform->dispatch->clGetDeviceIDs(

if (!num_entries && devices)
{
return CL_INVALID_VALUE;
}
if (!devices && !num_devices)
{
return CL_INVALID_VALUE;
}

if (num_devices)
{
*num_devices = 0;
}
for (i = 0; i < num_entries && devices; ++i)
{
devices[i] = NULL;
}

result = platform->dispatch->clGetDeviceIDs(
platform,
device_type,
num_entries,
devices,
num_devices);
device_type,
0,
NULL,
&num_all_devices);
if (CL_SUCCESS != result)
{
return result;
}
if (!num_all_devices)
{
return CL_DEVICE_NOT_FOUND;
}
all_devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_all_devices);
if (!all_devices)
{
return CL_OUT_OF_HOST_MEMORY;
}
result = platform->dispatch->clGetDeviceIDs(
platform,
device_type,
num_all_devices,
all_devices,
NULL);
if (CL_SUCCESS != result)
{
free(all_devices);
return result;
}

result = CL_DEVICE_NOT_FOUND;
for (i = 0; i < num_all_devices; ++i)
{
if (khrIcdCheckDeviceVisible(platform, all_devices[i]))
{
result = CL_SUCCESS;
if (num_entries && devices)
{
*(devices++) = all_devices[i];
--num_entries;
}
if (num_devices)
{
++(*num_devices);
}
}
}
free(all_devices);
return result;
}

CL_API_ENTRY cl_int CL_API_CALL
Expand Down Expand Up @@ -211,6 +280,10 @@ clCreateContextFromType(const cl_context_properties * properties,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_platform_id platform = NULL;
cl_uint num_devices = 0;
cl_device_id *devices = NULL;
cl_context context = NULL;
cl_int result;

// initialize the platforms (in case they have not been already)
khrIcdInitialize();
Expand All @@ -220,12 +293,53 @@ clCreateContextFromType(const cl_context_properties * properties,

// validate the platform handle and dispatch
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(platform, CL_INVALID_PLATFORM);
return platform->dispatch->clCreateContextFromType(

result = clGetDeviceIDs(platform, device_type, 0, NULL, &num_devices);
if (CL_SUCCESS != result)
{
if (*errcode_ret)
{
*errcode_ret = result;
}
return NULL;
}
if (!num_devices)
{
if (*errcode_ret)
{
*errcode_ret = CL_DEVICE_NOT_FOUND;
}
return NULL;
}
devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_devices);
if (!devices)
{
if (*errcode_ret)
{
*errcode_ret = CL_OUT_OF_HOST_MEMORY;
}
return NULL;
}
result = clGetDeviceIDs(platform, device_type, num_devices, devices, NULL);
if (CL_SUCCESS != result)
{
free(devices);
if (*errcode_ret)
{
*errcode_ret = result;
}
return NULL;
}

context = platform->dispatch->clCreateContext(
properties,
device_type,
num_devices,
devices,
pfn_notify,
user_data,
errcode_ret);
free(devices);
return context;
}

CL_API_ENTRY cl_int CL_API_CALL
Expand Down
Loading