summaryrefslogtreecommitdiff
path: root/include/gras/block_config.hpp
blob: c026cba89b5c3bf5eea2d111c53e79f7322631e6 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.

#ifndef INCLUDED_GRAS_BLOCK_CONFIG_HPP
#define INCLUDED_GRAS_BLOCK_CONFIG_HPP

#include <gras/gras.hpp>
#include <cstddef>

namespace gras
{

//! Configuration parameters for a block
struct GRAS_API GlobalBlockConfig
{
    GlobalBlockConfig(void);

    /*!
     * Constrain the maximum number of items that
     * work can be called with for all output ports.
     *
     * Default = 0 aka disabled.
     */
    size_t maximum_output_items;

    /*!
     * Set the global memory node affinity.
     * Blocks that have not been explicitly set,
     * will take on this new buffer_affinity.
     *
     * This param affects how buffers are allocated.
     * By default memory is allocated by malloc.
     * When the affinity is set, virtual memory
     * will be locked to a physical CPU/memory node.
     *
     * Default = -1 aka no affinity.
     */
    long buffer_affinity;

    /*!
     * True if the work call should be interruptible by stop().
     * Some work implementations block with the expectation of
     * getting a boost thread interrupt in a blocking call.
     * If this is the case, this parameter should be set true.
     * By default, work implementations are not interruptible.
     *
     * Default = false.
     */
    bool interruptible_work;
};

//! Configuration parameters for an input port
struct GRAS_API InputPortConfig
{
    InputPortConfig(void);

    //! The size of an item in bytes
    size_t item_size;

    /*!
     * Set an input reserve requirement such that work is called
     * with an input buffer at least reserve items in size.
     *
     * Default = 1.
     */
    size_t reserve_items;

    /*!
     * Constrain the input buffer allocation size:
     * The scheduler may accumulate multiple buffers
     * into a single larger buffer under failure conditions.
     * The maximum size of this accumulated buffer
     * is constrained by this maximum_items setting.
     *
     * Default = 0 aka disabled.
     */
    size_t maximum_items;

    /*!
     * Set buffer inlining for this port config.
     * Inlining means that the input buffer can be used as an output buffer.
     * The goal is to make better use of cache and memory bandwidth.
     *
     * By default, inlining is disabled on all input ports.
     * The user should enable inlining on an input port
     * when it is understood that the work function will read
     * before writting to a particular section of the buffer.
     *
     * The scheduler will inline a buffer when
     *  * inlining is enabled on the particular input port
     *  * block holds the only buffer reference aka unique
     *  * the input buffer has the same affinity as the block
     *  * the input port has a buffer look-ahead of 0
     *
     * Default = false.
     */
    bool inline_buffer;

    /*!
     * Preload the input queue with num preload items.
     * All items preloaded into the buffer will be 0.
     * This is used to implement zero-padding for
     * things like sliding dot products/FIR filters.
     *
     *  - Increasing the preload at runtime will
     * inject more items into the input queue.
     *  - Decreasing the preload at runtime will
     * consume random items from the input queue.
     *
     * Default = 0.
     */
    size_t preload_items;

    /*!
     * Force this block done when input port is done.
     * When the upstream feeding this port declares done,
     * this block will mark done once upstream notifies.
     * The primary usage is to modify the done logic
     * for the purposes of unit test confiruability.
     *
     * If the force done option is false, the block will
     * not mark done when this port's upstream is done.
     * However, this block will mark done when all
     * input ports are done, reguardless of this setting.
     *
     * Default = true.
     */
    bool force_done;
};

//! Configuration parameters for an output port
struct GRAS_API OutputPortConfig
{
    OutputPortConfig(void);

    //! The size of an item in bytes
    size_t item_size;

    /*!
     * Set an output reserve requirement such that work is called
     * with an output buffer at least reserve items in size.
     *
     * Default = 1.
     */
    size_t reserve_items;

    /*!
     * Constrain the output buffer allocation size:
     * The user might set a small maximum items
     * to reduce the amount of buffered items
     * waiting for processing in downstream queues.
     *
     * Default = 0 aka disabled.
     */
    size_t maximum_items;
};

} //namespace gras

#endif /*INCLUDED_GRAS_BLOCK_CONFIG_HPP*/