void compute_dataflow()

in reInvent19_Developer_Workshop/modules/module_03/design/reference-files/dataflow/convolve_fpga.cpp [32:96]


  void compute_dataflow(hls::stream<RGBPixel>& write_stream, hls::stream<RGBPixel>& read_stream,
                        const float* coefficient, int img_width, int elements, int center) {
      static RGBPixel window_mem[COEFFICIENT_SIZE][MAX_WIDTH];
#pragma HLS data_pack variable=window_mem
#pragma HLS array_partition variable=window_mem complete dim=1
      static fixed coef[COEFFICIENT_SIZE * COEFFICIENT_SIZE];
#pragma HLS array_partition variable=coef complete

      for(int i  = 0; i < COEFFICIENT_SIZE*COEFFICIENT_SIZE; i++) {
          coef[i] = coefficient[i];
      }

      int line_idx = 0;
      while(line_idx < center) {
          for(int i = 0; i < img_width; i++) {
              window_mem[line_idx][i] = zero;
          }
          line_idx++;
      }

      while(line_idx < COEFFICIENT_SIZE - 1) {
          for(int ii = 0; ii < img_width; ii++) {
              read_stream >> window_mem[line_idx][ii];
          }
          line_idx++;
      }

      for(int ii = 0; ii < COEFFICIENT_SIZE; ii++) {
          read_stream >> window_mem[line_idx][ii];
      }

      int top_idx = 0;
      int insert_idx = line_idx;
      int window_line_idx = top_idx;
      int j = 0;
      int insert_column_idx = COEFFICIENT_SIZE;
      while(elements--) {
          fixed sum_r = 0, sum_g=0, sum_b=0;
          for(int m = 0; m < COEFFICIENT_SIZE; ++m) {
              for(int n = 0; n < COEFFICIENT_SIZE; ++n) {
                  int jj = j + n - center;
                  RGBPixel tmp = (jj >= 0 && jj < img_width) ? window_mem[window_line_idx][jj] : zero;
                  fixed coef_tmp = coef[m * COEFFICIENT_SIZE + n] * (jj >= 0 && jj < img_width);
                  sum_r += tmp.r * coef_tmp;
                  sum_g += tmp.g * coef_tmp;
                  sum_b += tmp.b * coef_tmp;
              }
              window_line_idx = ((window_line_idx + 1) == COEFFICIENT_SIZE) ? 0 : window_line_idx + 1;
          }
          window_line_idx = top_idx;
          RGBPixel out = {sum_r.to_int(), sum_g.to_int(), sum_b.to_int(), 0};
          write_stream << out;
          j++;
          if(j >= img_width) {
              j = 0;
              top_idx = ((top_idx + 1) == COEFFICIENT_SIZE) ? 0 : top_idx + 1;
              window_line_idx = top_idx;
          }
          read_stream >> window_mem[insert_idx][insert_column_idx++];
          if (insert_column_idx >= img_width) {
              insert_column_idx = 0;
              insert_idx = ((insert_idx + 1) == COEFFICIENT_SIZE) ? 0 : insert_idx + 1;
          }
      }
  }