Fixing some opencl issues.

This commit is contained in:
clemahieu 2016-04-16 12:51:07 -05:00
commit 9598c879b2
2 changed files with 13 additions and 4 deletions

View file

@ -21,7 +21,7 @@ public:
clCreateBuffer = reinterpret_cast <decltype (clCreateBuffer)> (dlsym(opencl_library, "clCreateBuffer")); clCreateBuffer = reinterpret_cast <decltype (clCreateBuffer)> (dlsym(opencl_library, "clCreateBuffer"));
clCreateProgramWithSource = reinterpret_cast <decltype (clCreateProgramWithSource)> (dlsym(opencl_library, "clCreateProgramWithSource")); clCreateProgramWithSource = reinterpret_cast <decltype (clCreateProgramWithSource)> (dlsym(opencl_library, "clCreateProgramWithSource"));
clBuildProgram = reinterpret_cast <decltype (clBuildProgram)> (dlsym(opencl_library, "clBuildProgram")); clBuildProgram = reinterpret_cast <decltype (clBuildProgram)> (dlsym(opencl_library, "clBuildProgram"));
clGetProgramBuildInfo = reinterpret_cast <decltype (clGetProgramBuildInfo)> (GetProcAddress(opencl_library, "clGetProgramBuildInfo")); clGetProgramBuildInfo = reinterpret_cast <decltype (clGetProgramBuildInfo)> (dlsym(opencl_library, "clGetProgramBuildInfo"));
clCreateKernel = reinterpret_cast <decltype (clCreateKernel)> (dlsym(opencl_library, "clCreateKernel")); clCreateKernel = reinterpret_cast <decltype (clCreateKernel)> (dlsym(opencl_library, "clCreateKernel"));
clSetKernelArg = reinterpret_cast <decltype (clSetKernelArg)> (dlsym(opencl_library, "clSetKernelArg")); clSetKernelArg = reinterpret_cast <decltype (clSetKernelArg)> (dlsym(opencl_library, "clSetKernelArg"));
clReleaseKernel = reinterpret_cast <decltype (clReleaseKernel)> (dlsym(opencl_library, "clReleaseKernel")); clReleaseKernel = reinterpret_cast <decltype (clReleaseKernel)> (dlsym(opencl_library, "clReleaseKernel"));
@ -34,9 +34,12 @@ public:
} }
} }
~opencl_initializer () ~opencl_initializer ()
{
if (opencl_library != nullptr)
{ {
dlclose (opencl_library); dlclose (opencl_library);
} }
}
void * opencl_library; void * opencl_library;
cl_int (* clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); cl_int (* clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *);
cl_int (* clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); cl_int (* clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);
@ -73,8 +76,11 @@ cl_int clGetPlatformIDs (cl_uint num_entries, cl_platform_id * platforms, cl_uin
else else
{ {
result = CL_SUCCESS; result = CL_SUCCESS;
if (num_platforms != nullptr)
{
*num_platforms = 0; *num_platforms = 0;
} }
}
return result; return result;
} }

View file

@ -34,9 +34,12 @@ namespace
} }
} }
~opencl_initializer() ~opencl_initializer()
{
if (opencl_library != nullptr)
{ {
FreeLibrary(opencl_library); FreeLibrary(opencl_library);
} }
}
HMODULE opencl_library; HMODULE opencl_library;
cl_int(*clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); cl_int(*clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *);
cl_int(*clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); cl_int(*clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);