Advertisement
Guest User

HLS code

a guest
Jun 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <hls_stream.h>
  2.  
  3. void MatrixSplitter(int a [2][2], int b [2][2],
  4.         hls::stream<int> &x, hls::stream<int> &y,
  5.         hls::stream<int> &w, hls::stream<int> &z){
  6. #pragma HLS INTERFACE s_axilite port=return
  7. #pragma HLS INTERFACE s_axilite port=a
  8. #pragma HLS INTERFACE s_axilite port=b
  9. #pragma HLS INTERFACE axis register both port=x name=x
  10. #pragma HLS INTERFACE axis register both port=y name=y
  11. #pragma HLS INTERFACE axis register both port=w name=w
  12. #pragma HLS INTERFACE axis register both port=z name=z
  13.  
  14.     //the first 2 integers sent on each stream represent the "position" of the vectors being mutiplied
  15.  
  16.     x.write(0);
  17.     x.write(0);
  18.  
  19.     y.write(0);
  20.     y.write(1);
  21.  
  22.     w.write(1);
  23.     w.write(0);
  24.  
  25.     z.write(1);
  26.     z.write(1);
  27.  
  28.     //then we send on each stream the i-th element of the row from the first matrix
  29.     //followed by the i-th element of the ccolumn from the second matrix
  30.  
  31.     for (int i = 0; i<2; i++){
  32.  
  33.         x.write(a[0][i]);
  34.  
  35.         y.write(a[0][i]);
  36.  
  37.         w.write(a[1][i]);
  38.  
  39.         z.write(a[1][i]);
  40.  
  41.  
  42.         x.write(b[i][0]);
  43.  
  44.         y.write(b[i][1]);
  45.  
  46.         w.write(b[i][0]);
  47.  
  48.         z.write(b[i][1]);
  49.     }
  50. }
  51. void VectorMultiplier (hls::stream<int> &in, hls::stream<int> &out){
  52. #pragma HLS INTERFACE ap_ctrl_none port=return
  53. #pragma HLS INTERFACE axis register both port=in name=in
  54. #pragma HLS INTERFACE axis register both port=out name=out
  55.  
  56.  
  57.     //the first two integers (the "coordinates") are just passed on
  58.     out.write(in.read());
  59.     out.write(in.read());
  60.  
  61.     int res=0;
  62.     for (int i = 0; i<2; i++){
  63.         int part=in.read();
  64.         part*=in.read();
  65.         res += part;
  66.     }
  67.     out.write(res);
  68. }
  69.  
  70. void consumeStream(hls::stream<int> &a, int out [2][2]){
  71.     int row = a.read();
  72.     int col = a.read();
  73.     out [row][col]=a.read();
  74. }
  75.  
  76.  
  77. void MatrixJoiner(hls::stream<int> &x, hls::stream<int> &y,
  78.         hls::stream<int> &w, hls::stream<int> &z, int out [2][2]){
  79. #pragma HLS INTERFACE s_axilite port=return
  80. #pragma HLS INTERFACE axis register both port=x name=x
  81. #pragma HLS INTERFACE axis register both port=y name=y
  82. #pragma HLS INTERFACE axis register both port=w name=w
  83. #pragma HLS INTERFACE axis register both port=z name=z
  84. #pragma HLS INTERFACE s_axilite port=out
  85.  
  86.     int tempOut[2][2]={
  87.             {0, 0},
  88.             {0, 0}
  89.     };
  90.  
  91.     consumeStream(x, tempOut);
  92.     consumeStream(y, tempOut);
  93.     consumeStream(w, tempOut);
  94.     consumeStream(z, tempOut);
  95.  
  96.  
  97.     for (int i = 0; i<2; i++){
  98.         for (int j = 0; j<2; j++){
  99.             out[i][j]=tempOut[i][j];
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement