30#ifndef DT_CACHES_PIXELPIPE_CACHE_H
31#define DT_CACHES_PIXELPIPE_CACHE_H
52#define DT_PIXELPIPE_CACHE_HASH_INVALID ((uint64_t)-1)
94 const gboolean verbose_detail);
285 const char *
name,
const int id,
const gboolean alloc,
334 const size_t size,
const char *
name,
const int id,
335 const gboolean alloc,
const gboolean allow_rekey_reuse,
401 int preferred_devid,
void **
data);
428 gboolean *out_reused);
488 gboolean *out_reused,
void *keep);
503 const char *message,
void *keep);
518 void *host_ptr, gboolean cache_device);
554 const char *message);
580 float *input,
void **cl_mem_input,
744 void **cl_mem_output);
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
static const dt_dev_pixelpipe_t * pipe
dt_mipmap_buffer_dsc_flags flags
gboolean dt_dev_pixelpipe_cache_flush_host_pinned_image(void *host_ptr, struct dt_pixel_cache_entry_t *entry_hint, int devid)
Drop cached pinned OpenCL images associated with a given host buffer.
void * dt_pixel_cache_entry_get_buffer(struct dt_pixel_cache_entry_t *entry)
The host buffer of a cache entry, whatever hash its content describes.
void dt_dev_pixelpipe_cache_ref_count_entry(gboolean lock, struct dt_pixel_cache_entry_t *entry)
Take or release one reference on a cache line. A referenced line is never evicted,...
void * dt_dev_pixelpipe_cache_get_cl_buffer(int devid, void *host_ptr, const struct dt_iop_roi_t *roi, size_t bpp, struct dt_iop_module_t *module, const char *message, struct dt_pixel_cache_entry_t *entry, gboolean *out_reused, void *keep)
Allocate or reuse an OpenCL buffer for one cache entry payload.
GArray * dt_dev_pixelpipe_cache_get_entries_stats(void)
int dt_dev_pixelpipe_cache_sync_cl_buffer(int devid, void *host_ptr, void *cl_mem_buffer, const struct dt_iop_roi_t *roi, int cl_mode, size_t bpp, struct dt_iop_module_t *module, const char *message)
Synchronize between host memory and a pinned OpenCL image.
int dt_dev_pixelpipe_cache_invalidate_hashes(const uint64_t *hashes, const size_t count)
Invalidate cache lines matching an explicit list of hashes.
const char * dt_pixelpipe_cache_set_current_image(const char *image)
Set the image the current module runs on, for the message that reports a refused allocation (thread-l...
size_t dt_dev_pixelpipe_cache_get_available(void)
gboolean dt_dev_pixelpipe_cache_peek(const uint64_t hash, void **data, struct dt_pixel_cache_entry_t **entry, const int preferred_devid, void **cl_mem_output)
Non-owning lookup of an existing cache line.
void * dt_dev_pixelpipe_cache_borrow_cl_payload(struct dt_pixel_cache_entry_t *entry, int devid, int width, int height, int bpp)
Borrow a cached OpenCL payload attached to a cache entry.
void dt_dev_pixelpipe_cache_cleanup(void)
Release everything dt_dev_pixelpipe_cache_init() created, the instance included. Only after a success...
void dt_dev_pixelpipe_cache_set_alert_handler(dt_pixelpipe_cache_alert_handler_t alert)
Install the alert handler. The GUI installs it, once it exists, apart from the others: without a GUI ...
void * dt_pixelpipe_cache_alloc_align_cache_impl(size_t size, int id, const char *name)
Allocate aligned memory tracked by the pixelpipe cache. This allows LRU cache entries to be evicted i...
struct dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry_by_data(void *data)
void dt_dev_pixelpipe_cache_flush_clmem(const int devid)
Release cached OpenCL buffers for a single device.
size_t dt_pixel_cache_entry_get_size(const struct dt_pixel_cache_entry_t *entry)
Peek the size (in bytes) reserved for the host buffer of a cache entry.
int dt_dev_pixel_pipe_cache_remove_lru(void)
void(* dt_pixelpipe_cache_warn_handler_t)(const char *message)
Tell the user something that is fine to miss: the cache went over its budget, but the allocation went...
void dt_dev_pixelpipe_cache_wrlock_entry(gboolean lock, struct dt_pixel_cache_entry_t *entry)
Lock or release the write lock on the entry.
void dt_dev_pixelpipe_cache_put_pinned_image(void *host_ptr, struct dt_pixel_cache_entry_t *entry_hint, void **mem)
Release or cache a pinned OpenCL image acquired with dt_dev_pixelpipe_cache_get_pinned_image().
size_t dt_dev_pixelpipe_cache_get_max_memory(void)
void(* dt_pixelpipe_cache_alert_handler_t)(const char *message, const char *item)
Tell the user something that must not go unseen: what it says stays true after a toast would have gon...
int dt_dev_pixelpipe_cache_prepare_cl_input(struct dt_dev_pixelpipe_t *pipe, struct dt_iop_module_t *module, float *input, void **cl_mem_input, const struct dt_iop_roi_t *roi_in, size_t in_bpp, struct dt_pixel_cache_entry_t *input_entry, struct dt_pixel_cache_entry_t **locked_input_entry, void *keep)
Prepare the OpenCL input image corresponding to one cache-backed module input.
float * dt_dev_pixelpipe_cache_restore_cl_buffer(struct dt_dev_pixelpipe_t *pipe, float *input, void *cl_mem_input, const struct dt_iop_roi_t *roi_in, struct dt_iop_module_t *module, size_t in_bpp, struct dt_pixel_cache_entry_t *input_entry, const char *message)
Resynchronize one OpenCL input payload back into its cache-backed host buffer.
void dt_dev_pixelpipe_cache_flush_clmem_for_pipe(const int devid)
Like dt_dev_pixelpipe_cache_flush_clmem(), for callers that do not hold the device lock (dt_opencl_re...
void dt_dev_pixelpipe_cache_flush_entry_clmem(struct dt_pixel_cache_entry_t *entry)
Flush all reusable OpenCL payloads cached on one cache entry.
struct dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_ref_entry_for_host_ptr(void *host_ptr)
Resolve and retain the cache entry owning a host pointer.
void dt_dev_pixelpipe_cache_flush(const int id)
Remove cache lines matching id. Entries locked in read/write or having reference count greater than 0...
void dt_dev_pixelpipe_cache_print(void)
size_t dt_pixelpipe_cache_get_largest_free_run(void)
void dt_dev_pixelpipe_cache_unref_entry(struct dt_pixel_cache_entry_t *entry)
Release one reference held on entry, by POINTER.
void * dt_pixel_cache_entry_get_data(struct dt_pixel_cache_entry_t *entry)
Peek the host pixels a cache entry holds for its current hash, without allocating.
void * dt_dev_pixelpipe_cache_get_pinned_image(void *host_ptr, struct dt_pixel_cache_entry_t *entry_hint, int devid, int width, int height, int bpp, int flags, gboolean *out_reused)
Acquire a pinned OpenCL image for a host buffer tracked by the pixelpipe cache.
gboolean dt_dev_pixelpipe_cache_ref_host_entry_by_hash(const uint64_t hash, void **data, struct dt_pixel_cache_entry_t **entry)
Resolve and retain an existing cacheline that already holds HOST pixels.
gboolean dt_dev_pixelpipe_cache_ref_entry_by_hash(const uint64_t hash, void **data, struct dt_pixel_cache_entry_t **entry)
Resolve and retain an existing cache entry by hash.
void dt_dev_pixelpipe_cache_release_cl_buffer(void **cl_mem_buffer, struct dt_pixel_cache_entry_t *entry, void *host_ptr, gboolean cache_device)
Release or cache an OpenCL image associated with one cache entry.
void dt_dev_pixelpipe_cache_get_usage(size_t *current, size_t *max)
void(* dt_pixelpipe_cache_ready_handler_t)(uint64_t hash, uint64_t producer_node_key)
A cacheline finished and is readable.
void dt_dev_pixelpipe_cache_rdlock_entry(gboolean lock, struct dt_pixel_cache_entry_t *entry)
Lock or release the read lock on the entry.
void * dt_pixel_cache_alloc(struct dt_pixel_cache_entry_t *entry)
Actually allocate the memory buffer attached to the cache entry once you create it with dt_dev_pixelp...
void dt_dev_pixelpipe_cache_return_cl_payload(struct dt_pixel_cache_entry_t *entry, void *mem)
Return a borrowed cached OpenCL payload to its cache entry.
gboolean dt_dev_pixelpipe_cache_init(size_t max_memory, const gboolean verbose, const gboolean verbose_detail)
Reserve the cache's arena and start it.
struct dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry(const uint64_t hash)
Get an internal reference to the cache entry matching hash. If you are going to access this entry mor...
int dt_dev_pixelpipe_cache_rekey(const uint64_t old_hash, const uint64_t new_hash, struct dt_pixel_cache_entry_t *entry)
Change the hash/key of an existing cache line in place, without freeing, reallocating or invalidating...
void dt_dev_pixelpipe_cache_flag_host_written(struct dt_pixel_cache_entry_t *entry)
Record that the host buffer of entry now holds the pixels of its current hash.
void dt_dev_pixelpipe_cache_unref_hash(const uint64_t hash)
Find the entry matching hash, and decrease its ref_count if found.
void * dt_dev_pixelpipe_cache_alloc_cl_device_buffer(int devid, const struct dt_iop_roi_t *roi, size_t bpp, const struct dt_iop_module_t *module, const char *message, void *keep)
Allocate a temporary device-only OpenCL image, retrying once after cache flush.
void dt_pixelpipe_cache_free_align_cache(void **mem, const char *message)
Free aligned memory allocated with dt_pixelpipe_cache_alloc_align_cache.
gboolean dt_dev_pixelpipe_cache_restore_host_payload(struct dt_pixel_cache_entry_t *entry, int preferred_devid, void **data)
Materialize a host payload for a live cache entry from its cached device payload.
void dt_dev_pixelpipe_cache_set_handlers(dt_pixelpipe_cache_warn_handler_t warn, dt_pixelpipe_cache_ready_handler_t ready, const dt_pixelpipe_cache_observer_t *observer)
Install the handlers. Call once, from the orchestrator, before any pipe runs.
dt_dev_pixelpipe_cache_writable_status_t dt_dev_pixelpipe_cache_get_writable(const uint64_t hash, const size_t size, const char *name, const int id, const gboolean alloc, const gboolean allow_rekey_reuse, const struct dt_pixel_cache_entry_t *reuse_hint, const struct dt_pixel_cache_entry_t *reuse_hint_prev, void **data, struct dt_pixel_cache_entry_t **entry)
Acquire a writable cache line for module output.
void dt_dev_pixelpipe_cache_flag_auto_destroy(struct dt_pixel_cache_entry_t *entry)
Flag a cache line as disposable (auto_destroy), for short-lived lines nothing will need again: the re...
int dt_dev_pixelpipe_cache_get(const uint64_t hash, const size_t size, const char *name, const int id, const gboolean alloc, void **data, struct dt_pixel_cache_entry_t **entry)
Get a cache line from the cache.
dt_dev_pixelpipe_cache_writable_status_t
@ DT_DEV_PIXELPIPE_CACHE_WRITABLE_REKEYED
@ DT_DEV_PIXELPIPE_CACHE_WRITABLE_ERROR
@ DT_DEV_PIXELPIPE_CACHE_WRITABLE_CREATED
@ DT_DEV_PIXELPIPE_CACHE_WRITABLE_EXACT_HIT
const char * dt_pixelpipe_cache_set_current_module(const char *module)
Set the current module name for cache diagnostics (thread-local).
uint32_t dt_pixelpipe_cache_get_alloc_refusals(void)
Count the allocations the cache refused to the calling thread for lack of memory (thread-local).
gboolean dt_dev_pixelpipe_cache_is_ready(void)
Has the pixelpipe cache been initialised? Callers that run before dt_dev_pixelpipe_cache_init() succe...
unsigned __int64 uint64_t
Region of interest passed through the pixelpipe.
dt_dev_pixelpipe_cache_t * cache
dt_pthread_mutex_t cl_mem_lock
uint64_t producer_node_key
dt_pixel_cache_stats_device_t * devices
The supervisor's view of the cache. All four may be NULL; active gates the other three so the cache p...
void(* cacheline_delete)(uint64_t hash, size_t size, int owner_pipe_id, const char *name)
void(* cacheline_read)(uint64_t hash, size_t size)
void(* rekey)(uint64_t old_hash, uint64_t new_hash)