Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <hls_stream.h>
- void MatrixSplitter(int a [2][2], int b [2][2],
- hls::stream<int> &x, hls::stream<int> &y,
- hls::stream<int> &w, hls::stream<int> &z){
- #pragma HLS INTERFACE s_axilite port=return
- #pragma HLS INTERFACE s_axilite port=a
- #pragma HLS INTERFACE s_axilite port=b
- #pragma HLS INTERFACE axis register both port=x name=x
- #pragma HLS INTERFACE axis register both port=y name=y
- #pragma HLS INTERFACE axis register both port=w name=w
- #pragma HLS INTERFACE axis register both port=z name=z
- //the first 2 integers sent on each stream represent the "position" of the vectors being mutiplied
- x.write(0);
- x.write(0);
- y.write(0);
- y.write(1);
- w.write(1);
- w.write(0);
- z.write(1);
- z.write(1);
- //then we send on each stream the i-th element of the row from the first matrix
- //followed by the i-th element of the ccolumn from the second matrix
- for (int i = 0; i<2; i++){
- x.write(a[0][i]);
- y.write(a[0][i]);
- w.write(a[1][i]);
- z.write(a[1][i]);
- x.write(b[i][0]);
- y.write(b[i][1]);
- w.write(b[i][0]);
- z.write(b[i][1]);
- }
- }
- void VectorMultiplier (hls::stream<int> &in, hls::stream<int> &out){
- #pragma HLS INTERFACE ap_ctrl_none port=return
- #pragma HLS INTERFACE axis register both port=in name=in
- #pragma HLS INTERFACE axis register both port=out name=out
- //the first two integers (the "coordinates") are just passed on
- out.write(in.read());
- out.write(in.read());
- int res=0;
- for (int i = 0; i<2; i++){
- int part=in.read();
- part*=in.read();
- res += part;
- }
- out.write(res);
- }
- void consumeStream(hls::stream<int> &a, int out [2][2]){
- int row = a.read();
- int col = a.read();
- out [row][col]=a.read();
- }
- void MatrixJoiner(hls::stream<int> &x, hls::stream<int> &y,
- hls::stream<int> &w, hls::stream<int> &z, int out [2][2]){
- #pragma HLS INTERFACE s_axilite port=return
- #pragma HLS INTERFACE axis register both port=x name=x
- #pragma HLS INTERFACE axis register both port=y name=y
- #pragma HLS INTERFACE axis register both port=w name=w
- #pragma HLS INTERFACE axis register both port=z name=z
- #pragma HLS INTERFACE s_axilite port=out
- int tempOut[2][2]={
- {0, 0},
- {0, 0}
- };
- consumeStream(x, tempOut);
- consumeStream(y, tempOut);
- consumeStream(w, tempOut);
- consumeStream(z, tempOut);
- for (int i = 0; i<2; i++){
- for (int j = 0; j<2; j++){
- out[i][j]=tempOut[i][j];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement