Paweł Bylica
10 years ago
15 changed files with 0 additions and 4764 deletions
@ -1,35 +0,0 @@ |
|||||
cmake_minimum_required (VERSION 2.6) |
|
||||
cmake_policy(SET CMP0015 NEW) |
|
||||
set(CMAKE_AUTOMOC OFF) |
|
||||
|
|
||||
aux_source_directory(. SRC_LIST) |
|
||||
|
|
||||
include_directories(BEFORE ..) |
|
||||
|
|
||||
project (OPENCL_ICD_LOADER) |
|
||||
|
|
||||
set (OPENCL_ICD_LOADER_SOURCES icd.c icd_dispatch.c) |
|
||||
|
|
||||
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") |
|
||||
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_linux.c icd_exports.map) |
|
||||
get_filename_component(ICD_EXPORTS_MAP_FILE icd_exports.map ABSOLUTE) |
|
||||
else () |
|
||||
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_windows.c OpenCL.def) |
|
||||
include_directories ($ENV{DXSDK_DIR}/Include) |
|
||||
endif () |
|
||||
|
|
||||
# Change this to point to a directory containing OpenCL header directory "CL" |
|
||||
# OR copy OpenCL headers to ./inc/CL/ |
|
||||
include_directories (./inc) |
|
||||
|
|
||||
add_library (OpenCL_ICD SHARED ${OPENCL_ICD_LOADER_SOURCES}) |
|
||||
set_target_properties (OpenCL_ICD PROPERTIES VERSION "1.2" SOVERSION "1") |
|
||||
|
|
||||
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") |
|
||||
set_target_properties (OpenCL_ICD PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${ICD_EXPORTS_MAP_FILE}") |
|
||||
endif () |
|
||||
|
|
||||
target_link_libraries (OpenCL_ICD ${CMAKE_DL_LIBS}) |
|
||||
target_include_directories(OpenCL_ICD PUBLIC ${OpenCL_INCLUDE_DIR}) |
|
||||
|
|
||||
install(TARGETS OpenCL_ICD RUNTIME DESTINATION bin LIBRARY DESTINATION lib) |
|
@ -1,38 +0,0 @@ |
|||||
Copyright (c) 2012 The Khronos Group Inc. |
|
||||
|
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
of this software source and associated documentation files (the "Materials"), |
|
||||
to use, copy, modify and compile the Materials to create a binary under the |
|
||||
following terms and conditions: |
|
||||
|
|
||||
1. The Materials shall NOT be distributed to any third party; |
|
||||
|
|
||||
2. The binary may be distributed without restriction, including without |
|
||||
limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
do so; |
|
||||
|
|
||||
3. All modifications to the Materials used to create a binary that is |
|
||||
distributed to third parties shall be provided to Khronos with an |
|
||||
unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
enhancements to the Materials; |
|
||||
|
|
||||
4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
binary is distributed together with or separately to that implementation, |
|
||||
then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
conformance process for that implementation, details at: |
|
||||
http://www.khronos.org/conformance/; |
|
||||
|
|
||||
5. The above copyright notice and this permission notice shall be included in |
|
||||
all copies or substantial portions of the Materials. |
|
||||
|
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
THE MATERIALS. |
|
||||
|
|
||||
OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
|
|
@ -1,30 +0,0 @@ |
|||||
.PHONY: default do_cmake do_build test package |
|
||||
.PHONY: clean clobber |
|
||||
|
|
||||
BUILD_DIR:=build |
|
||||
BIN_DIR:=bin |
|
||||
|
|
||||
ICD_VERSION:=$(shell grep FileVersion OpenCL.rc | sed "s/.*\([0-9]\+\.[0-9]\+\.[0-9]\+.[0-9]\+\).*/\1/") |
|
||||
PACKAGE_PATH:=/tmp/opencl-icd-${ICD_VERSION}.tgz |
|
||||
|
|
||||
default: do_build |
|
||||
|
|
||||
do_build: do_cmake |
|
||||
${MAKE} -C ${BUILD_DIR} |
|
||||
|
|
||||
do_cmake: |
|
||||
mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} && cmake .. |
|
||||
|
|
||||
test: |
|
||||
${MAKE} -C ${BUILD_DIR} test |
|
||||
|
|
||||
package: clobber |
|
||||
rm -f ${PACKAGE_PATH} |
|
||||
tar -C .. -czf ${PACKAGE_PATH} --exclude .svn icd |
|
||||
@echo "Package created at ${PACKAGE_PATH}" |
|
||||
|
|
||||
clean: |
|
||||
${MAKE} -C ${BUILD_DIR} clean |
|
||||
|
|
||||
clobber: |
|
||||
rm -rf ${BUILD_DIR} ${BIN_DIR} |
|
@ -1,143 +0,0 @@ |
|||||
; Copyright (c) 2012 The Khronos Group Inc. |
|
||||
; |
|
||||
; Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
; of this software source and associated documentation files (the "Materials"), |
|
||||
; to use, copy, modify and compile the Materials to create a binary under the |
|
||||
; following terms and conditions: |
|
||||
; |
|
||||
; 1. The Materials shall NOT be distributed to any third party; |
|
||||
; |
|
||||
; 2. The binary may be distributed without restriction, including without |
|
||||
; limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
; and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
; do so; |
|
||||
; |
|
||||
; 3. All modifications to the Materials used to create a binary that is |
|
||||
; distributed to third parties shall be provided to Khronos with an |
|
||||
; unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
; enhancements to the Materials; |
|
||||
; |
|
||||
; 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
; binary is distributed together with or separately to that implementation, |
|
||||
; then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
; conformance process for that implementation, details at: |
|
||||
; http://www.khronos.org/conformance/; |
|
||||
; |
|
||||
; 5. The above copyright notice and this permission notice shall be included in |
|
||||
; all copies or substantial portions of the Materials. |
|
||||
; |
|
||||
; THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
; OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
; THE MATERIALS. |
|
||||
; |
|
||||
; OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
|
|
||||
EXPORTS |
|
||||
|
|
||||
; OpenCL 1.0 |
|
||||
clBuildProgram |
|
||||
clCreateBuffer |
|
||||
clCreateCommandQueue |
|
||||
clCreateContext |
|
||||
clCreateContextFromType |
|
||||
clCreateFromGLBuffer |
|
||||
clCreateFromGLRenderbuffer |
|
||||
clCreateFromGLTexture2D |
|
||||
clCreateFromGLTexture3D |
|
||||
clCreateImage2D |
|
||||
clCreateImage3D |
|
||||
clCreateKernel |
|
||||
clCreateKernelsInProgram |
|
||||
clCreateProgramWithBinary |
|
||||
clCreateProgramWithSource |
|
||||
clCreateSampler |
|
||||
clEnqueueAcquireGLObjects |
|
||||
clEnqueueBarrier |
|
||||
clEnqueueCopyBuffer |
|
||||
clEnqueueCopyBufferToImage |
|
||||
clEnqueueCopyImage |
|
||||
clEnqueueCopyImageToBuffer |
|
||||
clEnqueueMapBuffer |
|
||||
clEnqueueMapImage |
|
||||
clEnqueueMarker |
|
||||
clEnqueueNDRangeKernel |
|
||||
clEnqueueNativeKernel |
|
||||
clEnqueueReadBuffer |
|
||||
clEnqueueReadImage |
|
||||
clEnqueueReleaseGLObjects |
|
||||
clEnqueueTask |
|
||||
clEnqueueUnmapMemObject |
|
||||
clEnqueueWaitForEvents |
|
||||
clEnqueueWriteBuffer |
|
||||
clEnqueueWriteImage |
|
||||
clFinish |
|
||||
clFlush |
|
||||
clGetCommandQueueInfo |
|
||||
clGetContextInfo |
|
||||
clGetDeviceIDs |
|
||||
clGetDeviceInfo |
|
||||
clGetEventInfo |
|
||||
clGetEventProfilingInfo |
|
||||
clGetExtensionFunctionAddress |
|
||||
clGetGLObjectInfo |
|
||||
clGetGLTextureInfo |
|
||||
clGetImageInfo |
|
||||
clGetKernelInfo |
|
||||
clGetKernelWorkGroupInfo |
|
||||
clGetMemObjectInfo |
|
||||
clGetPlatformIDs |
|
||||
clGetPlatformInfo |
|
||||
clGetProgramBuildInfo |
|
||||
clGetProgramInfo |
|
||||
clGetSamplerInfo |
|
||||
clGetSupportedImageFormats |
|
||||
clReleaseCommandQueue |
|
||||
clReleaseContext |
|
||||
clReleaseEvent |
|
||||
clReleaseKernel |
|
||||
clReleaseMemObject |
|
||||
clReleaseProgram |
|
||||
clReleaseSampler |
|
||||
clRetainCommandQueue |
|
||||
clRetainContext |
|
||||
clRetainEvent |
|
||||
clRetainKernel |
|
||||
clRetainMemObject |
|
||||
clRetainProgram |
|
||||
clRetainSampler |
|
||||
clSetCommandQueueProperty |
|
||||
clSetKernelArg |
|
||||
clUnloadCompiler |
|
||||
clWaitForEvents |
|
||||
|
|
||||
; OpenCL 1.1 API |
|
||||
clCreateSubBuffer |
|
||||
clCreateUserEvent |
|
||||
clEnqueueCopyBufferRect |
|
||||
clEnqueueReadBufferRect |
|
||||
clEnqueueWriteBufferRect |
|
||||
clSetEventCallback |
|
||||
clSetMemObjectDestructorCallback |
|
||||
clSetUserEventStatus |
|
||||
|
|
||||
; OpenCL 1.2 API |
|
||||
clCompileProgram |
|
||||
clCreateFromGLTexture |
|
||||
clCreateImage |
|
||||
clCreateProgramWithBuiltInKernels |
|
||||
clCreateSubDevices |
|
||||
clEnqueueBarrierWithWaitList |
|
||||
clEnqueueFillBuffer |
|
||||
clEnqueueFillImage |
|
||||
clEnqueueMarkerWithWaitList |
|
||||
clEnqueueMigrateMemObjects |
|
||||
clGetExtensionFunctionAddressForPlatform |
|
||||
clGetKernelArgInfo |
|
||||
clLinkProgram |
|
||||
clReleaseDevice |
|
||||
clRetainDevice |
|
||||
clUnloadPlatformCompiler |
|
@ -1,74 +0,0 @@ |
|||||
/* |
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/; |
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
#include <windows.h> |
|
||||
|
|
||||
#ifdef RC_INVOKED |
|
||||
|
|
||||
VS_VERSION_INFO VERSIONINFO |
|
||||
FILEVERSION 1,2,11,0 |
|
||||
PRODUCTVERSION 1,2,11,0 |
|
||||
FILETYPE VFT_DLL |
|
||||
|
|
||||
BEGIN |
|
||||
BLOCK "StringFileInfo" |
|
||||
BEGIN |
|
||||
BLOCK "040904E4" |
|
||||
BEGIN |
|
||||
VALUE "FileDescription" ,"OpenCL Client DLL" |
|
||||
VALUE "ProductName" ,"Khronos OpenCL ICD" |
|
||||
VALUE "LegalCopyright" ,"Copyright \251 The Khronos Group Inc 2011" |
|
||||
VALUE "FileVersion" ,"1.2.11.0" |
|
||||
|
|
||||
VALUE "CompanyName" ,"Khronos Group" |
|
||||
VALUE "InternalName" ,"OpenCL" |
|
||||
VALUE "OriginalFilename","OpenCL.dll" |
|
||||
END |
|
||||
END |
|
||||
|
|
||||
BLOCK "VarFileInfo" |
|
||||
BEGIN |
|
||||
// extend this line for localized versions |
|
||||
VALUE "Translation", 0x0409, 0x04E4 |
|
||||
END |
|
||||
END |
|
||||
|
|
||||
#endif |
|
||||
|
|
@ -1,50 +0,0 @@ |
|||||
== Building ICD and ICD Test == |
|
||||
|
|
||||
The build system will build ICD Loader library (OpenCL.dll or libOpenCL.so) and |
|
||||
ICD Loader Test binary (icd_loader_test) and some helper libraries for the test. |
|
||||
|
|
||||
=== Linux === |
|
||||
|
|
||||
Run "make" |
|
||||
|
|
||||
=== Windows === |
|
||||
|
|
||||
Run "build_using_cmake.bat" |
|
||||
|
|
||||
== Running ICD Test == |
|
||||
|
|
||||
ICD Test can be run using ctest, which is a companion to cmake. It can also be |
|
||||
run directly by executing icd_loader_test(.exe) executable from the bin folder. |
|
||||
|
|
||||
=== Linux === |
|
||||
|
|
||||
1. Add driver stub as an ICD |
|
||||
echo full/path/to/libOpenCLDriverStub.so > /etc/OpenCL/vendors/test.icd |
|
||||
|
|
||||
2. Run test using ctest |
|
||||
make test |
|
||||
|
|
||||
=== Windows === |
|
||||
|
|
||||
1. Add driver stub as an ICD by adding appropriate registry value |
|
||||
Key for 32-bit apps: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Khronos\OpenCL\Vendors |
|
||||
Key for 64-bit apps: HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors |
|
||||
|
|
||||
Add a REG_DWORD value: |
|
||||
Name: c:/full/path/to/OpenCLDriverStub.dll |
|
||||
Data: 0 |
|
||||
|
|
||||
Note: The build_using_cmake.bat builds ICD test as a 32-bit binary. |
|
||||
|
|
||||
2. Run test using ctest.exe |
|
||||
cd build |
|
||||
ctest.exe |
|
||||
|
|
||||
== Cleanup == |
|
||||
|
|
||||
Manually remove the registry key or .icd files added for running the ICD test. |
|
||||
|
|
||||
The "build" and "bin" folders are autogenerated by the build so those may be |
|
||||
safely deleted without losing any source code (on Linux "make clobber" will |
|
||||
delete them). |
|
||||
|
|
@ -1,11 +0,0 @@ |
|||||
call "%VS90COMNTOOLS%/vsvars32.bat" |
|
||||
|
|
||||
set BUILD_DIR=build |
|
||||
set BIN_DIR=bin |
|
||||
|
|
||||
mkdir %BUILD_DIR% |
|
||||
cd %BUILD_DIR% |
|
||||
cmake -G "NMake Makefiles" ../ |
|
||||
nmake |
|
||||
cd .. |
|
||||
|
|
@ -1,218 +0,0 @@ |
|||||
/*
|
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/;
|
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
#include "icd.h" |
|
||||
#include "icd_dispatch.h" |
|
||||
#include <stdlib.h> |
|
||||
#include <string.h> |
|
||||
|
|
||||
KHRicdState khrIcdState = {0}; |
|
||||
|
|
||||
// entrypoint to initialize the ICD and add all vendors
|
|
||||
void khrIcdInitialize(void) |
|
||||
{ |
|
||||
// make sure we don't double-initialize
|
|
||||
// TODO: this should use an atomic exchange to be thread-safe
|
|
||||
if (khrIcdState.initialized) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
khrIcdState.initialized = CL_TRUE; |
|
||||
|
|
||||
// enumerate vendors present on the system
|
|
||||
khrIcdOsVendorsEnumerate(); |
|
||||
} |
|
||||
|
|
||||
void khrIcdVendorAdd(const char *libraryName) |
|
||||
{ |
|
||||
void *library = NULL; |
|
||||
cl_int result = CL_SUCCESS; |
|
||||
pfn_clGetExtensionFunctionAddress p_clGetExtensionFunctionAddress = NULL; |
|
||||
pfn_clIcdGetPlatformIDs p_clIcdGetPlatformIDs = NULL; |
|
||||
cl_uint i = 0; |
|
||||
cl_uint platformCount = 0; |
|
||||
cl_platform_id *platforms = NULL; |
|
||||
|
|
||||
// require that the library name be valid
|
|
||||
if (!libraryName) |
|
||||
{ |
|
||||
goto Done; |
|
||||
} |
|
||||
KHR_ICD_TRACE("attempting to add vendor %s...\n", libraryName); |
|
||||
|
|
||||
// load its library and query its function pointers
|
|
||||
library = khrIcdOsLibraryLoad(libraryName); |
|
||||
if (!library) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed to load library %s\n", libraryName); |
|
||||
goto Done; |
|
||||
} |
|
||||
|
|
||||
// get the library's clGetExtensionFunctionAddress pointer
|
|
||||
p_clGetExtensionFunctionAddress = khrIcdOsLibraryGetFunctionAddress(library, "clGetExtensionFunctionAddress"); |
|
||||
if (!p_clGetExtensionFunctionAddress) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed to get function address clGetExtensionFunctionAddress\n"); |
|
||||
goto Done; |
|
||||
} |
|
||||
|
|
||||
// use that function to get the clIcdGetPlatformIDsKHR function pointer
|
|
||||
p_clIcdGetPlatformIDs = p_clGetExtensionFunctionAddress("clIcdGetPlatformIDsKHR"); |
|
||||
if (!p_clIcdGetPlatformIDs) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed to get extension function address clIcdGetPlatformIDsKHR\n"); |
|
||||
goto Done; |
|
||||
} |
|
||||
|
|
||||
// query the number of platforms available and allocate space to store them
|
|
||||
result = p_clIcdGetPlatformIDs(0, NULL, &platformCount); |
|
||||
if (CL_SUCCESS != result) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed clIcdGetPlatformIDs\n"); |
|
||||
goto Done; |
|
||||
} |
|
||||
platforms = (cl_platform_id *)malloc(platformCount * sizeof(cl_platform_id) ); |
|
||||
if (!platforms) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed to allocate memory\n"); |
|
||||
goto Done; |
|
||||
} |
|
||||
memset(platforms, 0, platformCount * sizeof(cl_platform_id) ); |
|
||||
result = p_clIcdGetPlatformIDs(platformCount, platforms, NULL); |
|
||||
if (CL_SUCCESS != result) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("failed clIcdGetPlatformIDs\n"); |
|
||||
goto Done; |
|
||||
} |
|
||||
|
|
||||
// for each platform, add it
|
|
||||
for (i = 0; i < platformCount; ++i) |
|
||||
{ |
|
||||
KHRicdVendor* vendor = NULL; |
|
||||
char *suffix; |
|
||||
size_t suffixSize; |
|
||||
|
|
||||
// call clGetPlatformInfo on the returned platform to get the suffix
|
|
||||
if (!platforms[i]) |
|
||||
{ |
|
||||
continue; |
|
||||
} |
|
||||
result = platforms[i]->dispatch->clGetPlatformInfo( |
|
||||
platforms[i], |
|
||||
CL_PLATFORM_ICD_SUFFIX_KHR, |
|
||||
0, |
|
||||
NULL, |
|
||||
&suffixSize); |
|
||||
if (CL_SUCCESS != result) |
|
||||
{ |
|
||||
continue; |
|
||||
} |
|
||||
suffix = (char *)malloc(suffixSize); |
|
||||
if (!suffix) |
|
||||
{ |
|
||||
continue; |
|
||||
} |
|
||||
result = platforms[i]->dispatch->clGetPlatformInfo( |
|
||||
platforms[i], |
|
||||
CL_PLATFORM_ICD_SUFFIX_KHR, |
|
||||
suffixSize, |
|
||||
suffix, |
|
||||
NULL); |
|
||||
if (CL_SUCCESS != result) |
|
||||
{ |
|
||||
free(suffix); |
|
||||
continue; |
|
||||
} |
|
||||
|
|
||||
// allocate a structure for the vendor
|
|
||||
vendor = (KHRicdVendor*)malloc(sizeof(*vendor) ); |
|
||||
if (!vendor) |
|
||||
{ |
|
||||
free(suffix); |
|
||||
KHR_ICD_TRACE("failed to allocate memory\n"); |
|
||||
continue; |
|
||||
} |
|
||||
memset(vendor, 0, sizeof(*vendor) ); |
|
||||
|
|
||||
// populate vendor data
|
|
||||
vendor->library = khrIcdOsLibraryLoad(libraryName); |
|
||||
if (!vendor->library) |
|
||||
{ |
|
||||
free(suffix); |
|
||||
free(vendor); |
|
||||
KHR_ICD_TRACE("failed get platform handle to library\n"); |
|
||||
continue; |
|
||||
} |
|
||||
vendor->clGetExtensionFunctionAddress = p_clGetExtensionFunctionAddress; |
|
||||
vendor->platform = platforms[i]; |
|
||||
vendor->suffix = suffix; |
|
||||
|
|
||||
// add this vendor to the list of vendors at the tail
|
|
||||
{ |
|
||||
KHRicdVendor **prevNextPointer = NULL; |
|
||||
for (prevNextPointer = &khrIcdState.vendors; *prevNextPointer; prevNextPointer = &( (*prevNextPointer)->next) ); |
|
||||
*prevNextPointer = vendor; |
|
||||
} |
|
||||
|
|
||||
KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
Done: |
|
||||
|
|
||||
if (library) |
|
||||
{ |
|
||||
khrIcdOsLibraryUnload(library); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void khrIcdContextPropertiesGetPlatform(const cl_context_properties *properties, cl_platform_id *outPlatform) |
|
||||
{ |
|
||||
const cl_context_properties *property = (cl_context_properties *)NULL; |
|
||||
*outPlatform = NULL; |
|
||||
for (property = properties; property && property[0]; property += 2) |
|
||||
{ |
|
||||
if ((cl_context_properties)CL_CONTEXT_PLATFORM == property[0]) |
|
||||
{ |
|
||||
*outPlatform = (cl_platform_id)property[1]; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
@ -1,199 +0,0 @@ |
|||||
/*
|
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/;
|
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
#ifndef _ICD_H_ |
|
||||
#define _ICD_H_ |
|
||||
|
|
||||
#include <CL/cl.h> |
|
||||
#include <CL/cl_ext.h> |
|
||||
|
|
||||
/*
|
|
||||
* type definitions |
|
||||
*/ |
|
||||
|
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clIcdGetPlatformIDs)( |
|
||||
cl_uint num_entries, |
|
||||
cl_platform_id *platforms, |
|
||||
cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0; |
|
||||
|
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clGetPlatformInfo)( |
|
||||
cl_platform_id platform, |
|
||||
cl_platform_info param_name, |
|
||||
size_t param_value_size, |
|
||||
void * param_value, |
|
||||
size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; |
|
||||
|
|
||||
typedef CL_API_ENTRY void *(CL_API_CALL *pfn_clGetExtensionFunctionAddress)( |
|
||||
const char *function_name) CL_API_SUFFIX__VERSION_1_0; |
|
||||
|
|
||||
typedef struct KHRicdVendorRec KHRicdVendor; |
|
||||
typedef struct KHRicdStateRec KHRicdState; |
|
||||
|
|
||||
/*
|
|
||||
* KHRicdVendor |
|
||||
* |
|
||||
* Data for a single ICD vendor platform. |
|
||||
*/ |
|
||||
struct KHRicdVendorRec |
|
||||
{ |
|
||||
// the loaded library object (true type varies on Linux versus Windows)
|
|
||||
void *library; |
|
||||
|
|
||||
// the extension suffix for this platform
|
|
||||
char *suffix; |
|
||||
|
|
||||
// function pointer to the ICD platform IDs extracted from the library
|
|
||||
pfn_clGetExtensionFunctionAddress clGetExtensionFunctionAddress; |
|
||||
|
|
||||
// the platform retrieved from clGetIcdPlatformIDsKHR
|
|
||||
cl_platform_id platform; |
|
||||
|
|
||||
// next vendor in the list vendors
|
|
||||
KHRicdVendor *next; |
|
||||
}; |
|
||||
|
|
||||
|
|
||||
/*
|
|
||||
* KHRicdState |
|
||||
* |
|
||||
* The global state of all vendors |
|
||||
* |
|
||||
* TODO: write access to this structure needs to be protected via a mutex |
|
||||
*/ |
|
||||
|
|
||||
struct KHRicdStateRec |
|
||||
{ |
|
||||
// has this structure been initialized
|
|
||||
cl_bool initialized; |
|
||||
|
|
||||
// the list of vendors which have been loaded
|
|
||||
KHRicdVendor *vendors; |
|
||||
}; |
|
||||
|
|
||||
// the global state
|
|
||||
extern KHRicdState khrIcdState; |
|
||||
|
|
||||
/*
|
|
||||
* khrIcd interface |
|
||||
*/ |
|
||||
|
|
||||
// read vendors from system configuration and store the data
|
|
||||
// loaded into khrIcdState. this will call the OS-specific
|
|
||||
// function khrIcdEnumerateVendors. this is called at every
|
|
||||
// dispatch function which may be a valid first call into the
|
|
||||
// API (e.g, getPlatformIDs, etc).
|
|
||||
void khrIcdInitialize(void); |
|
||||
|
|
||||
// go through the list of vendors (in /etc/OpenCL.conf or through
|
|
||||
// the registry) and call khrIcdVendorAdd for each vendor encountered
|
|
||||
// n.b, this call is OS-specific
|
|
||||
void khrIcdOsVendorsEnumerate(void); |
|
||||
|
|
||||
// add a vendor's implementation to the list of libraries
|
|
||||
void khrIcdVendorAdd(const char *libraryName); |
|
||||
|
|
||||
// dynamically load a library. returns NULL on failure
|
|
||||
// n.b, this call is OS-specific
|
|
||||
void *khrIcdOsLibraryLoad(const char *libraryName); |
|
||||
|
|
||||
// get a function pointer from a loaded library. returns NULL on failure.
|
|
||||
// n.b, this call is OS-specific
|
|
||||
void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName); |
|
||||
|
|
||||
// unload a library.
|
|
||||
// n.b, this call is OS-specific
|
|
||||
void khrIcdOsLibraryUnload(void *library); |
|
||||
|
|
||||
// parse properties and determine the platform to use from them
|
|
||||
void khrIcdContextPropertiesGetPlatform( |
|
||||
const cl_context_properties *properties, |
|
||||
cl_platform_id *outPlatform); |
|
||||
|
|
||||
// internal tracing macros
|
|
||||
#if 0 |
|
||||
#include <stdio.h> |
|
||||
#define KHR_ICD_TRACE(...) \ |
|
||||
do \ |
|
||||
{ \ |
|
||||
fprintf(stderr, "KHR ICD trace at %s:%d: ", __FILE__, __LINE__); \ |
|
||||
fprintf(stderr, __VA_ARGS__); \ |
|
||||
} while (0) |
|
||||
|
|
||||
#define KHR_ICD_ASSERT(x) \ |
|
||||
do \ |
|
||||
{ \ |
|
||||
if (!(x)) \ |
|
||||
{ \ |
|
||||
fprintf(stderr, "KHR ICD assert at %s:%d: %s failed", __FILE__, __LINE__, #x); \ |
|
||||
} \ |
|
||||
} while (0) |
|
||||
#else |
|
||||
#define KHR_ICD_TRACE(...) |
|
||||
#define KHR_ICD_ASSERT(x) |
|
||||
#endif |
|
||||
|
|
||||
// if handle is NULL then return invalid_handle_error_code
|
|
||||
#define KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(handle,invalid_handle_error_code) \ |
|
||||
do \ |
|
||||
{ \ |
|
||||
if (!handle) \ |
|
||||
{ \ |
|
||||
return invalid_handle_error_code; \ |
|
||||
} \ |
|
||||
} while (0) |
|
||||
|
|
||||
// if handle is NULL then set errcode_ret to invalid_handle_error and return NULL
|
|
||||
// (NULL being an invalid handle)
|
|
||||
#define KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(handle,invalid_handle_error) \ |
|
||||
do \ |
|
||||
{ \ |
|
||||
if (!handle) \ |
|
||||
{ \ |
|
||||
if (errcode_ret) \ |
|
||||
{ \ |
|
||||
*errcode_ret = invalid_handle_error; \ |
|
||||
} \ |
|
||||
return NULL; \ |
|
||||
} \ |
|
||||
} while (0) |
|
||||
|
|
||||
|
|
||||
#endif |
|
||||
|
|
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,153 +0,0 @@ |
|||||
/* |
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/; |
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
OPENCL_1.0 { |
|
||||
global: |
|
||||
clBuildProgram; |
|
||||
clCreateBuffer; |
|
||||
clCreateCommandQueue; |
|
||||
clCreateContext; |
|
||||
clCreateContextFromType; |
|
||||
clCreateFromGLBuffer; |
|
||||
clCreateFromGLRenderbuffer; |
|
||||
clCreateFromGLTexture2D; |
|
||||
clCreateFromGLTexture3D; |
|
||||
clCreateImage2D; |
|
||||
clCreateImage3D; |
|
||||
clCreateKernel; |
|
||||
clCreateKernelsInProgram; |
|
||||
clCreateProgramWithBinary; |
|
||||
clCreateProgramWithSource; |
|
||||
clCreateSampler; |
|
||||
clEnqueueAcquireGLObjects; |
|
||||
clEnqueueBarrier; |
|
||||
clEnqueueCopyBuffer; |
|
||||
clEnqueueCopyBufferToImage; |
|
||||
clEnqueueCopyImage; |
|
||||
clEnqueueCopyImageToBuffer; |
|
||||
clEnqueueMapBuffer; |
|
||||
clEnqueueMapImage; |
|
||||
clEnqueueMarker; |
|
||||
clEnqueueNDRangeKernel; |
|
||||
clEnqueueNativeKernel; |
|
||||
clEnqueueReadBuffer; |
|
||||
clEnqueueReadImage; |
|
||||
clEnqueueReleaseGLObjects; |
|
||||
clEnqueueTask; |
|
||||
clEnqueueUnmapMemObject; |
|
||||
clEnqueueWaitForEvents; |
|
||||
clEnqueueWriteBuffer; |
|
||||
clEnqueueWriteImage; |
|
||||
clFinish; |
|
||||
clFlush; |
|
||||
clGetCommandQueueInfo; |
|
||||
clGetContextInfo; |
|
||||
clGetDeviceIDs; |
|
||||
clGetDeviceInfo; |
|
||||
clGetEventInfo; |
|
||||
clGetEventProfilingInfo; |
|
||||
clGetExtensionFunctionAddress; |
|
||||
clGetGLObjectInfo; |
|
||||
clGetGLTextureInfo; |
|
||||
clGetImageInfo; |
|
||||
clGetKernelInfo; |
|
||||
clGetKernelWorkGroupInfo; |
|
||||
clGetMemObjectInfo; |
|
||||
clGetPlatformIDs; |
|
||||
clGetPlatformInfo; |
|
||||
clGetProgramBuildInfo; |
|
||||
clGetProgramInfo; |
|
||||
clGetSamplerInfo; |
|
||||
clGetSupportedImageFormats; |
|
||||
clReleaseCommandQueue; |
|
||||
clReleaseContext; |
|
||||
clReleaseEvent; |
|
||||
clReleaseKernel; |
|
||||
clReleaseMemObject; |
|
||||
clReleaseProgram; |
|
||||
clReleaseSampler; |
|
||||
clRetainCommandQueue; |
|
||||
clRetainContext; |
|
||||
clRetainEvent; |
|
||||
clRetainKernel; |
|
||||
clRetainMemObject; |
|
||||
clRetainProgram; |
|
||||
clRetainSampler; |
|
||||
clSetCommandQueueProperty; |
|
||||
clSetKernelArg; |
|
||||
clUnloadCompiler; |
|
||||
clWaitForEvents; |
|
||||
|
|
||||
local: |
|
||||
/* Everything else is local to ICD. */ |
|
||||
*; |
|
||||
}; |
|
||||
|
|
||||
OPENCL_1.1 { |
|
||||
global: |
|
||||
clCreateSubBuffer; |
|
||||
clCreateUserEvent; |
|
||||
clEnqueueCopyBufferRect; |
|
||||
clEnqueueReadBufferRect; |
|
||||
clEnqueueWriteBufferRect; |
|
||||
clSetEventCallback; |
|
||||
clSetMemObjectDestructorCallback; |
|
||||
clSetUserEventStatus; |
|
||||
} OPENCL_1.0; |
|
||||
|
|
||||
OPENCL_1.2 { |
|
||||
global: |
|
||||
clCompileProgram; |
|
||||
clCreateFromGLTexture; |
|
||||
clCreateImage; |
|
||||
clCreateProgramWithBuiltInKernels; |
|
||||
clCreateSubDevices; |
|
||||
clEnqueueBarrierWithWaitList; |
|
||||
clEnqueueFillBuffer; |
|
||||
clEnqueueFillImage; |
|
||||
clEnqueueMarkerWithWaitList; |
|
||||
clEnqueueMigrateMemObjects; |
|
||||
clGetExtensionFunctionAddressForPlatform; |
|
||||
clGetKernelArgInfo; |
|
||||
clLinkProgram; |
|
||||
clReleaseDevice; |
|
||||
clRetainDevice; |
|
||||
clUnloadPlatformCompiler; |
|
||||
} OPENCL_1.1; |
|
@ -1,178 +0,0 @@ |
|||||
/*
|
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/;
|
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
#include "icd.h" |
|
||||
#include <dlfcn.h> |
|
||||
#include <stdio.h> |
|
||||
#include <string.h> |
|
||||
#include <stdlib.h> |
|
||||
#include <sys/types.h> |
|
||||
#include <dirent.h> |
|
||||
|
|
||||
/*
|
|
||||
* |
|
||||
* Vendor enumeration functions |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
// go through the list of vendors in the two configuration files
|
|
||||
void khrIcdOsVendorsEnumerate(void) |
|
||||
{ |
|
||||
DIR *dir = NULL; |
|
||||
struct dirent *dirEntry = NULL; |
|
||||
char *vendorPath = "/etc/OpenCL/vendors/"; |
|
||||
|
|
||||
// open the directory
|
|
||||
dir = opendir(vendorPath); |
|
||||
if (NULL == dir) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Failed to open path %s\n", vendorPath); |
|
||||
goto Cleanup; |
|
||||
} |
|
||||
|
|
||||
// attempt to load all files in the directory
|
|
||||
for (dirEntry = readdir(dir); dirEntry; dirEntry = readdir(dir) ) |
|
||||
{ |
|
||||
switch(dirEntry->d_type) |
|
||||
{ |
|
||||
case DT_UNKNOWN: |
|
||||
case DT_REG: |
|
||||
case DT_LNK: |
|
||||
{ |
|
||||
const char* extension = ".icd"; |
|
||||
FILE *fin = NULL; |
|
||||
char* fileName = NULL; |
|
||||
char* buffer = NULL; |
|
||||
long bufferSize = 0; |
|
||||
|
|
||||
// make sure the file name ends in .icd
|
|
||||
if (strlen(extension) > strlen(dirEntry->d_name) ) |
|
||||
{ |
|
||||
break; |
|
||||
} |
|
||||
if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) ) |
|
||||
{ |
|
||||
break; |
|
||||
} |
|
||||
|
|
||||
// allocate space for the full path of the vendor library name
|
|
||||
fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 1); |
|
||||
if (!fileName) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Failed allocate space for ICD file path\n"); |
|
||||
break; |
|
||||
} |
|
||||
sprintf(fileName, "%s%s", vendorPath, dirEntry->d_name); |
|
||||
|
|
||||
// open the file and read its contents
|
|
||||
fin = fopen(fileName, "r"); |
|
||||
if (!fin) |
|
||||
{ |
|
||||
free(fileName); |
|
||||
break; |
|
||||
} |
|
||||
fseek(fin, 0, SEEK_END); |
|
||||
bufferSize = ftell(fin); |
|
||||
|
|
||||
buffer = malloc(bufferSize+1); |
|
||||
if (!buffer) |
|
||||
{ |
|
||||
free(fileName); |
|
||||
fclose(fin); |
|
||||
break; |
|
||||
} |
|
||||
memset(buffer, 0, bufferSize+1); |
|
||||
fseek(fin, 0, SEEK_SET); |
|
||||
if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) ) |
|
||||
{ |
|
||||
free(fileName); |
|
||||
free(buffer); |
|
||||
fclose(fin); |
|
||||
break; |
|
||||
} |
|
||||
// ignore a newline at the end of the file
|
|
||||
if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0'; |
|
||||
|
|
||||
// load the string read from the file
|
|
||||
khrIcdVendorAdd(buffer); |
|
||||
|
|
||||
free(fileName); |
|
||||
free(buffer); |
|
||||
fclose(fin); |
|
||||
} |
|
||||
break; |
|
||||
default: |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Cleanup: |
|
||||
|
|
||||
// free resources and exit
|
|
||||
if (dir) |
|
||||
{ |
|
||||
closedir(dir); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/*
|
|
||||
* |
|
||||
* Dynamic library loading functions |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
// dynamically load a library. returns NULL on failure
|
|
||||
void *khrIcdOsLibraryLoad(const char *libraryName) |
|
||||
{ |
|
||||
return dlopen (libraryName, RTLD_NOW); |
|
||||
} |
|
||||
|
|
||||
// get a function pointer from a loaded library. returns NULL on failure.
|
|
||||
void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName) |
|
||||
{ |
|
||||
return dlsym(library, functionName); |
|
||||
} |
|
||||
|
|
||||
// unload a library
|
|
||||
void khrIcdOsLibraryUnload(void *library) |
|
||||
{ |
|
||||
dlclose(library); |
|
||||
} |
|
||||
|
|
@ -1,152 +0,0 @@ |
|||||
/*
|
|
||||
* Copyright (c) 2012 The Khronos Group Inc. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software source and associated documentation files (the "Materials"), |
|
||||
* to use, copy, modify and compile the Materials to create a binary under the |
|
||||
* following terms and conditions: |
|
||||
* |
|
||||
* 1. The Materials shall NOT be distributed to any third party; |
|
||||
* |
|
||||
* 2. The binary may be distributed without restriction, including without |
|
||||
* limitation the rights to use, copy, merge, publish, distribute, sublicense, |
|
||||
* and/or sell copies, and to permit persons to whom the binary is furnished to |
|
||||
* do so; |
|
||||
* |
|
||||
* 3. All modifications to the Materials used to create a binary that is |
|
||||
* distributed to third parties shall be provided to Khronos with an |
|
||||
* unrestricted license to use for the purposes of implementing bug fixes and |
|
||||
* enhancements to the Materials; |
|
||||
* |
|
||||
* 4. If the binary is used as part of an OpenCL(TM) implementation, whether |
|
||||
* binary is distributed together with or separately to that implementation, |
|
||||
* then recipient must become an OpenCL Adopter and follow the published OpenCL |
|
||||
* conformance process for that implementation, details at: |
|
||||
* http://www.khronos.org/conformance/;
|
|
||||
* |
|
||||
* 5. The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Materials. |
|
||||
* |
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE MATERIALS. |
|
||||
* |
|
||||
* OpenCL is a trademark of Apple Inc. used under license by Khronos. |
|
||||
*/ |
|
||||
|
|
||||
#include "icd.h" |
|
||||
#include <stdio.h> |
|
||||
#include <windows.h> |
|
||||
#include <winreg.h> |
|
||||
|
|
||||
/*
|
|
||||
* |
|
||||
* Vendor enumeration functions |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
// go through the list of vendors in the registry and call khrIcdVendorAdd
|
|
||||
// for each vendor encountered
|
|
||||
void khrIcdOsVendorsEnumerate() |
|
||||
{ |
|
||||
LONG result; |
|
||||
const char* platformsName = "SOFTWARE\\Khronos\\OpenCL\\Vendors"; |
|
||||
HKEY platformsKey = NULL; |
|
||||
DWORD dwIndex; |
|
||||
|
|
||||
KHR_ICD_TRACE("Opening key HKLM\\%s...\n", platformsName); |
|
||||
result = RegOpenKeyExA( |
|
||||
HKEY_LOCAL_MACHINE, |
|
||||
platformsName, |
|
||||
0, |
|
||||
KEY_READ, |
|
||||
&platformsKey); |
|
||||
if (ERROR_SUCCESS != result) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Failed to open platforms key %s, continuing\n", platformsName); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
// for each value
|
|
||||
for (dwIndex = 0;; ++dwIndex) |
|
||||
{ |
|
||||
char cszLibraryName[1024] = {0}; |
|
||||
DWORD dwLibraryNameSize = sizeof(cszLibraryName); |
|
||||
DWORD dwLibraryNameType = 0; |
|
||||
DWORD dwValue = 0; |
|
||||
DWORD dwValueSize = sizeof(dwValue); |
|
||||
|
|
||||
// read the value name
|
|
||||
KHR_ICD_TRACE("Reading value %d...\n", dwIndex); |
|
||||
result = RegEnumValueA( |
|
||||
platformsKey, |
|
||||
dwIndex, |
|
||||
cszLibraryName, |
|
||||
&dwLibraryNameSize, |
|
||||
NULL, |
|
||||
&dwLibraryNameType, |
|
||||
(LPBYTE)&dwValue, |
|
||||
&dwValueSize); |
|
||||
// if RegEnumKeyEx fails, we are done with the enumeration
|
|
||||
if (ERROR_SUCCESS != result) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Failed to read value %d, done reading key.\n", dwIndex); |
|
||||
break; |
|
||||
} |
|
||||
KHR_ICD_TRACE("Value %s found...\n", cszLibraryName); |
|
||||
|
|
||||
// Require that the value be a DWORD and equal zero
|
|
||||
if (REG_DWORD != dwLibraryNameType) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Value not a DWORD, skipping\n"); |
|
||||
continue; |
|
||||
} |
|
||||
if (dwValue) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Value not zero, skipping\n"); |
|
||||
continue; |
|
||||
} |
|
||||
|
|
||||
// add the library
|
|
||||
khrIcdVendorAdd(cszLibraryName); |
|
||||
} |
|
||||
|
|
||||
result = RegCloseKey(platformsKey); |
|
||||
if (ERROR_SUCCESS != result) |
|
||||
{ |
|
||||
KHR_ICD_TRACE("Failed to close platforms key %s, ignoring\n", platformsName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/*
|
|
||||
* |
|
||||
* Dynamic library loading functions |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
// dynamically load a library. returns NULL on failure
|
|
||||
void *khrIcdOsLibraryLoad(const char *libraryName) |
|
||||
{ |
|
||||
return (void *)LoadLibraryA(libraryName); |
|
||||
} |
|
||||
|
|
||||
// get a function pointer from a loaded library. returns NULL on failure.
|
|
||||
void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName) |
|
||||
{ |
|
||||
if (!library || !functionName) |
|
||||
{ |
|
||||
return NULL; |
|
||||
} |
|
||||
return GetProcAddress( (HMODULE)library, functionName); |
|
||||
} |
|
||||
|
|
||||
// unload a library.
|
|
||||
void khrIcdOsLibraryUnload(void *library) |
|
||||
{ |
|
||||
FreeLibrary( (HMODULE)library); |
|
||||
} |
|
||||
|
|
@ -1,14 +0,0 @@ |
|||||
Copy OpenCL headers here, inside a directory named "CL", so that the inc folder |
|
||||
looks like this: |
|
||||
|
|
||||
inc/CL/cl_d3d10.h |
|
||||
inc/CL/cl_d3d11.h |
|
||||
inc/CL/cl_dx9_media_sharing.h |
|
||||
inc/CL/cl_ext.h |
|
||||
inc/CL/cl_gl_ext.h |
|
||||
inc/CL/cl_gl.h |
|
||||
inc/CL/cl.h |
|
||||
inc/CL/cl.hpp |
|
||||
inc/CL/cl_platform.h |
|
||||
inc/CL/opencl.h |
|
||||
|
|
Loading…
Reference in new issue