Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the methods for pixel reading and writing #14

Open
maarzt opened this issue Jun 17, 2021 · 1 comment
Open

Simplify the methods for pixel reading and writing #14

maarzt opened this issue Jun 17, 2021 · 1 comment

Comments

@maarzt
Copy link

maarzt commented Jun 17, 2021

When writing a OpenCL kernel in clEsperanto, the code for reading a pixel usually looks like this:

const POS_src_TYPE spos = POS_src_INSTANCE(sx, sy, 0, 0);
const float a = READ_src_IMAGE(src,sampler,spos).x;

I understand the benefits that clEsperanto gives us here. But I would suggest to go further and simplify this by adding a C #define such that the example above could be rewritten as:

const float a = READ_PIXEL_2D(src, sx, sy);

The define could look like this:

#define READ_PIXEL_2D(image, x, y) (READ_ ## image ## _IMAGE((image), sampler, POS_ ## image ## _INSTANCE((x), (y), 0, 0)).x)

The same should be done for image writing, and 3d images.

@haesleinhuepf
Copy link
Member

Hey @maarzt ,

great to see you here!

The same should be done for image writing, and 3d images.

I think we could even formulate that in a 2D-3D-agnostic way. E.g.

#define READ_PIXEL(image, x, y, z) (READ_ ## image ## _IMAGE((image), sampler, POS_ ## image ## _INSTANCE((x), (y), (z), 0)).x)

And the change appears backwards-compatible. Thus, we can build it in the preamble any time and update kernels step by step.

Thanks for the suggestion!

Cheers,
Robert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants