Search code examples
openclgpgpupyopencl

Derive channel type from pyopencl.Image object


I created an pyopencl.Image object via:

import pyopencl as cl
import numpy as np
ctx = cl.create_some_context()
image = cl.image_from_array(ctx, np.ones((16, 16), dtype=np.uint8))

How can I obtain the image channel type information (here, cl.channel_type.UNSIGNED_INT8)? I want to implement a generic downloading function that returns a numpy array given an Image.

I tried two approaches:

Using Image.element_size gives me the byte size of a single element, however I can't map the element size to a data type (float32 and int32 have the same element size, for instance).

Image.format returns a cdata 'struct _cl_image_format &'. Querying either of the fields image_channel_data_type and image_channel_order returns 0.


Solution

  • I received an answer via the PyOpenCl mailing list.

    It turned out that the functionality of returning Image.format was incorrect. This has been fixed in the github repo.