linear filters in streamit
DESCRIPTION
Linear Filters in StreamIt. Andrew A. Lamb MIT Laboratory for Computer Science Computer Architecture Group 8/29/2002. Outline. Introduction Dataflow Analysis Hierarchal Matrix Combinations Performance Optimizations. Basic Idea. Filter A a=pop(); b=pop(); c=(a+b)/2 + 1; push(c);. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/1.jpg)
Linear Filters in StreamIt
Andrew A. LambMIT
Laboratory for Computer ScienceComputer Architecture Group
8/29/2002
![Page 2: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/2.jpg)
Outline
Introduction
Dataflow Analysis
Hierarchal Matrix Combinations
Performance Optimizations
![Page 3: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/3.jpg)
Basic Idea
Filter Aa=pop();
b=pop();
c=(a+b)/2 + 1;
push(c);
Matrix Mult. 1b
x y
y = xA + b
21
21A
![Page 4: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/4.jpg)
What is a Linear Filter? Generic filters calculate some
outputs (possibly) based on their inputs.
Linear filters: outputs (yj) are weighted sums of the inputs (xi) plus a constant.
bxwxwxwy
bxwy
NN
Niii
(...)2211
],1[
for b constantwi constant for all i
N is the number of inputs
![Page 5: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/5.jpg)
Linearity and Matricies Matrix multiply is exactly weighted sum We treat inputs (xi) and outputs (yj) as
vectors of values (x, and y respectively) Filter is represented as a matrix of
weights A and a vector of constants b Therefore, filter represents the equation
y = xA + b
![Page 6: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/6.jpg)
Equation Example, y1
3,42,41,4
3,32,31,3
3,22,21,2
3,12,11,1
aaa
aaa
aaa
aaa 4321 xxxx
321 yyy
321 bbb
)( 11,441,331,21,111 baxaxxaaxy
![Page 7: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/7.jpg)
Equation Example, y2
3,42,41,4
3,32,31,3
3,22,21,2
3,12,11,1
aaa
aaa
aaa
aaa 4321 xxxx
321 yyy
321 bbb
)( 22,442,332,22,112 baxaxxaaxy
![Page 8: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/8.jpg)
Equation Example, y3
3,42,41,4
3,32,31,3
3,22,21,2
3,12,11,1
aaa
aaa
aaa
aaa 4321 xxxx
321 yyy
321 bbb
)( 33,443,333,23,113 baxaxxaaxy
![Page 9: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/9.jpg)
Usefulness of Linearity Not all filters compute linear
functions push(pop()*pop());
Many fundamental DSP filters do DFT/FFT DCT Convolution/FIR Matrix Multiply
![Page 10: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/10.jpg)
Example: DFT Matrix
NjN
NNN
NN
NN
NNNN
NNNN
N
ew
www
www
www
F
/2
)1()1(1)1(0)1(
)1(11101
)1(01000
...
............
...
...
1,...,2,1,0,)()(1
0
/2
NmenxmXN
n
Nnmj DFT:
row n
column m
![Page 11: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/11.jpg)
Example: IDFT Matrix
1,...,2,1,0,)(1
)(1
0
/2
NnemXN
nxN
m
Nmnj IDFT:
NjN
NNN
NN
NN
NNNN
NNNN
N
eN
w
www
www
www
F
/2
)1()1(1)1(0)1(
)1(11101
)1(01000
1
1
...
............
...
...
row m
column n
![Page 12: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/12.jpg)
Usefullness, cont.
Matrix representations Are “embarrassingly parallel” 1
Expose redundant computation
Let us take advantage of existing work in DSP field
Well understood mathematics1: Thank you, Bill Thies
![Page 13: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/13.jpg)
Outline
Introduction
Dataflow Analysis
Hierarchal Matrix Combinations
Performance Optimizations
![Page 14: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/14.jpg)
Dataflow Analysis Basic idea: convert the general code
of a filter’s work function into an affine representation (eg y=xA+b) The A matrix represents the linear
combination of inputs used to calculate each output.
The vector b represents a constant offset that is added to the combination.
![Page 15: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/15.jpg)
“Linear” Dataflow Analysis Much like standard constant prop. Goal: Have a vector of weights and a
constant that represents the argument to each push statement which become a column in A and an entry in b.
Keep mappings from variables to their linear forms (eg vector + constant).
![Page 16: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/16.jpg)
“Linear” Dataflow Analysis Of course, we need the appropriate
generating cases, eg
constants
pop/peek(x)
c
0
0
0
0
0
1
0
![Page 17: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/17.jpg)
“Linear” Dataflow Analysis Like const prop, confluence
operator is set union.
Need combination rules to handle things like multiplication and addition (vector add and constant scale)
![Page 18: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/18.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
![Page 19: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/19.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
0
0
0
1
a
![Page 20: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/20.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
0
1
0
0
b
0
0
0
1
a
![Page 21: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/21.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
0
0
1
0
c
0
1
0
0
b
0
0
0
1
a
![Page 22: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/22.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
0
2
0
1
d
0
0
1
0
c
0
1
0
0
b
0
0
0
1
a
![Page 23: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/23.jpg)
Ridiculous Example
a=peek(2);b=pop();c=pop();pop();d=a+2b;e=d+5;
e
0
2
0
1
d
0
0
1
0
c
0
1
0
0
b
0
0
0
1
a
5
2
0
1
![Page 24: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/24.jpg)
Constructing matrix A
a 4
3
2
1
b 8
7
6
5
filter code
push(b); push(a);
Filter A:
00
00
00
A 00b
![Page 25: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/25.jpg)
Constructing matrix A
a 4
3
2
1
b 8
7
6
5
filter code
push(b); push(a);
Filter A:
70
60
50
A 80b
![Page 26: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/26.jpg)
Constructing matrix A
a 4
3
2
1
b 8
7
6
5
filter code
push(b); push(a);
Filter A:
73
62
51
A 84b
![Page 27: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/27.jpg)
Big Picture
FIR Filterweights1 = {1,2,3};
weights2 = {4,5,6};
float sum1 = 0; float sum2 = 0;
float mean1 = 5; mean2 = 17;
for (int i=0; i<3; i++) {
sum1 += weights1[i]*peek(3-i-1);
sum1 += weights1[i]*peek(3-i-1);
}
push(sum2 – mean2);
push(sum1 – mean1);
pop();
push = 2pop = 1peek = 3
![Page 28: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/28.jpg)
Big Picture, cont.
x y
y = xA + b
41
52
63
A
size(x) = 3size(y) = 2
Matrix Mult.
175b
![Page 29: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/29.jpg)
Outline
Introduction
Dataflow Analysis
Hierarchal Matrix Combinations
Performance Optimizations
![Page 30: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/30.jpg)
Combining Filters Basic idea: combine pipelines,
splitjoins (and possibly feedback loops) of linear filters together
End up with a single large matrix representation
The details are tricky in the general case (eg I am still working on them)
![Page 31: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/31.jpg)
Combining Pipelines
[A] [B]
ye olde pipeline
[C]single filter
The matrix C is calculated as A’ B’ where A’ and B’ have been appropriately scaled and duplicated to make the dimensions work out.
In the case where peek(B) pop(B), we might have to use two stage filters or duplicate some work to get the dimensions to work out.
![Page 32: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/32.jpg)
Combining Split Joins
[AN]
ye olde SplitJoin
[C]
single filter
splitte
r
[A1]
[A2]
[A3]
join
er
A split join reorders data, so the columns of C are interleaved copies of the columns of A1 through AN.
Matching the rates of A1 through AN is a challenge that I am still working out.
![Page 33: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/33.jpg)
Combining Feedback Loops
[B]
ye olde FeedbackLoop
splitte
r
[A]
join
er
?
It is unclear if we can do anything of use with a FeedbackLoop construct. Eigen values might give information about stability, but it is not clear if that is useful… more thought is needed.
![Page 34: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/34.jpg)
Outline
Introduction
Dataflow Analysis
Hierarchal Matrix Combinations
Performance Optimizations
![Page 35: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/35.jpg)
Performance Optimizations Take advantage of our compile time
knowledge of the matrix coefficients. eg don’t waste computation on zeros
Try and leverage existing DSP work on factoring matricies.
Try to recognize parallel structures in our matrices.
Use frequency analysis.
![Page 36: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/36.jpg)
Factoring for Performance
4,43,42,41,4
3,32,31,3
2,21,2
1,1
4,4
3,3
2,2
1,1
0
00
000
000
000
000
000
cccc
ccc
cc
c
b
b
b
b
BC
4,43,42,41,4
4,33,32,31,3
4,23,22,21,2
4,13,12,11,1
aaaa
aaaa
aaaa
aaaa
A
16 multiplies
12 adds
14 multiplies
6 adds
![Page 37: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/37.jpg)
SPL/SPIRAL Software package that will attempt to
find a fast implementation signal processing algorithms described as matrices.
It attempts to find a sparse factorization of an arbitrary matrix.
It can automatically derive FFT (eg the Cooley-Turkey algorithm) from DFT definition.
Claim that their performance is FFTW1.1. See http://www.fftw.org
![Page 38: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/38.jpg)
Recognize Parallel Structure We can go from SplitJoin to matrix.
Perhaps we can recognize the reverse transformation.
Also, implement blocked matrix multiply to keep parallel resources busy.
![Page 39: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/39.jpg)
Frequency Analysis
[A]
DFT [A’]
IDFT
Instead of computing the matrix product straight up, possibly go to frequency domain.
Rids us of offset vector (added to response at f=0).
Might allow additional optimizations (because of possible symmetries exposed in frequency domain).
![Page 40: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/40.jpg)
Work left to do Implementation of single filter
analysis. Combining hierarchical constructs. Understand the math of automatic
matrix factorizations (group theory).
Analyze frequency analysis. Implement optimizations. Get results.
![Page 41: Linear Filters in StreamIt](https://reader036.vdocuments.mx/reader036/viewer/2022062322/56814d0e550346895dba4af5/html5/thumbnails/41.jpg)
Questions for the Future Are there any other optimizations? Can we produce inverted matrices
programmer codes up transmitter and StreamIt automatically creates the receiver.1
How many cycles of a “real” DSP application are spent computing linear functions?
Can we combine the linear description of what happens inside a filter with the SARE representation of what is happening between them? (POPL paper)
1. Thank you, BT