source: icGREP/icgrep-devel/icgrep/kernels/attributes.h @ 5706

Last change on this file since 5706 was 5706, checked in by nmedfort, 20 months ago

First stage of MultiBlockKernel? and pipeline restructuring

File size: 5.3 KB
Line 
1#ifndef ATTRIBUTES_H
2#define ATTRIBUTES_H
3
4namespace kernel {
5
6struct Attribute {
7
8    friend struct Binding;
9
10    enum class KindId {
11
12        /** INPUT STREAM ATTRIBUTES **/
13
14        BlockSize,
15
16        // A BlockSize(K) attribute, where K=2^k for some value of k>=4 declares
17        // that the layout of stream data items within the corresponding input
18        // or output buffer is arranged in blocks of K items each.   In each
19        // block, the data buffer contains K items of the first stream in the
20        // set, followed by K items of the next stream in the set and so on,
21        // up to and including K items of the last stream in the set.
22
23        // (Note: this replaces the concept of swizzling and anticipates that
24        // the pipeline will take on the role of automatically inserting the
25        // swizzling code necessary).
26
27        LookAhead,
28
29        // A LookAhead(n) attribute on an input stream set S declares that the kernel
30        // looks ahead n positions in the input stream.   That is,
31        // processing of item S[i, j] may be defined in terms of S[i, j+n].
32
33        // Guarantee required: the pipeline compiler must ensure that, when
34        // the kernel is called with an available item count of N for the
35        // input stream, that the corresponding input data buffer has
36        // valid items in the buffer up to and including position N+n,
37        // and that the blocks containing the items from N-1 through N+n are
38        // linearly contiguous.  When the final doMultiBlock call is made,
39        // the pipeline compiler must ensure that the n items at lookahead
40        // positions are zero-initialized.
41
42        // (Note: this guarantee anticipates using a single buffer pointer
43        // for both normal stream access and lookahead access.   This avoids
44        // the cost of extra parameters per doMultiBlock call, but requires
45        // that the corresponding circular buffer have a "lookahead extension area"
46        // that holds a copy of the data at the physical start of buffer).
47
48        LookBehind,
49
50        // A LookBehind(n) attribute on an input stream S declares that the kernel
51        // requires access to input items up to n positions prior to the current
52        // processed item position.
53
54        // (Notes: this may allow more efficient advances within n (without saving state).
55        // However, a lookbehind extension area prior to the normal buffer base address
56        // is necessary, which must be initially zero-filled.)
57
58        // A LookBehind(n) attribute on an output stream S declares that the kernel
59        // requires access to up to n previously generated output items.
60        // (Example: lz4d lookbehind(65536)).
61
62        Principle,
63
64        // One input stream can be declared as the principle input buffer for a kernel.
65        // If a kernel has a principle input stream, when processing the final stride,
66        // a MultiBlockKernel assumes the item count of the principle is the correct
67        // one and zero extends / truncates all other input streams to match it.
68
69        /** OUTPUT STREAM ATTRIBUTES **/
70
71        Add,
72
73        // An Add(K) attribute states that K bits will be added to this stream after
74        // processing the final block.
75
76        RoundUpTo,
77
78        // A RoundUpTo(k) attribute indicates the final item count of this stream will
79        // be rounded up to the nearest multiple of k
80
81        /** KERNEL ATTRIBUTES **/
82
83        SelectMinimumInputLength,
84
85        // If a kernel has multiple input streams and their final item count differs,
86        // a MultiBlock kernel will select the *minimum* input item count as it's
87        // principle item length and truncate the streams to fit
88
89        // NOTE: this is the default if a kernel does not have SelectMaximumInputLength
90        // set and no PrincipleInputStream was declared.
91
92        SelectMaximumInputLength,
93
94        // If a kernel has multiple input streams and their final item count differs,
95        // a MultiBlock kernel will select the *maximum* input item count as it's
96        // principle item length and zero-extend the streams accordingly.
97
98    };
99
100    bool isAdd() const {
101        return mKind == KindId::Add;
102    }
103
104    bool isPrinciple() const {
105        return mKind == KindId::Principle;
106    }
107
108    bool isRoundUpTo() const {
109        return mKind == KindId::RoundUpTo;
110    }
111
112    unsigned getAmount() const {
113        return mK;
114    }
115
116    bool operator == (const Attribute & other) const {
117        return mKind == other.mKind && mK == other.mK;
118    }
119
120    bool operator != (const Attribute & other) const {
121        return !(*this == other);
122    }
123
124protected:
125
126    KindId getKind() const {
127        return mKind;
128    }
129
130    friend Attribute Add1();
131    friend Attribute Principle();
132    friend Attribute RoundUpTo(const unsigned);
133    friend Attribute LookBehind(const unsigned);
134
135    Attribute(const KindId kind, const unsigned k) : mKind(kind), mK(k) { }
136
137private:
138
139    const KindId    mKind;
140    const unsigned  mK;
141
142};
143
144inline Attribute Add1() {
145    return Attribute(Attribute::KindId::Add, 1);
146}
147
148inline Attribute RoundUpTo(const unsigned k) {
149    return Attribute(Attribute::KindId::RoundUpTo, k);
150}
151
152inline Attribute Principle() {
153    return Attribute(Attribute::KindId::Principle, 0);
154}
155
156inline Attribute LookBehind(const unsigned k) {
157    return Attribute(Attribute::KindId::LookBehind, k);
158}
159
160
161}
162
163
164#endif // ATTRIBUTES_H
Note: See TracBrowser for help on using the repository browser.