Skip to content

Commit

Permalink
hazeremoval: harmonise OpenCL calls
Browse files Browse the repository at this point in the history
This changes the OpenCL invokations of the haze removal kernels to use
sizeof(type) instead of sizeof(variable), like the others OpenCL call
sites, in an effort to prevent an issue similar to aurelienpierreeng#369.

Signed-off-by: Alban Gruin <alban@pa1ch.fr>
  • Loading branch information
agrn authored and aurelienpierre committed Sep 29, 2024
1 parent 8ea6045 commit 0e94264
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/iop/hazeremoval.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,22 +564,22 @@ static int box_min_cl(struct dt_iop_module_t *self, int devid, cl_mem in, cl_mem
void *temp = dt_opencl_alloc_device(devid, width, height, (int)sizeof(float));

const int kernel_x = gd->kernel_hazeremoval_box_min_x;
dt_opencl_set_kernel_arg(devid, kernel_x, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel_x, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel_x, 2, sizeof(in), &in);
dt_opencl_set_kernel_arg(devid, kernel_x, 3, sizeof(temp), &temp);
dt_opencl_set_kernel_arg(devid, kernel_x, 4, sizeof(w), &w);
const size_t sizes_x[] = { 1, ROUNDUPDHT(height, devid) };
dt_opencl_set_kernel_arg(devid, kernel_x, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel_x, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel_x, 2, sizeof(cl_mem), &in);
dt_opencl_set_kernel_arg(devid, kernel_x, 3, sizeof(cl_mem), &temp);
dt_opencl_set_kernel_arg(devid, kernel_x, 4, sizeof(int), &w);
const size_t sizes_x[] = { 1, ROUNDUPDHT(height, devid), 1 };
int err = dt_opencl_enqueue_kernel_2d(devid, kernel_x, sizes_x);
if(err != CL_SUCCESS) goto error;

const int kernel_y = gd->kernel_hazeremoval_box_min_y;
dt_opencl_set_kernel_arg(devid, kernel_y, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel_y, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel_y, 2, sizeof(temp), &temp);
dt_opencl_set_kernel_arg(devid, kernel_y, 3, sizeof(out), &out);
dt_opencl_set_kernel_arg(devid, kernel_y, 4, sizeof(w), &w);
const size_t sizes_y[] = { ROUNDUPDWD(width, devid), 1 };
dt_opencl_set_kernel_arg(devid, kernel_y, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel_y, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel_y, 2, sizeof(cl_mem), &temp);
dt_opencl_set_kernel_arg(devid, kernel_y, 3, sizeof(cl_mem), &out);
dt_opencl_set_kernel_arg(devid, kernel_y, 4, sizeof(int), &w);
const size_t sizes_y[] = { ROUNDUPDWD(width, devid), 1, 1 };
err = dt_opencl_enqueue_kernel_2d(devid, kernel_y, sizes_y);

error:
Expand All @@ -597,22 +597,22 @@ static int box_max_cl(struct dt_iop_module_t *self, int devid, cl_mem in, cl_mem
void *temp = dt_opencl_alloc_device(devid, width, height, (int)sizeof(float));

const int kernel_x = gd->kernel_hazeremoval_box_max_x;
dt_opencl_set_kernel_arg(devid, kernel_x, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel_x, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel_x, 2, sizeof(in), &in);
dt_opencl_set_kernel_arg(devid, kernel_x, 3, sizeof(temp), &temp);
dt_opencl_set_kernel_arg(devid, kernel_x, 4, sizeof(w), &w);
const size_t sizes_x[] = { 1, ROUNDUPDHT(height, devid) };
dt_opencl_set_kernel_arg(devid, kernel_x, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel_x, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel_x, 2, sizeof(cl_mem), &in);
dt_opencl_set_kernel_arg(devid, kernel_x, 3, sizeof(cl_mem), &temp);
dt_opencl_set_kernel_arg(devid, kernel_x, 4, sizeof(int), &w);
const size_t sizes_x[] = { 1, ROUNDUPDHT(height, devid), 1 };
int err = dt_opencl_enqueue_kernel_2d(devid, kernel_x, sizes_x);
if(err != CL_SUCCESS) goto error;

const int kernel_y = gd->kernel_hazeremoval_box_max_y;
dt_opencl_set_kernel_arg(devid, kernel_y, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel_y, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel_y, 2, sizeof(temp), &temp);
dt_opencl_set_kernel_arg(devid, kernel_y, 3, sizeof(out), &out);
dt_opencl_set_kernel_arg(devid, kernel_y, 4, sizeof(w), &w);
const size_t sizes_y[] = { ROUNDUPDWD(width, devid), 1 };
dt_opencl_set_kernel_arg(devid, kernel_y, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel_y, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel_y, 2, sizeof(cl_mem), &temp);
dt_opencl_set_kernel_arg(devid, kernel_y, 3, sizeof(cl_mem), &out);
dt_opencl_set_kernel_arg(devid, kernel_y, 4, sizeof(int), &w);
const size_t sizes_y[] = { ROUNDUPDWD(width, devid), 1, 1 };
err = dt_opencl_enqueue_kernel_2d(devid, kernel_y, sizes_y);

error:
Expand All @@ -630,15 +630,15 @@ static int transition_map_cl(struct dt_iop_module_t *self, int devid, cl_mem img
const int height = dt_opencl_get_image_height(img1);

const int kernel = gd->kernel_hazeremoval_transision_map;
dt_opencl_set_kernel_arg(devid, kernel, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel, 2, sizeof(img1), &img1);
dt_opencl_set_kernel_arg(devid, kernel, 3, sizeof(img2), &img2);
dt_opencl_set_kernel_arg(devid, kernel, 4, sizeof(strength), &strength);
dt_opencl_set_kernel_arg(devid, kernel, 5, sizeof(A0[0]), &A0[0]);
dt_opencl_set_kernel_arg(devid, kernel, 6, sizeof(A0[1]), &A0[1]);
dt_opencl_set_kernel_arg(devid, kernel, 7, sizeof(A0[2]), &A0[2]);
size_t sizes[2] = { ROUNDUPDWD(width, devid), ROUNDUPDHT(height, devid) };
dt_opencl_set_kernel_arg(devid, kernel, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel, 2, sizeof(cl_mem), &img1);
dt_opencl_set_kernel_arg(devid, kernel, 3, sizeof(cl_mem), &img2);
dt_opencl_set_kernel_arg(devid, kernel, 4, sizeof(float), &strength);
dt_opencl_set_kernel_arg(devid, kernel, 5, sizeof(float), &A0[0]);
dt_opencl_set_kernel_arg(devid, kernel, 6, sizeof(float), &A0[1]);
dt_opencl_set_kernel_arg(devid, kernel, 7, sizeof(float), &A0[2]);
size_t sizes[] = { ROUNDUPDWD(width, devid), ROUNDUPDHT(height, devid), 1 };
int err = dt_opencl_enqueue_kernel_2d(devid, kernel, sizes);
if(err != CL_SUCCESS)
{
Expand All @@ -659,16 +659,16 @@ static int dehaze_cl(struct dt_iop_module_t *self, int devid, cl_mem img_in, cl_
const int height = dt_opencl_get_image_height(img_in);

const int kernel = gd->kernel_hazeremoval_dehaze;
dt_opencl_set_kernel_arg(devid, kernel, 0, sizeof(width), &width);
dt_opencl_set_kernel_arg(devid, kernel, 1, sizeof(height), &height);
dt_opencl_set_kernel_arg(devid, kernel, 2, sizeof(img_in), &img_in);
dt_opencl_set_kernel_arg(devid, kernel, 3, sizeof(trans_map), &trans_map);
dt_opencl_set_kernel_arg(devid, kernel, 4, sizeof(img_out), &img_out);
dt_opencl_set_kernel_arg(devid, kernel, 5, sizeof(t_min), &t_min);
dt_opencl_set_kernel_arg(devid, kernel, 6, sizeof(A0[0]), &A0[0]);
dt_opencl_set_kernel_arg(devid, kernel, 7, sizeof(A0[1]), &A0[1]);
dt_opencl_set_kernel_arg(devid, kernel, 8, sizeof(A0[2]), &A0[2]);
size_t sizes[2] = { ROUNDUPDWD(width, devid), ROUNDUPDHT(height, devid) };
dt_opencl_set_kernel_arg(devid, kernel, 0, sizeof(int), &width);
dt_opencl_set_kernel_arg(devid, kernel, 1, sizeof(int), &height);
dt_opencl_set_kernel_arg(devid, kernel, 2, sizeof(cl_mem), &img_in);
dt_opencl_set_kernel_arg(devid, kernel, 3, sizeof(cl_mem), &trans_map);
dt_opencl_set_kernel_arg(devid, kernel, 4, sizeof(cl_mem), &img_out);
dt_opencl_set_kernel_arg(devid, kernel, 5, sizeof(float), &t_min);
dt_opencl_set_kernel_arg(devid, kernel, 6, sizeof(float), &A0[0]);
dt_opencl_set_kernel_arg(devid, kernel, 7, sizeof(float), &A0[1]);
dt_opencl_set_kernel_arg(devid, kernel, 8, sizeof(float), &A0[2]);
size_t sizes[] = { ROUNDUPDWD(width, devid), ROUNDUPDHT(height, devid), 1 };
int err = dt_opencl_enqueue_kernel_2d(devid, kernel, sizes);
if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, "[hazeremoval, dehaze_cl] unknown error: %d\n", err);
return err;
Expand Down

0 comments on commit 0e94264

Please sign in to comment.