50#define CLAMPI(a, mn, mx) ((a) < (mn) ? (mn) : ((a) > (mx) ? (mx) : (a)))
56#define CL_ALIGNMENT ((piece->dsc_in.filters != 9u) ? 4 : 1)
64static unsigned _gcd(
unsigned a,
unsigned b)
77static unsigned _lcm(
unsigned a,
unsigned b)
79 return (((
unsigned long)a * b) /
_gcd(a, b));
83static inline int _min(
int a,
int b)
88static inline int _max(
int a,
int b)
96 return n + a - (
n % a);
104 const int off =
n % a;
105 const int shift = (off > a/2) ? a - off : -off;
120 fprintf(stderr,
" {%5d %5d ->%5d %5d (%5dx%5d) %.6f } %s\n",
127_nm_constraints(
double x[],
int n)
134 if(
x[0] > 1.0)
x[0] = 1.0 -
x[0];
135 if(
x[1] > 1.0)
x[1] = 1.0 -
x[1];
136 if(
x[2] > 1.0)
x[2] = 1.0 -
x[2];
137 if(
x[3] > 1.0)
x[3] = 1.0 -
x[3];
144 void **rest = (
void **)params;
159 self->modify_roi_in(self, pipe, &piece_copy, &oroi_test, &iroi_probe);
161 double fitness = 0.0;
163 fitness += (
double)(iroi_probe.
x - iroi->
x) * (iroi_probe.
x - iroi->
x);
164 fitness += (
double)(iroi_probe.
y - iroi->
y) * (iroi_probe.
y - iroi->
y);
176 void *rest[5] = { (
void *)self, (
void *)piece, (
void *)iroi, (
void *)oroi, (
void *)pipe };
177 double start[4] = { (float)oroi->
x / piece->
iwidth, (
float)oroi->
y / piece->
iheight,
186 oroi->
x = start[0] * piece->
iwidth;
187 oroi->
y = start[1] * piece->
iheight;
191 return (iter <= maxiter);
209 self->modify_roi_in(self, pipe, &piece_copy, oroi, &iroi_probe);
210 while((abs((
int)iroi_probe.
x - (
int)iroi->
x) >
delta || abs((
int)iroi_probe.
y - (
int)iroi->
y) >
delta
217 oroi->
x += (iroi->
x - iroi_probe.
x) * oroi->
scale / iroi->
scale;
218 oroi->
y += (iroi->
y - iroi_probe.
y) * oroi->
scale / iroi->
scale;
225 self->modify_roi_in(self, pipe, &piece_copy, oroi, &iroi_probe);
229 if(iter > 0)
return TRUE;
245 const void *
const ivoid,
void *
const ovoid,
252 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_ptp] **** tiling module '%s' for image with size %dx%d --> %dx%d\n",
256 const int ipitch = roi_in->
width * in_bpp;
257 const int opitch = roi_out->
width * out_bpp;
258 const int max_bpp =
_max(in_bpp, out_bpp);
262 self->tiling_callback(self, pipe, piece, &
tiling);
270 "memory saving to be expected\n", self->
op);
276 assert(available >= 500.0f * 1024.0f * 1024.0f);
278 available = fmaxf(available - ((
float)roi_out->
width * roi_out->
height * out_bpp)
287 const float maxbuf = fmaxf(
tiling.maxbuf, 1.0f);
288 const float singlebuffer = available /
factor;
294 if((
float)
width *
height * max_bpp * maxbuf > singlebuffer)
296 const float scale = singlebuffer / ((float)
width *
height * max_bpp * maxbuf);
299 if(width < height && scale >= 0.333f)
303 else if(height <= width && scale >= 0.333f)
333 assert(xyalign != 0);
340 const int overlap =
tiling.overlap % xyalign != 0 ? (
tiling.overlap / xyalign + 1) * xyalign
344 const int tile_wd =
width - 2 * overlap > 0 ?
width - 2 * overlap : 1;
345 const int tile_ht =
height - 2 * overlap > 0 ?
height - 2 * overlap : 1;
348 const int tiles_x =
width < roi_in->
width ? ceilf(roi_in->
width / (
float)tile_wd) : 1;
349 const int tiles_y =
height < roi_in->
height ? ceilf(roi_in->
height / (
float)tile_ht) : 1;
354 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_ptp] gave up tiling for module '%s'. too many tiles: %d x %d\n",
355 self->
op, tiles_x, tiles_y);
359 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_ptp] (%dx%d) tiles with max dimensions %dx%d and overlap %d\n",
383 for(
size_t tx = 0; tx < tiles_x; tx++)
386 for(
size_t ty = 0; ty < tiles_y; ty++)
393 if((wd <= 2 * overlap && tx > 0) || (ht <= 2 * overlap && ty > 0))
continue;
396 size_t origin[] = { 0, 0, 0 };
397 size_t region[] = { wd, ht, 1 };
400 dt_iop_roi_t iroi = { roi_in->
x + tx * tile_wd, roi_in->
y + ty * tile_ht, wd, ht, roi_in->
scale };
401 dt_iop_roi_t oroi = { roi_out->
x + tx * tile_wd, roi_out->
y + ty * tile_ht, wd, ht, roi_out->
scale };
404 const size_t ioffs = (ty * tile_ht) * ipitch + (tx * tile_wd) * in_bpp;
405 size_t ooffs = (ty * tile_ht) * opitch + (tx * tile_wd) * out_bpp;
407 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_ptp] tile (%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
") with %" G_GSIZE_FORMAT
"x%" G_GSIZE_FORMAT
" at origin [%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
"]\n",
408 tx, ty, wd, ht, tx * tile_wd, ty * tile_ht);
412 for(
size_t j = 0; j < ht; j++)
413 memcpy((
char *)input + j * wd * in_bpp, (
char *)ivoid + ioffs + j * ipitch, (
size_t)wd * in_bpp);
419 int err = self->process(self, pipe, &piece_tile, input, output);
432 origin[0] += overlap;
433 region[0] -= overlap;
434 ooffs += (size_t)overlap * out_bpp;
438 origin[1] += overlap;
439 region[1] -= overlap;
440 ooffs += (size_t)overlap * opitch;
445 for(
size_t j = 0; j < region[1]; j++)
446 memcpy((
char *)
ovoid + ooffs + j * opitch,
447 (
char *)output + ((j + origin[1]) * wd + origin[0]) * out_bpp, (
size_t)region[0] * out_bpp);
457 dt_control_log(_(
"tiling failed for module '%s'. output might be garbled."), self->
op);
466 int err = self->process(self, pipe, piece, ivoid,
ovoid);
476 const void *
const ivoid,
void *
const ovoid,
484 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_roi] **** tiling module '%s' for image input size %dx%d --> %dx%d\n",
491 const int ipitch = roi_in->
width * in_bpp;
492 const int opitch = roi_out->
width * out_bpp;
493 const int max_bpp =
_max(in_bpp, out_bpp);
495 float fullscale = fmaxf(roi_in->
scale / roi_out->
scale, sqrtf(((
float)roi_in->
width * roi_in->
height)
499 const int delta = ceilf(fullscale);
506 self->tiling_callback(self, pipe, piece, &
tiling);
512 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_roi] no need to use tiling for module '%s' as no memory saving is expected\n",
519 assert(available >= 500.0f * 1024.0f * 1024.0f);
521 available = fmaxf(available - ((
float)roi_out->
width * roi_out->
height * out_bpp)
530 const float maxbuf = fmaxf(
tiling.maxbuf, 1.0f);
531 const float singlebuffer = available /
factor;
544 assert(xyalign != 0);
547 if((
float)
width *
height * max_bpp * maxbuf > singlebuffer)
549 const float scale = singlebuffer / ((float)
width *
height * max_bpp * maxbuf);
552 if(width < height && scale >= 0.333f)
556 else if(height <= width && scale >= 0.333f)
580 const int overlap_out = ceilf((
float)overlap_in / fullscale);
582 int tiles_x = 1, tiles_y = 1;
588 ? ceilf((
float)roi_in->
width / (
float)
_max(
width - 2 * overlap_in - inacc, 1))
596 ? ceilf((
float)roi_in->
height / (
float)
_max(
height - 2 * overlap_in - inacc, 1))
606 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_roi] gave up tiling for module '%s'. too many tiles: %d x %d\n",
607 self->
op, tiles_x, tiles_y);
615 roi_out->
width % tiles_x == 0 ? roi_out->
width / tiles_x : roi_out->
width / tiles_x + 1, xyalign);
617 roi_out->
height % tiles_y == 0 ? roi_out->
height / tiles_y : roi_out->
height / tiles_y + 1, xyalign);
619 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_roi] (%dx%d) tiles with max dimensions %dx%d, good %dx%d, overlap %d->%d\n",
620 tiles_x, tiles_y,
width,
height, tile_wd, tile_ht, overlap_in, overlap_out);
623 for(
size_t tx = 0; tx < tiles_x; tx++)
624 for(
size_t ty = 0; ty < tiles_y; ty++)
629 const size_t wd = (tx + 1) * tile_wd > roi_out->
width ? (
size_t)roi_out->
width - tx * tile_wd : tile_wd;
630 const size_t ht = (ty + 1) * tile_ht > roi_out->
height ? (
size_t)roi_out->
height - ty * tile_ht : tile_ht;
634 dt_iop_roi_t iroi_good = { roi_in->
x + tx * tile_wd, roi_in->
y + ty * tile_ht, wd, ht, roi_in->
scale };
635 dt_iop_roi_t oroi_good = { roi_out->
x + tx * tile_wd, roi_out->
y + ty * tile_ht, wd, ht, roi_out->
scale };
638 self->modify_roi_in(self, pipe, &piece_copy, &oroi_good, &iroi_good);
641 iroi_good.
x =
_max(iroi_good.
x, roi_in->
x);
642 iroi_good.
y =
_max(iroi_good.
y, roi_in->
y);
653 const int x_in = iroi_good.
x;
654 const int y_in = iroi_good.
y;
655 const int width_in = iroi_good.
width;
656 const int height_in = iroi_good.
height;
659 const int new_width_in =
_min(
_align_up(width_in + overlap_in +
delta + (x_in - new_x_in), xyalign),
660 roi_in->
width + roi_in->
x - new_x_in);
661 const int new_height_in =
_min(
_align_up(height_in + overlap_in +
delta + (y_in - new_y_in), xyalign),
662 roi_in->
height + roi_in->
y - new_y_in);
666 dt_iop_roi_t iroi_full = { new_x_in, new_y_in, new_width_in, new_height_in, iroi_good.
scale };
669 _print_roi(&iroi_full,
"tile iroi_full before optimization");
670 _print_roi(&oroi_full,
"tile oroi_full before optimization");
676 "module '%s' not possible.\n",
681 _print_roi(&iroi_full,
"tile iroi_full after optimization");
682 _print_roi(&oroi_full,
"tile oroi_full after optimization");
686 oroi_full.
x =
_min(oroi_full.
x, oroi_good.
x);
687 oroi_full.
y =
_min(oroi_full.
y, oroi_good.
y);
692 oroi_full.
x =
_max(oroi_full.
x, roi_out->
x);
693 oroi_full.
y =
_max(oroi_full.
y, roi_out->
y);
699 self->modify_roi_in(self, pipe, &piece_full, &oroi_full, &iroi_full);
702 iroi_full.
x =
_max(iroi_full.
x, roi_in->
x);
703 iroi_full.
y =
_max(iroi_full.
y, roi_in->
y);
707 _print_roi(&iroi_full,
"tile iroi_full final");
708 _print_roi(&oroi_full,
"tile oroi_full final");
711 const size_t ioffs = ((size_t)iroi_full.
y - roi_in->
y) * ipitch + ((size_t)iroi_full.
x - roi_in->
x) * in_bpp;
712 size_t ooffs = ((size_t)oroi_good.
y - roi_out->
y) * opitch + ((size_t)oroi_good.
x - roi_out->
x) * out_bpp;
714 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_roi] process tile (%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
") size %dx%d at origin [%d,%d]\n",
715 tx, ty, iroi_full.
width, iroi_full.
height, iroi_full.
x, iroi_full.
y);
719 (
size_t)iroi_full.
width * iroi_full.
height * in_bpp,
728 (
size_t)oroi_full.
width * oroi_full.
height * out_bpp,
737 for(
size_t j = 0; j < iroi_full.
height; j++)
738 memcpy((
char *)input + j * iroi_full.
width * in_bpp, (
char *)ivoid + ioffs + j * ipitch,
739 (
size_t)iroi_full.
width * in_bpp);
743 piece_tile.
roi_in = iroi_full;
744 piece_tile.
roi_out = oroi_full;
745 int err = self->process(self, pipe, &piece_tile, input, output);
755 const int origin_x = oroi_good.
x - oroi_full.
x;
756 const int origin_y = oroi_good.
y - oroi_full.
y;
758 for(
size_t j = 0; j < oroi_good.
height; j++)
759 memcpy((
char *)
ovoid + ooffs + j * opitch,
760 (
char *)output + ((j + origin_y) * oroi_full.
width + origin_x) * out_bpp,
761 (
size_t)oroi_good.
width * out_bpp);
765 input = output = NULL;
774 dt_control_log(_(
"tiling failed for module '%s'. output might be garbled."), self->
op);
783 int err = self->process(self, pipe, piece, ivoid,
ovoid);
796 const void *
const ivoid,
void *
const ovoid,
const int in_bpp)
812 const void *
const ivoid,
void *
const ovoid,
819 cl_mem output = NULL;
821 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_cl_ptp] **** tiling module '%s' for image with size %dx%d --> %dx%d\n",
827 const int ipitch = roi_in->
width * in_bpp;
828 const int opitch = roi_out->
width * out_bpp;
829 const int max_bpp =
_max(in_bpp, out_bpp);
833 self->tiling_callback(self, pipe, piece, &
tiling);
838 const float singlebuffer = fminf(fmaxf((available -
tiling.overhead) /
factor, 0.0f),
840 const float maxbuf = fmaxf(
tiling.maxbuf_cl, 1.0f);
845 if((
float)
width *
height * max_bpp * maxbuf > singlebuffer)
847 const float scale = singlebuffer / ((float)
width *
height * max_bpp * maxbuf);
849 if(width < height && scale >= 0.333f)
853 else if(height <= width && scale >= 0.333f)
887 const unsigned int halign = xyalign;
889 assert(xyalign != 0 && walign != 0 && halign != 0);
903 if(
width <= (
int)walign &&
height <= (int)halign)
break;
904 if(width < height && height > (
int)halign)
906 else if(
width > (
int)walign)
913 const int overlap =
tiling.overlap % xyalign != 0 ? (
tiling.overlap / xyalign + 1) * xyalign
918 const int tile_wd =
width - 2 * overlap > 0 ?
width - 2 * overlap : 1;
919 const int tile_ht =
height - 2 * overlap > 0 ?
height - 2 * overlap : 1;
923 const int tiles_x =
width < roi_in->
width ? ceilf(roi_in->
width / (
float)tile_wd) : 1;
924 const int tiles_y =
height < roi_in->
height ? ceilf(roi_in->
height / (
float)tile_ht) : 1;
929 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_cl_ptp] aborted tiling for module '%s'. too many tiles: %d x %d\n",
930 self->
op, tiles_x, tiles_y);
934 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_cl_ptp] (%dx%d) tiles with max dimensions %dx%d, good %dx%d and overlap %d\n",
935 tiles_x, tiles_y,
width,
height, tile_wd, tile_ht, overlap);
938 for(
size_t tx = 0; tx < tiles_x; tx++)
939 for(
size_t ty = 0; ty < tiles_y; ty++)
947 if((wd <= 2 * overlap && tx > 0) || (ht <= 2 * overlap && ty > 0))
continue;
950 size_t origin[] = { 0, 0, 0 };
951 size_t region[] = { wd, ht, 1 };
954 dt_iop_roi_t iroi = { roi_in->
x + tx * tile_wd, roi_in->
y + ty * tile_ht, wd, ht, roi_in->
scale };
955 dt_iop_roi_t oroi = { roi_out->
x + tx * tile_wd, roi_out->
y + ty * tile_ht, wd, ht, roi_out->
scale };
959 const size_t ioffs = (ty * tile_ht) * ipitch + (tx * tile_wd) * in_bpp;
960 size_t ooffs = (ty * tile_ht) * opitch + (tx * tile_wd) * out_bpp;
963 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_cl_ptp] tile (%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
") size %" G_GSIZE_FORMAT
"x%" G_GSIZE_FORMAT
" at origin [%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
"]\n",
964 tx, ty, wd, ht, tx * tile_wd, ty * tile_ht);
975 if(err != CL_SUCCESS)
goto error;
981 if(!self->process_cl(self, pipe, &piece_tile, input, output))
goto error;
987 origin[0] += overlap;
988 region[0] -= overlap;
989 ooffs += (size_t)overlap * out_bpp;
993 origin[1] += overlap;
994 region[1] -= overlap;
995 ooffs += (size_t)overlap * opitch;
1001 if(err != CL_SUCCESS)
goto error;
1015 mutable_pipe->
tiling = 0;
1021 mutable_pipe->
tiling = 0;
1023 "[default_process_tiling_opencl_ptp] couldn't run process_cl() for module '%s' in tiling mode: %i\n",
1033 const void *
const ivoid,
void *
const ovoid,
1039 cl_mem input = NULL;
1040 cl_mem output = NULL;
1043 "[default_process_tiling_cl_roi] **** tiling module '%s' for image with input size %dx%d --> %dx%d\n",
1051 const int ipitch = roi_in->
width * in_bpp;
1052 const int opitch = roi_out->
width * out_bpp;
1053 const int max_bpp =
_max(in_bpp, out_bpp);
1055 const float fullscale = fmaxf(roi_in->
scale / roi_out->
scale, sqrtf(((
float)roi_in->
width * roi_in->
height)
1059 const int delta = ceilf(fullscale);
1066 self->tiling_callback(self, pipe, piece, &
tiling);
1071 const float singlebuffer = fminf(fmaxf((available -
tiling.overhead) /
factor, 0.0f),
1073 const float maxbuf = fmaxf(
tiling.maxbuf_cl, 1.0f);
1087 assert(xyalign != 0);
1090 if((
float)
width *
height * max_bpp * maxbuf > singlebuffer)
1092 const float scale = singlebuffer / ((float)
width *
height * max_bpp * maxbuf);
1094 if(width < height && scale >= 0.333f)
1098 else if(height <= width && scale >= 0.333f)
1122 const int overlap_out = ceilf((
float)overlap_in / fullscale);
1130 if(
width <= (
int)xyalign &&
height <= (
int)xyalign)
break;
1131 if(width < height && height > (
int)xyalign)
1133 else if(
width > (
int)xyalign)
1139 int tiles_x = 1, tiles_y = 1;
1145 ? ceilf((
float)roi_in->
width / (
float)
_max(
width - 2 * overlap_in - inacc, 1))
1153 ? ceilf((
float)roi_in->
height / (
float)
_max(
height - 2 * overlap_in - inacc, 1))
1164 "[default_process_tiling_cl_roi] aborted tiling for module '%s'. too many tiles: %dx%d\n",
1165 self->
op, tiles_x, tiles_y);
1172 roi_out->
width % tiles_x == 0 ? roi_out->
width / tiles_x : roi_out->
width / tiles_x + 1, xyalign);
1174 roi_out->
height % tiles_y == 0 ? roi_out->
height / tiles_y : roi_out->
height / tiles_y + 1, xyalign);
1177 "[default_process_tiling_cl_roi] (%dx%d) tiles with max input dimensions %dx%d, good %ix%i\n",
1178 tiles_x, tiles_y,
width,
height, tile_wd, tile_ht);
1181 for(
size_t tx = 0; tx < tiles_x; tx++)
1182 for(
size_t ty = 0; ty < tiles_y; ty++)
1184 mutable_pipe->
tiling = 1;
1187 const size_t wd = (tx + 1) * tile_wd > roi_out->
width ? (
size_t)roi_out->
width - tx * tile_wd : tile_wd;
1188 const size_t ht = (ty + 1) * tile_ht > roi_out->
height ? (
size_t)roi_out->
height - ty * tile_ht : tile_ht;
1192 dt_iop_roi_t iroi_good = { roi_in->
x + tx * tile_wd, roi_in->
y + ty * tile_ht, wd, ht, roi_in->
scale };
1193 dt_iop_roi_t oroi_good = { roi_out->
x + tx * tile_wd, roi_out->
y + ty * tile_ht, wd, ht, roi_out->
scale };
1196 self->modify_roi_in(self, pipe, &piece_copy, &oroi_good, &iroi_good);
1199 iroi_good.
x =
_max(iroi_good.
x, roi_in->
x);
1200 iroi_good.
y =
_max(iroi_good.
y, roi_in->
y);
1211 const int x_in = iroi_good.
x;
1212 const int y_in = iroi_good.
y;
1213 const int width_in = iroi_good.
width;
1214 const int height_in = iroi_good.
height;
1217 const int new_width_in =
_min(
_align_up(width_in + overlap_in +
delta + (x_in - new_x_in), xyalign),
1218 roi_in->
width + roi_in->
x - new_x_in);
1219 const int new_height_in =
_min(
_align_up(height_in + overlap_in +
delta + (y_in - new_y_in), xyalign),
1220 roi_in->
height + roi_in->
y - new_y_in);
1224 dt_iop_roi_t iroi_full = { new_x_in, new_y_in, new_width_in, new_height_in, iroi_good.
scale };
1227 _print_roi(&iroi_full,
"tile iroi_full before optimization");
1228 _print_roi(&oroi_full,
"tile oroi_full before optimization");
1234 "for module '%s' not possible.\n",
1242 oroi_full.
x =
_min(oroi_full.
x, oroi_good.
x);
1243 oroi_full.
y =
_min(oroi_full.
y, oroi_good.
y);
1248 oroi_full.
x =
_max(oroi_full.
x, roi_out->
x);
1249 oroi_full.
y =
_max(oroi_full.
y, roi_out->
y);
1256 self->modify_roi_in(self, pipe, &piece_full, &oroi_full, &iroi_full);
1259 iroi_full.
x =
_max(iroi_full.
x, roi_in->
x);
1260 iroi_full.
y =
_max(iroi_full.
y, roi_in->
y);
1268 const int in_dx = iroi_full.
x - roi_in->
x;
1269 const int in_dy = iroi_full.
y - roi_in->
y;
1270 const int out_dx = oroi_good.
x - roi_out->
x;
1271 const int out_dy = oroi_good.
y - roi_out->
y;
1272 const size_t ioffs = (size_t)(in_dy * ipitch) + (size_t)(in_dx * in_bpp);
1273 const size_t ooffs = (size_t)(out_dy * opitch) + (size_t)(out_dx * out_bpp);
1276 size_t iorigin[] = { 0, 0, 0 };
1277 size_t iregion[] = { iroi_full.
width, iroi_full.
height, 1 };
1280 size_t oorigin[] = { oroi_good.
x - oroi_full.
x, oroi_good.
y - oroi_full.
y, 0 };
1281 size_t oregion[] = { oroi_good.
width, oroi_good.
height, 1 };
1283 dt_print(
DT_DEBUG_TILING,
"[default_process_tiling_cl_roi] process tile (%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
") size %dx%d at origin [%d,%d]\n",
1284 tx, ty, iroi_full.
width, iroi_full.
height, iroi_full.
x, iroi_full.
y);
1285 dt_vprint(
DT_DEBUG_TILING,
"[default_process_tiling_cl_roi] dest [%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
"] at [%" G_GSIZE_FORMAT
",%" G_GSIZE_FORMAT
"], offsets [%i,%i] -> [%i,%i], delta=%i\n\n",
1286 oregion[0], oregion[1], oorigin[0], oorigin[1], in_dx, in_dy, out_dx, out_dy,
delta);
1298 if(err != CL_SUCCESS)
goto error;
1302 piece_tile.
roi_in = iroi_full;
1303 piece_tile.
roi_out = oroi_full;
1304 if(!self->process_cl(self, pipe, &piece_tile, input, output))
goto error;
1309 if(err != CL_SUCCESS)
goto error;
1323 mutable_pipe->
tiling = 0;
1329 mutable_pipe->
tiling = 0;
1331 "[default_process_tiling_opencl_roi] couldn't run process_cl() for module '%s' in tiling mode: %i\n",
1343 const void *
const ivoid,
void *
const ovoid,
const int in_bpp)
1356 const void *
const ivoid,
void *
const ovoid,
const int in_bpp)
1379 tiling->factor = 1.0f + ioratio;
1413 const float factor,
const size_t overhead)
1420 while(!
error && available < total)
1426 if(total <= available)
static void error(char *msg)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_control_log(const char *msg,...)
void dt_vprint(dt_debug_thread_t thread, const char *msg,...)
size_t dt_get_available_mem()
void dt_print(dt_debug_thread_t thread, const char *msg,...)
#define dt_pixelpipe_cache_alloc_align_cache(size, id)
#define dt_pixelpipe_cache_free_align(mem)
#define __OMP_PARALLEL_FOR__(...)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
@ IOP_FLAGS_TILING_FULL_ROI
int dt_ioppr_get_iop_order(GList *iop_order_list, const char *op_name, const int multi_priority)
Return the iop_order for a given operation/instance pair.
static int simplex(double(*objfunc)(double[], void *params), double start[], int n, double EPSILON, double scale, int maxiter, void(*constrain)(double[], int n), void *params)
cl_ulong dt_opencl_get_device_available(const int devid)
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking)
cl_ulong dt_opencl_get_device_memalloc(const int devid)
gboolean dt_opencl_finish(const int devid)
int dt_opencl_write_host_to_device_raw(const int devid, const void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking)
void dt_opencl_release_mem_object(cl_mem mem)
int dt_dev_pixel_pipe_cache_remove_lru(dt_dev_pixelpipe_cache_t *cache)
struct dt_dev_pixelpipe_cache_t * pixelpipe_cache
struct dt_opencl_t * opencl
dt_iop_buffer_dsc_t dsc_out
dt_iop_buffer_dsc_t dsc_in
dt_dev_pixelpipe_type_t type
GModule *dt_dev_operation_t op
Region of interest passed through the pixelpipe.
typedef double((*spd)(unsigned long int wavelength, double TempK))
static double _nm_fitness(double x[], void *params)
int default_process_tiling(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const int in_bpp)
static int _fit_output_to_input_roi(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *iroi, dt_iop_roi_t *oroi, int delta, int iter)
static int _nm_fit_output_to_input_roi(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *iroi, dt_iop_roi_t *oroi, int delta)
void default_tiling_callback(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, struct dt_develop_tiling_t *tiling)
static int _default_process_tiling_roi(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int in_bpp)
static int _align_up(int n, int a)
static int _default_process_tiling_ptp(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int in_bpp)
static void _print_roi(const dt_iop_roi_t *roi, const char *label)
int dt_tiling_piece_fits_host_memory(const size_t width, const size_t height, const unsigned bpp, const float factor, const size_t overhead)
static int _max(int a, int b)
static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int in_bpp)
static int _align_close(int n, int a)
static unsigned _lcm(unsigned a, unsigned b)
static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int in_bpp)
static int _min(int a, int b)
int default_process_tiling_cl(struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const int in_bpp)
static int _align_down(int n, int a)
static int _maximum_number_tiles()
static unsigned _gcd(unsigned a, unsigned b)