Dynamically binding to posix opencl library.

This commit is contained in:
clemahieu 2016-04-05 21:46:19 -05:00
commit d3cd6d2908
3 changed files with 51 additions and 0 deletions

View file

@ -101,12 +101,15 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set (PLATFORM_WALLET_SOURCE rai/plat/default/icon.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set (PLATFORM_SECURE_SOURCE rai/plat/windows/working.cpp rai/plat/windows/priority.cpp)
set (PLATFORM_NODE_SOURCE rai/plat/windows/openclapi.cpp)
set (PLATFORM_WALLET_SOURCE rai/plat/windows/icon.cpp RaiBlocks.rc)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set (PLATFORM_SECURE_SOURCE rai/plat/posix/working.cpp rai/plat/linux/priority.cpp)
set (PLATFORM_NODE_SOURCE rai/plat/posix/openclapi.cpp)
set (PLATFORM_WALLET_SOURCE rai/plat/default/icon.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set (PLATFORM_SECURE_SOURCE rai/plat/posix/working.cpp rai/plat/default/priority.cpp)
set (PLATFORM_NODE_SOURCE rai/plat/posix/openclapi.cpp)
set (PLATFORM_WALLET_SOURCE rai/plat/default/icon.cpp)
else ()
error ("Unknown platform: ${CMAKE_SYSTEM_NAME}")
@ -123,6 +126,7 @@ add_library (secure
rai/versioning.cpp)
add_library (node
${PLATFORM_NODE_SOURCE}
rai/node/bootstrap.cpp
rai/node/bootstrap.hpp
rai/node/common.cpp

View file

@ -0,0 +1,47 @@
#include <rai/node/openclwork.hpp>
#include <dlfcn.h>
namespace
{
class opencl_initializer
{
public:
opencl_initializer ()
{
opencl_library = dlopen ("libOpenCL.so", RTLD_NOW);
if (opencl_library != nullptr)
{
clGetPlatformIDs = reinterpret_cast <decltype (clGetPlatformIDs)> (dlsym (opencl_library, "clGetPlatformIDs"));
}
}
~opencl_initializer ()
{
dlclose (opencl_library);
}
void * opencl_library;
cl_int (* clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *);
cl_int (* clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
static opencl_initializer initializer;
};
}
cl_int clGetPlatformIDs (cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms)
{
cl_int result;
if (opencl_initializer::initializer.opencl_library != nullptr)
{
result = opencl_initializer::initializer.clGetPlatformIDs (num_entries, platforms, num_platforms);
}
else
{
result = CL_SUCCESS;
*num_platforms = 0;
}
return result;
}
cl_int clGetDeviceIDs (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id * devices, cl_uint * num_devices)
{
return clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices);
}

View file