Hi,
I’m on kUbuntu 11.10 64bit, I downloaded & installed the latest catalyst and app sdk. I tried to reproduce the functionality of the SimpleGL sample app that came with the sdk. However when I try to query the number of CL-GL interop capable devices, my app crashes with sigsegv. In the frame stack the last call from my app is line 71, clGetGLContextInfoKHR (see code), and there’s one more from OpenCL.so. I could run SimpleGL, so I assume I’m doing something wrong… I use SFML for windowing which creates a glX context. I can get the context and everything seems to work until I query for the CL-GL devices.
so here’s the code:
compute_context.h
#ifndef compute_context_h
#define compute_context_h
#include "common.h"
#include "assert.h"
struct compute_platform_description
{
cl_platform_info info;
std::string desc;
};
struct compute_device_description
{
cl_device_info info;
std::string desc;
};
typedef CL_API_ENTRY cl_int
(CL_API_CALL *clGetGLContextInfoKHR_fn)(const cl_context_properties *properties,
cl_gl_context_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret);
#define clGetGLContextInfoKHR clGetGLContextInfoKHR_proc
static clGetGLContextInfoKHR_fn clGetGLContextInfoKHR;
class compute_context
{
private:
cl_int error;
protected:
public:
void init();
cl_platform_id the_platform;
cl_device_id the_device;
cl_context the_context;
cl_command_queue the_command_queue;
compute_context() {};
};
#endif
compute_context.cpp
#include "compute_context.h"
#include "objs.h"
void compute_context::init()
{
std::cout << "
Initializing OpenCL...
";
GLXContext the_glx_context = glXGetCurrentContext();
if (the_glx_context == 0)
{
std::cerr << "Error getting the current glX context.
";
objs::get()->conf.the_window.Close();
exit(1);
}
cl_int error = CL_SUCCESS;
cl_context_properties the_context_properties[] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)the_platform,
CL_GLX_DISPLAY_KHR,
(intptr_t)glXGetCurrentDisplay(),
CL_GL_CONTEXT_KHR,
(intptr_t)the_glx_context,
0
};
if (!clGetGLContextInfoKHR)
{
clGetGLContextInfoKHR = (clGetGLContextInfoKHR_fn)clGetExtensionFunctionAddress("clGetGLContextInfoKHR");
if (!clGetGLContextInfoKHR)
{
std::cerr << "Error getting clGetGLContextInfoKHR function ptr.
";
objs::get()->conf.the_window.Close();
exit(1);
}
}
cl_uint num_platfroms;
error = clGetPlatformIDs(1, &the_platform, &num_platfroms);
assert(error == CL_SUCCESS);
std::cout << "Number of platforms: " << num_platfroms << "
";
std::vector< compute_platform_description > compute_platform_info;
compute_platform_info.resize(4);
compute_platform_info[0] = {CL_PLATFORM_PROFILE, "Platform info: "};
compute_platform_info[1] = {CL_PLATFORM_VERSION, "Platform version: "};
compute_platform_info[2] = {CL_PLATFORM_NAME, "Platform name: "};
compute_platform_info[3] = {CL_PLATFORM_VENDOR, "Platform vendor: "};
//compute_platform_info[4] = {CL_PLATFORM_EXTENSIONS, "Platform extensions: "};
for (int c = 0; c < compute_platform_info.size(); c++)
{
char buffer[1024];
error = clGetPlatformInfo(the_platform, compute_platform_info[c].info, sizeof(buffer), &buffer, 0);
assert(error == CL_SUCCESS);
std::cout << compute_platform_info[c].desc << buffer << "
";
}
/*cl_uint num_devices;
//could be: CPU, GPU, ACCELERATOR, DEFAULT, ALL
error = clGetDeviceIDs(the_platform, CL_DEVICE_TYPE_GPU, 1, &the_device, &num_devices);
assert(error == CL_SUCCESS);
std::cout << "Number of devices: " << num_devices << "
";*/
size_t device_size = 0;
//this line causes the app crash
error = clGetGLContextInfoKHR(the_context_properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, 0, 0, &device_size);
assert(error == CL_SUCCESS);
int num_of_devices = (device_size / sizeof(cl_device_id));
std::cout << "Number of CL-GL-interop capable devices: " << num_of_devices << "
";
error = clGetGLContextInfoKHR(the_context_properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &the_device, 0);
assert(error == CL_SUCCESS);
std::vector<compute_device_description> compute_device_info;
compute_device_info.resize(2);
compute_device_info[0] = {CL_DEVICE_VENDOR, "Device vendor: "};
compute_device_info[1] = {CL_DEVICE_NAME, "Device name: "};
//compute_device_info[2] = {CL_DEVICE_EXTENSIONS, "Device extensions: "};
for (int c = 0; c < compute_device_info.size(); c++)
{
char buffer[1024];
error = clGetDeviceInfo(the_device, compute_device_info[c].info, sizeof(buffer), &buffer, 0);
assert(error == CL_SUCCESS);
std::cout << compute_device_info[c].desc << buffer << "
";
}
cl_uint uint_buffer;
size_t size_t_buffer;
size_t size_t_array_buffer[1024];
error = clGetDeviceInfo(the_device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t_buffer), &size_t_buffer, 0);
assert(error == CL_SUCCESS);
std::cout << "Max device work group size: " << size_t_buffer << "
";
error = clGetDeviceInfo(the_device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(uint_buffer), &uint_buffer, 0);
assert(error == CL_SUCCESS);
std::cout << "Max device compute units: " << uint_buffer << "
";
error = clGetDeviceInfo(the_device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(uint_buffer), &uint_buffer, 0);
assert(error == CL_SUCCESS);
std::cout << "Max device work item dimensions: " << uint_buffer << "
";
error = clGetDeviceInfo(the_device, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t_array_buffer), &size_t_array_buffer, &size_t_buffer);
assert(error == CL_SUCCESS);
for (int c = 0; c < size_t_buffer / 8; c++)
{
std::cout << "Max device work item size [" << c << "] : " << size_t_array_buffer[c] << "
";
}
the_context = clCreateContext(the_context_properties, 1, &the_device, 0, 0, &error);
assert(error == CL_SUCCESS);
the_command_queue = clCreateCommandQueue(the_context, the_device, 0, &error);
assert(error == CL_SUCCESS);
}
any ideas what I’m doing wrong?
Best regards,
Yours3lf