PDA

View Full Version : Unexpected output clGetContextInfo



bnut
09-01-2009, 10:22 PM
Hi,

The spec doesn't seem to be clear on this, so I thought I would ask here:

I have created a context using clCreateContextFromType and CL_DEVICE_TYPE_ALL which returns a non zero context and CL_SUCCESS.

When querying this context for all devices using clGetContextInfo with CL_CONTEXT_DEVICES i also get CL_SUCCESS, however the returned size and device list do not appear to be correct.

The problem is:
The returned data is 32 bit, not 64 and the data is not a valid device.

The size is 4 bytes, which is half a word on my 64 bit MacBook Pro running Mac OSX Snow Leopard. The size given by sizeof(cl_device_id) is of course 8 bytes. So arguably this is invalid, or the implementation is made for a 32bit machine...? However, if I ignore this, there should be 2 devices returned (CPU+GPU), which queries on the platform indicate. Also ignoring this, the value of the data is always 0x2, which when treated like a device seems to be invalid also (although I was not thorough).

Has anyone else come across this? Or am I missing something obvious? Perhaps it is a problem with the implementation or current spec?

Other OpenCL code seems to work, but I would like to be able to query the context like this.

Platform:
Name = "Apple";
Vendor = "Apple";
Version = "OpenCL 1.0 (May 28 2009 16:54:15)";

GPU:
Name = "GeForce 9400M";
Vendor = "NVIDIA";
Version = "OpenCL 1.0";

CPU:
Name = "Intel(R) Core(TM)2 Duo CPU T9550 @ 2.66GHz";
Vendor = "Intel";
Version = "OpenCL 1.0";

affie
09-02-2009, 02:00 PM
Can you post your test example source that shows this problem?

bnut
09-02-2009, 07:06 PM
This isn't the original code, but a cut down version which exhibits the same behaviour, and with a bit of tracing information.


#include <OpenCL/OpenCL.h>

int main(int argc, char *argv[])
{
cl_int errcode;

cl_context context = clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL, NULL, NULL, &errcode);

if (!context)
{
return errcode;
}

if (errcode != CL_SUCCESS)
{
clReleaseContext(context);
return errcode;
}

size_t devices_size;
errcode = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &devices_size);

if (errcode != CL_SUCCESS)
{
clReleaseContext(context);
return errcode;
}

printf("sizeof(cl_device_id): %u\n", (unsigned) sizeof(cl_device_id));
printf("devices_size: %u\n", (unsigned) devices_size);

size_t devices_size_ret;
cl_device_id * devices = alloca(devices_size);
errcode = clGetContextInfo(context, CL_CONTEXT_DEVICES, devices_size, devices, &devices_size_ret);

if (errcode != CL_SUCCESS)
{
clReleaseContext(context);
return errcode;
}

printf("devices_size_ret: %u\n", (unsigned) devices_size_ret);

printf("device data: ");
for (unsigned i=0; i<devices_size_ret; ++i)
{
printf("%X", ((char*)devices)[i]);
}
printf("\n");

cl_device_id word = (void*) 2;
printf("comparative cl_device_id: ");
for (unsigned i=0; i<sizeof(cl_device_id); ++i)
{
printf("%X", ((char*)&word)[i]);
}
printf("\n");

return 0;
}


This is the output from running that code on my machine:

sizeof(cl_device_id): 8
devices_size: 4
devices_size_ret: 4
device data: 2000
comparative cl_device_id: 20000000

bnut
09-02-2009, 07:20 PM
The addition of this code:

size_t param_value_size_ret;
errcode = clGetDeviceInfo((cl_device_id)((int*)devices)[0], CL_DEVICE_NAME, 0, NULL, &param_value_size_ret);
if (errcode == CL_INVALID_DEVICE)
{
printf("Invalid device: %p", (cl_device_id)((int*)devices)[0]);
}

clReleaseContext(context);


Provides the following output, (as well as a few expected compiler warnings):

sizeof(cl_device_id): 8
devices_size: 4
devices_size_ret: 4
device data: 2000
comparative cl_device_id: 20000000
Invalid device: 0x2

affie
09-02-2009, 10:05 PM
I ran the posted test source on my MacBook Pro and got the following:

sizeof(cl_device_id): 8
devices_size: 16
devices_size_ret: 16
device data: 02622000004210000
comparative cl_device_id: 20000000

I was unable to reproduce your problem so am wondering what is the version of SnowLeopard you are running. BTW if you have an Apple Developer account, do please file a bug using your ADC account.

bnut
09-03-2009, 01:05 AM
Thanks for trying anyway,

Snow Leopard build 10A380 until I can find a dual layer DVD to update.

I have installed XCode Xcode 3.1 2199 from that DVD (snowleopard_10a432_userdvd) dmg.

However (before I lost my HDD) I had similar problems with the update prior to 10a432, I can't remember the build number.

The OpenCL version is given from clGetPlatformInfo in my original post as "OpenCL 1.0 (May 28 2009 16:54:15)".

I have an ADC account and if the problem persists after I update I will submit a bug report. I was hoping it was my error, and not a problem with the build so I could continue work.

bnut
09-03-2009, 02:23 AM
I managed to install the latest build by restoring my Snow Leopard dmg to a spare partition using Disk Utility. Suffice to say that worked, and now the unexpected behaviour I have described has stopped. Yay me for finding a bug, if only it was still relevant.

Thanks for your help affie.