Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_pipe_cache_policy.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Aurélien PIERRE.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
29
31
32#include <stdarg.h>
33#include <stddef.h>
34// cmocka.h declares `extern jmp_buf global_expect_assert_env' at file scope without including
35// <setjmp.h> itself. Same suppression as test_metadata_notify.c, and for the same reason.
36#include <setjmp.h> // NOLINT(misc-include-cleaner)
37#include <stdint.h>
38#include <cmocka.h>
39
40#ifdef _WIN32
41#include "win/main_wrapper.h"
42#endif
43
46{
48 in.supports_opencl = TRUE;
49 return in;
50}
51
54{
55 (void)state;
57 in.supports_opencl = FALSE;
58
59 gboolean upstream = FALSE;
60 const gboolean own = dt_dev_pipe_cache_policy_decide(&in, FALSE, &upstream);
61
62 // It requires nothing of its OWN output -- nobody downstream asked for it ...
63 assert_false(own);
64 // ... but the node before it must publish to host, because this one reads on the CPU.
65 assert_true(upstream);
66}
67
69{
70 (void)state;
72
73 gboolean upstream = TRUE;
74 const gboolean own = dt_dev_pipe_cache_policy_decide(&in, FALSE, &upstream);
75
76 assert_false(own);
77 assert_false(upstream);
78}
79
98{
99 (void)state;
101
102 gboolean upstream = TRUE;
103 const gboolean own = dt_dev_pipe_cache_policy_decide(&in, TRUE, &upstream);
104
105 // The consumer's requirement still reaches THIS node's output: that consumer reads it.
106 assert_true(own);
107 // ... and stops there. The node before this one publishes to this node, which is on GPU.
108 assert_false(upstream);
109}
110
117{
118 (void)state;
119 dt_dev_pipe_cache_policy_inputs_t in = { 0 }; // supports_opencl = FALSE
120
121 gboolean upstream = FALSE;
123 assert_true(upstream);
124}
125
135{
136 (void)state;
138
139 gboolean upstream = TRUE;
140 assert_false(dt_dev_pipe_cache_policy_decide(&in, FALSE, &upstream));
141 assert_false(upstream);
142}
143
146{
147 (void)state;
148 const size_t offsets[] = {
149 offsetof(dt_dev_pipe_cache_policy_inputs_t, active_in_gui),
150 offsetof(dt_dev_pipe_cache_policy_inputs_t, module_hist_on),
151 offsetof(dt_dev_pipe_cache_policy_inputs_t, global_hist_input_on),
152 offsetof(dt_dev_pipe_cache_policy_inputs_t, has_autoset),
153 };
154
155 for(size_t i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++)
156 {
158 *(gboolean *)((char *)&in + offsets[i]) = TRUE;
159
160 gboolean upstream = FALSE;
162 assert_true(upstream);
163 }
164}
165
168{
169 (void)state;
170 const size_t offsets[] = {
171 offsetof(dt_dev_pipe_cache_policy_inputs_t, authored_cache),
172 offsetof(dt_dev_pipe_cache_policy_inputs_t, user_requested_cache),
173 offsetof(dt_dev_pipe_cache_policy_inputs_t, color_picker_on),
174 offsetof(dt_dev_pipe_cache_policy_inputs_t, global_hist_output_on),
175 };
176
177 for(size_t i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++)
178 {
180 *(gboolean *)((char *)&in + offsets[i]) = TRUE;
181
182 gboolean upstream = FALSE;
183 assert_true(dt_dev_pipe_cache_policy_decide(&in, FALSE, &upstream));
184 // None of these four says anything about what the node BEFORE this one must do.
185 assert_false(upstream);
186 }
187}
188
191{
192 (void)state;
194 in.color_picker_on = TRUE;
195
196 assert_true(dt_dev_pipe_cache_policy_decide(&in, FALSE, NULL));
197}
198
210static void _walk(const dt_dev_pipe_cache_policy_inputs_t *nodes, gboolean *out, const int count,
211 const gboolean display_reads_the_last_output)
212{
213 gboolean carried = display_reads_the_last_output;
214 for(int i = count - 1; i >= 0; i--)
215 out[i] = dt_dev_pipe_cache_policy_decide(&nodes[i], carried, &carried);
216}
217
223{
224 (void)state;
226 for(int i = 0; i < 4; i++) nodes[i] = _gpu_node_with_no_needs();
227
228 gboolean cached[4] = { FALSE };
229 _walk(nodes, cached, 4, TRUE);
230
231 assert_true(cached[3]); // the displayed output
232 assert_false(cached[2]); // ... and nothing else. Relayed, these were all TRUE.
233 assert_false(cached[1]);
234 assert_false(cached[0]);
235}
236
243{
244 (void)state;
246 for(int i = 0; i < 4; i++) nodes[i] = _gpu_node_with_no_needs();
247 nodes[2].supports_opencl = FALSE; // CPU-only: reads its input from RAM
248
249 gboolean cached[4] = { FALSE };
250 _walk(nodes, cached, 4, TRUE);
251
252 assert_true(cached[3]); // displayed
253 /* The CPU node's OWN flag is FALSE, and that is correct rather than an oversight: the flag
254 * asks for a device->host COPY of a module's output, and a module that ran on the CPU has
255 * already written its output in host memory. There is nothing to copy. (Asserting TRUE here
256 * is what this test caught on its first run.) */
257 assert_false(cached[2]);
258 assert_true(cached[1]); // its PRODUCER must publish -- this is the one that matters
259 assert_false(cached[0]); // and the requirement stops there
260}
261
264{
265 (void)state;
267 for(int i = 0; i < 3; i++) nodes[i] = _gpu_node_with_no_needs();
268
269 gboolean cached[3] = { FALSE };
270 _walk(nodes, cached, 3, FALSE);
271
272 for(int i = 0; i < 3; i++) assert_false(cached[i]);
273}
274
275int main(int argc, char *argv[])
276{
277 const struct CMUnitTest tests[] = {
284 cmocka_unit_test(_each_own_output_reason_raises_own),
285 cmocka_unit_test(_null_upstream_pointer_is_allowed),
289 };
290
291 return cmocka_run_group_tests(tests, NULL, NULL);
292}
293
294// clang-format off
295// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
296// vim: shiftwidth=2 expandtab tabstop=2 cindent
297// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
298// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
const dt_colormatrix_t dt_aligned_pixel_t out
dt_iop_roi_t in
Definition geometry.h:117
Whether one pipeline node must keep a host-RAM copy of its output.
static gboolean dt_dev_pipe_cache_policy_decide(const dt_dev_pipe_cache_policy_inputs_t *in, const gboolean inherited_requirement, gboolean *upstream_requirement)
Decide one node's host-cache requirement, walking the pipe from the end backwards.
int main()
Definition prova.c:47
const float uint32_t state[4]
Everything the decision depends on, named.
static void _gpu_node_requires_nothing_on_its_own(void **state)
static void _each_own_output_reason_raises_own(void **state)
static void _a_cpu_node_publishes_its_producer_and_no_further(void **state)
static void _only_the_displayed_output_is_cached_in_a_gpu_chain(void **state)
static void _each_own_input_reason_raises_upstream(void **state)
static void _a_cpu_node_still_makes_its_producer_publish(void **state)
static dt_dev_pipe_cache_policy_inputs_t _gpu_node_with_no_needs(void)
static void _a_pure_gpu_chain_nobody_reads_caches_nothing(void **state)
static void _a_gpu_node_does_not_relay_its_consumers_requirement(void **state)
static void _null_upstream_pointer_is_allowed(void **state)
static void _cpu_only_node_needs_its_input_on_host(void **state)
static void _a_gpu_node_nothing_reads_from_ram_caches_nothing(void **state)
static void _walk(const dt_dev_pipe_cache_policy_inputs_t *nodes, gboolean *out, const int count, const gboolean display_reads_the_last_output)
Walk a chain of nodes the way _seal_opencl_cache_policy() does, last to first.