cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

koveras
Journeyman III

Problems with clGetContextInfo

I cannot use OpenCL because clGetContext info returns invalid values

Hi!

I'm trying to run the following code:

size_t param_value_size_ret;

cl_int ret = clGetContextInfo(context,param_name,0,NULL,&param_value_size_ret);

cl_device_id * param_value = malloc(param_value_size_ret);

ret = clGetContextInfo((cl_context)context,param_name,param_value_size_ret,param_value,NULL);

 

Well, the problem comes when clGetContextInfo finishes.  After it, the value of param_value_size_ret has changed, and I don't know why!

EDIT: clGetContextInfo tells me that I have 2009267360 devices on my computer!!!

I'm compiling with MinGW(GCC 4.4) and I don't know what to do

Could somebody tell me something about that?

Thank you!

(Sorry for my English...)

0 Likes
10 Replies
genaganna
Journeyman III

Originally posted by: koveras Hi!

 

I'm trying to run the following code:

 

size_t param_value_size_ret;

 

cl_int ret = clGetContextInfo(context,param_name,0,NULL,&param_value_size_ret);

 

cl_device_id * param_value = malloc(param_value_size_ret);

 

ret = clGetContextInfo((cl_context)context,param_name,param_value_size_ret,param_value,NULL);

 

 

 

Well, the problem comes when clGetContextInfo finishes.  After it, the value of param_value_size_ret has changed, and I don't know why!

 

EDIT: clGetContextInfo tells me that I have 2009267360 devices on my computer!!!

 

I'm compiling with MinGW(GCC 4.4) and I don't know what to do

 

Could somebody tell me something about that?

 

Thank you!

 

(Sorry for my English...)

 

 

is there any error code returned?

 

what is the value of ret variable after each function call.

 

0 Likes

The value returned is CL_SUCCESS, so the return is correct. The only problem is that clGetContextInfo tells me that I have a lot of devices...

0 Likes

Originally posted by: koveras The value returned is CL_SUCCESS, so the return is correct. The only problem is that clGetContextInfo tells me that I have a lot of devices...

 

what is your system configuration(OS, GPU, CPU)?

 

what is value of param_value_size_ret

0 Likes

The value of param_value_size_ret is 2009267360

I have Windows XP with the ATI Stream SDK installed correctly (I can run the examples in Visual Studio)

The GPU is an ATI Radeon HD 4870

My compiler is MinGW 4.4

 

0 Likes

Is there an answer to this problem? I am having a similar issue. clGetContextInfo is telling me I have 8 devices when I only have one GPU. I created the context using CL_DEVICE_TYPE_GPU. My system is:

Intel Core i7

ATI Radeon HD5870

Ubuntu 9.10 (g++ 4.4)

ATI Stream SDK 2.01

 

Even more weird, when I run CLInfo (provided with the SDK), I tells me I have 2 devices, which is correct (CPU + GPU). I can't look into CLInfo since the source code was not included in the SDK.

 

Thank you.

0 Likes

Could you post your source code?

0 Likes

Posting my code:

#include <stdio.h> #include <string.h> #include <CL/cl.h> int main() { cl_int status = 0; // find number of platforms cl_uint numPlatforms; status = clGetPlatformIDs(0, NULL, &numPlatforms); printf("Number of platforms: %d\n", numPlatforms); // find the platform from the right vendor cl_platform_id platform = NULL; if (numPlatforms > 0) { // get all the platforms cl_platform_id *platforms = (cl_platform_id*)malloc(numPlatforms * sizeof(cl_platform_id)); status = clGetPlatformIDs(numPlatforms, platforms, NULL); // traverse the platforms array for (int i = 0 ; i < numPlatforms ; i++) { char pbuf[100]; status = clGetPlatformInfo(platforms, CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL); printf("\tPlatform Vendor: %s\n", pbuf); platform = platforms; if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) break; } // free platforms array free(platforms); } cl_context_properties cps[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0}; // use NULL for backward compatibility cl_context_properties *cprops = (platform == NULL) ? NULL : cps; // create context for device cl_context context = clCreateContextFromType(cprops, CL_DEVICE_TYPE_GPU, NULL, NULL, &status); size_t numDevices; status = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &numDevices); printf("\tNumber of devices: %d\n", (int)numDevices); cl_device_id *devices = (cl_device_id *)malloc(numDevices); status = clGetContextInfo(context, CL_CONTEXT_DEVICES, numDevices, devices, NULL); // cleanup free(devices); clReleaseContext(context); return 0; }

0 Likes

And this is the output:

Number of platforms: 1
    Platform Vendor: Advanced Micro Devices, Inc.
    Number of devices: 8

0 Likes

clGetContextInfo returns size in bytes so you must divide returned value with sizeof(cl_device_id)

0 Likes

Ok. That makes sense. I got confused with clGetPlatformIDs which actually returns the number of platforms.

Thank you.

0 Likes