Composite multiple images using OpenCL and Python: Kernel image2d_array_t?

299 Views Asked by At

As I'm exploring some ways to composite (custom overlay) multiple images into one and I found this great article https://towardsdatascience.com/get-started-with-gpu-image-processing-15e34b787480. My only issue is that I need to pass multiple buffers to the kernel as an argument and not one.

So, in python I created a list with multiple buffers

inImgsBuffers = [cl.Image(context, cl.mem_flags.READ_ONLY, cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.UNORM_INT8), shape=inShape) for inImg in inImgs]

and then tried passing them as the argument

kernel.set_arg(0, inImgsBuffers) # input image buffer

Then, on Kernel I thought to use the image2d_array_t instead of image2d_t

__kernel void morphOpKernel(__read_only image2d_array_t ins, __write_only image2d_t out)

but I'm getting the following error.

pyopencl._cl.LogicError: Kernel.set_arg failed: INVALID_VALUE - invalid kernel argument

Any ideas on what I'm doing wrong?

1

There are 1 best solutions below

0
Egor On

image2d_array_t is a special OpenCL type. So, it is not possible to create the list of pyopencl.Image objects and pass it to the kernel. Instead of it, you need to create the object of pyopencl.Image with special format that means that it is an array of 2D images:

inImgsBufFlags = cl.mem_flags.READ_ONLY
inImgsFormat = cl.ImageFormat(cl.channel_order.RGBA,
                              cl.channel_type.UNORM_INT8)
# shape of cl.Image is a tuple that contains
# (image_width, image_height, image_array_size)
inImgsShape = inShape + (len(inImgs),)
inImgsBuffers = cl.Image(context, inImgsBufFlags, inImgsFormat,
                         shape=inImgsShape, is_array=True)

kernel.set_arg(0, inImgsBuffers)