AKTIVE

iveccache.h at trunk
Login

iveccache.h at trunk

File runtime/iveccache.h artifact b179f276d7 on branch trunk


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
/* -*- c -*-
 * - - -- --- ----- -------- -------------
 *
 * -- Vector cache utility functions, independent vectors.
 *
 *    Management of a local vector cache on top of the global cache.
 *    The global cache handles evictions, in cooperation with this user.
 *
 *    A vector cache stores a fixed number of vectors of doubles, all the
 *    same size, i.e. same number of elements.
 *
 *    Vector was chosen as generic name, applying to both image rows, and columns.
 *
 *    Access to the vectorcache from multiple concurrent threads is safe.
 *
 *    So far this sounds the same as the facilities of `veccache.[ch]`.
 *
 *    The difference is in a low-level assumption.
 *
 *    VecCache assumes that the vectors to cache are stored sequentially in
 *    the input, and that getting the vector at a higher index requires
 *    reading the vectors at the lower indices at least once.
 *
 *    IVecCache here replaces that with the assumption that vectors at any
 *    index can be retrieved independent of each other from the input,
 *    i.e. that the input supports random access at least at vector level.
 *
 *    This changes the interface between cache and input somewhat (See filler).
 *
 * EXAMPLE USER
 *
 *      `op column histogram` caches the calculated histograms to avoid
 *      recalculation in the face of row scans.
 *
 * API
 *
 * - new, release
 *
 *   Create and destroy vector caches. The cache has space for "nvecs" vectors
 *   of "nelems" double elements each. This cannot change over the lifetime of
 *   the cache.
 *
 * - get
 *
 *   Get the indexed vector.
 *
 *   Asking for an undefined vector causes the cache to fill the vector from
 *   the input, using the provided "filler" function vector and its "context".
 *   The vector is locked during this specific action.
 *
 *   Once the vector is defined no locking is performed any more. The data is
 *   considered immutable and read-only.
 *
 *   The "filler" is given the index of vector to fill.
 */
#ifndef AKTIVE_IVECTORCACHE_H
#define AKTIVE_IVECTORCACHE_H

/*
 * - - -- --- ----- -------- -------------
 */

#include <tclpre9compat.h>
#include <base.h>
#include <geometry.h>

/*
 * - - -- --- ----- -------- -------------
 */

typedef struct aktive_iveccache_ *aktive_iveccache;

// !xref-mark aktive_iveccache_fill
typedef void (*aktive_iveccache_fill)(void* context, aktive_uint index, double* dst);

// !xref-mark aktive_ivcache_context*
typedef struct aktive_ivcache_context {
    aktive_uint         z;       // requested band
    aktive_uint         stride;  // delta between band groups
    aktive_uint         size;    // number of values in the band
    aktive_rectangle*   request; // full request for input
    aktive_region       src;     // input region to pull from
    void*               client;  // function-specific context data
    aktive_region       caller;  // caller region making the request, to pass to fetch
    aktive_uint*        slot;    // and the relevant result slot
} aktive_ivcache_context;
// !xref-mark /end

/*
 * - - -- --- ----- -------- -------------
 */

extern aktive_iveccache aktive_iveccache_new    (aktive_uint nvecs,
						 aktive_uint nelems);
extern void            aktive_iveccache_release (aktive_iveccache cache);
extern double*         aktive_iveccache_get     (aktive_iveccache      cache,
						 aktive_uint           index,
						 aktive_iveccache_fill filler,
						 void*                 context);

/*
 * = = == === ===== ======== ============= =====================
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
#endif /* AKTIVE_IVECTORCACHE_H */