Question about clGetContextInfo and its purpose

The reference pages say: “Query information about a context.”

It seems simple enough, but the usage of this function in code examples seems very weird to me. It will show up twice in the tutorials I’ve found, like AMD Convolution OpenCL. First it will be used to figure out the size in bytes of the list of devices, which I believe means the numbers of devices can be implicitly found? Then it will be called again with this size information in order to actually get information about the context. This context information is sent a command queue. Is this all correct?

Is the whole purpose of this to get the size information of the device(s) to the command queue? Please let me know, thanks.

You are correct for the first part. The purpose of the first call is solely to know the number of devices present on the system so you can allocate a device list of the correct size.

Note that the device list may contain more that one element and could also be empty. When you create your command queue, you pass a device id (and not the size of the list) to specify on witch specific device (i.e. video card) those commands will execute.

If you have many devices, you can use the device id list to query some information on the device (manufacturer, model, memory size, etc.) in order to select the one you want.

Hope it helps…