Skip to content

Commit ca43a67

Browse files
authored
Merge pull request #19515 from jenshannoschwalm/safe_lowmem_systems
Safe lowmem systems
2 parents 27e1b95 + 88dd5bc commit ca43a67

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

src/common/darktable.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static size_t _get_mipmap_size()
546546
dt_sys_resources_t *res = &darktable.dtresources;
547547
const int level = res->level;
548548
if(level < 0)
549-
return res->refresource[4*(-level-1) + 2] * 1024lu * 1024lu;
549+
return res->refresource[4*(-level-1) + 2] * DT_MEGA;
550550
const int fraction = res->fractions[4*level + 2];
551551
return res->total_memory / 1024lu * fraction;
552552
}
@@ -1169,6 +1169,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
11691169
CHKSIGDBG(DT_SIGNAL_CONTROL_TOAST_REDRAW);
11701170
CHKSIGDBG(DT_SIGNAL_CONTROL_PICKERDATA_READY);
11711171
CHKSIGDBG(DT_SIGNAL_METADATA_UPDATE);
1172+
CHKSIGDBG(DT_SIGNAL_PRESET_APPLIED);
11721173
else
11731174
{
11741175
dt_print(DT_DEBUG_SIGNAL,
@@ -1694,7 +1695,9 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
16941695
dt_sys_resources_t *res = &darktable.dtresources;
16951696
res->fractions = fractions;
16961697
res->refresource = ref_resources;
1697-
res->total_memory = _get_total_memory() * 1024lu;
1698+
size_t total_mb = _get_total_memory() / 1024lu;
1699+
if(total_mb < 8192) total_mb -= 1024;
1700+
res->total_memory = total_mb * DT_MEGA;
16981701

16991702
char *config_info = calloc(1, DT_PERF_INFOSIZE);
17001703
if(last_configure_version != DT_CURRENT_PERFORMANCE_CONFIGURE_VERSION
@@ -1706,7 +1709,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
17061709
dt_get_sysresource_level();
17071710
res->mipmap_memory = _get_mipmap_size();
17081711
dt_print(DT_DEBUG_MEMORY | DT_DEBUG_DEV,
1709-
" mipmap cache: %luMB", res->mipmap_memory / 1024lu / 1024lu);
1712+
" mipmap cache: %luMB", res->mipmap_memory / DT_MEGA);
17101713
// initialize collection query
17111714
darktable.collection = dt_collection_new(NULL);
17121715

@@ -2007,11 +2010,11 @@ void dt_get_sysresource_level()
20072010
dt_print(DT_DEBUG_MEMORY | DT_DEBUG_DEV,
20082011
"[dt_get_sysresource_level] switched to `%s'", config);
20092012
dt_print(DT_DEBUG_MEMORY | DT_DEBUG_DEV,
2010-
" total mem: %luMB", res->total_memory / 1024lu / 1024lu);
2013+
" total mem: %luMB", res->total_memory / DT_MEGA);
20112014
dt_print(DT_DEBUG_MEMORY | DT_DEBUG_DEV,
2012-
" available mem: %luMB", dt_get_available_mem() / 1024lu / 1024lu);
2015+
" available mem: %luMB", dt_get_available_mem() / DT_MEGA);
20132016
dt_print(DT_DEBUG_MEMORY | DT_DEBUG_DEV,
2014-
" singlebuff: %luMB", dt_get_singlebuffer_mem() / 1024lu / 1024lu);
2017+
" singlebuff: %luMB", dt_get_singlebuffer_mem() / DT_MEGA);
20152018
}
20162019
}
20172020

@@ -2340,27 +2343,27 @@ size_t dt_get_available_mem()
23402343
dt_sys_resources_t *res = &darktable.dtresources;
23412344
const int level = res->level;
23422345
if(level < 0)
2343-
return res->refresource[4*(-level-1)] * 1024lu * 1024lu;
2346+
return res->refresource[4*(-level-1)] * DT_MEGA;
23442347

23452348
const int fraction = res->fractions[4*level];
2346-
return MAX(512lu * 1024lu * 1024lu, res->total_memory / 1024lu * fraction);
2349+
return MAX(512lu * DT_MEGA, res->total_memory / 1024lu * fraction);
23472350
}
23482351

23492352
size_t dt_get_singlebuffer_mem()
23502353
{
23512354
dt_sys_resources_t *res = &darktable.dtresources;
23522355
const int level = res->level;
23532356
if(level < 0)
2354-
return res->refresource[4*(-level-1) + 1] * 1024lu * 1024lu;
2357+
return res->refresource[4*(-level-1) + 1] * DT_MEGA;
23552358

23562359
const int fraction = res->fractions[4*level + 1];
2357-
return MAX(2lu * 1024lu * 1024lu, res->total_memory / 1024lu * fraction);
2360+
return MAX(2lu * DT_MEGA, res->total_memory / 1024lu * fraction);
23582361
}
23592362

23602363
void dt_configure_runtime_performance(const int old, char *info)
23612364
{
23622365
const size_t threads = dt_get_num_procs();
2363-
const size_t mem = darktable.dtresources.total_memory / 1024lu / 1024lu;
2366+
const size_t mem = darktable.dtresources.total_memory / DT_MEGA;
23642367
const size_t bits = CHAR_BIT * sizeof(void *);
23652368
const gboolean sufficient = mem >= 4096 && threads >= 2;
23662369

src/common/math.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#define LUT_ELEM 512 // gamut LUT number of elements:
2727

28+
#define DT_MEGA 1048576lu
29+
2830
#define NORM_MIN 1.52587890625e-05f // norm can't be < to 2^(-16)
2931

3032
// select speed vs accuracy tradeoff

src/common/opencl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ static gboolean _opencl_device_init(dt_opencl_t *cl,
781781
(cl->dlocl->symbols->dt_clGetDeviceInfo)
782782
(devid, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong),
783783
&(cl->dev[dev].max_global_mem), NULL);
784-
if(cl->dev[dev].max_global_mem < (uint64_t)800ul * 1024ul * 1024ul)
784+
if(cl->dev[dev].max_global_mem < (uint64_t)800ul * DT_MEGA)
785785
{
786786
dt_print_nts(DT_DEBUG_OPENCL,
787787
" *** insufficient global memory (%" PRIu64 "MB) ***\n",
788-
cl->dev[dev].max_global_mem / 1024 / 1024);
788+
cl->dev[dev].max_global_mem / DT_MEGA);
789789
res = TRUE;
790790
cl->dev[dev].disabled |= TRUE;
791791
goto end;
@@ -807,10 +807,10 @@ static gboolean _opencl_device_init(dt_opencl_t *cl,
807807

808808
dt_print_nts(DT_DEBUG_OPENCL,
809809
" GLOBAL MEM SIZE: %.0f MB\n",
810-
(double)cl->dev[dev].max_global_mem / 1024.0 / 1024.0);
810+
(double)cl->dev[dev].max_global_mem / (double)DT_MEGA);
811811
dt_print_nts(DT_DEBUG_OPENCL,
812812
" MAX MEM ALLOC: %.0f MB\n",
813-
(double)cl->dev[dev].max_mem_alloc / 1024.0 / 1024.0);
813+
(double)cl->dev[dev].max_mem_alloc / (double)DT_MEGA);
814814
dt_print_nts(DT_DEBUG_OPENCL,
815815
" MAX IMAGE SIZE: %zd x %zd\n",
816816
cl->dev[dev].max_image_width, cl->dev[dev].max_image_height);
@@ -3575,16 +3575,16 @@ void dt_opencl_check_tuning(const int devid)
35753575

35763576
if(level < 0)
35773577
{
3578-
cl->dev[devid].used_available = res->refresource[4*(-level-1) + 3] * 1024lu * 1024lu;
3578+
cl->dev[devid].used_available = res->refresource[4*(-level-1) + 3] * DT_MEGA;
35793579
}
35803580
else
35813581
{
35823582
const size_t allmem = cl->dev[devid].max_global_mem;
3583-
const size_t lowmem = 256ul * 1024ul * 1024ul;
3584-
const size_t dhead = DT_OPENCL_DEFAULT_HEADROOM * 1024ul * 1024ul;
3583+
const size_t lowmem = 256ul * DT_MEGA;
3584+
const size_t dhead = DT_OPENCL_DEFAULT_HEADROOM * DT_MEGA;
35853585
if(cl->dev[devid].tunehead)
35863586
{
3587-
const size_t headroom = (cl->dev[devid].headroom ? 1024ul * 1024ul * cl->dev[devid].headroom : dhead)
3587+
const size_t headroom = (cl->dev[devid].headroom ? DT_MEGA * cl->dev[devid].headroom : dhead)
35883588
+ (cl->dev[devid].clmem_error ? dhead : 0);
35893589
cl->dev[devid].used_available = allmem > headroom ? allmem - headroom : lowmem;
35903590
}

src/develop/pixelpipe_hb.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ gboolean dt_dev_pixelpipe_init_cached(dt_dev_pixelpipe_t *pipe,
282282

283283
size_t dt_get_available_pipe_mem(const dt_dev_pixelpipe_t *pipe)
284284
{
285-
size_t allmem = dt_get_available_mem();
286-
return MAX(1lu * 1024lu * 1024lu,
287-
allmem / (pipe->type & DT_DEV_PIXELPIPE_THUMBNAIL ? 3 : 1));
285+
const size_t allmem = dt_get_available_mem();
286+
return MAX(DT_MEGA, allmem / (pipe->type & DT_DEV_PIXELPIPE_THUMBNAIL ? 3 : 1));
288287
}
289288

290289
static void get_output_format(dt_iop_module_t *module,
@@ -3056,7 +3055,7 @@ gboolean dt_dev_pixelpipe_process(dt_dev_pixelpipe_t *pipe,
30563055
pipe, NULL, pipe->devid, &roi, &roi, "ID=%i, %s %luMB%s%s",
30573056
pipe->image.id,
30583057
darktable.opencl->dev[pipe->devid].cname,
3059-
darktable.opencl->dev[pipe->devid].used_available / 1024lu / 1024lu,
3058+
darktable.opencl->dev[pipe->devid].used_available / DT_MEGA,
30603059
darktable.opencl->dev[pipe->devid].tunehead ? ", tuned" : "",
30613060
darktable.opencl->dev[pipe->devid].pinned_memory ? ", pinned": "");
30623061
else

src/iop/demosaic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ DT_MODULE_INTROSPECTION(6, dt_iop_demosaic_params_t)
5252
#define DT_DEMOSAIC_XTRANS 1024 // masks for non-Bayer demosaic ops
5353
#define DT_DEMOSAIC_DUAL 2048 // masks for dual demosaicing methods
5454
#define DT_REDUCESIZE_MIN 64
55-
#define DT_MEGA 1048576l
5655

5756
// these are highly depending on CPU architecture (cache size)
5857
#define DT_RCD_TILESIZE 112

0 commit comments

Comments
 (0)