53 #ifndef _ROLE_SOBEL_HW_COMMON_HPP_
54 #define _ROLE_SOBEL_HW_COMMON_HPP_
58 #include <hls_stream.h>
61 #include "../../../../../HOST/vision/sobel/languages/cplusplus/include/config.h"
62 #include "memory_utils.hpp"
82 template<
typename Tin,
typename Tout,
unsigned int arraysize>
85 for (
unsigned int i = 0; i < arraysize; i++)
87 #pragma HLS PIPELINE II=1
107 template<
typename Tin,
typename Tout, const
unsigned int arraysize>
111 circ_buff_loop:
for (
unsigned int i = 0; i < elems; i++)
113 #pragma HLS PIPELINE II=1
114 #pragma HLS LOOP_TRIPCOUNT min = 1 max = arraysize
115 if(offset_buff+j==arraysize)
119 out_mem[i] = buff[0];
121 out_mem[i] = buff[offset_buff+j];
141 template<
typename Tin,
typename Tout, const
unsigned int burstsize>
144 mmloop:
for (
unsigned int i = 0; i < elems; i++)
146 #pragma HLS PIPELINE II=1
147 #pragma HLS LOOP_TRIPCOUNT min = 1 max = burstsize
148 Tout
tmp = main_mem[i];
170 template<
typename Tin,
typename Tout, const
unsigned int burstsize,
typename Tcntr>
174 mmloop:
for (
unsigned int i = 0; i < elems; i++)
176 #pragma HLS PIPELINE II=1
177 #pragma HLS LOOP_TRIPCOUNT min = 1 max = burstsize
178 Tout
tmp = main_mem[i];
200 template<
typename Tin,
typename Tout, const
unsigned int burstsize,
typename Tcntr>
204 mmloop:
for (
unsigned int i = 0; i < elems; i++)
206 #pragma HLS PIPELINE II=1
207 #pragma HLS LOOP_TRIPCOUNT min = 1 max = burstsize
208 Tout
tmp = main_mem[i];
220 template<
typename Tin,
const unsigned int loop_cnt,
221 const unsigned int bytes_per_loop,
const unsigned int max_data_transfer>
225 Tin &img_in_axi_stream,
226 unsigned int *processed_word_rx,
227 unsigned int *processed_bytes_rx,
228 stream<bool> &sImageLoaded
235 unsigned int bytes_with_keep = 0;
236 for (
unsigned int i=0; i<loop_cnt; i++) {
237 if ((word.
tkeep >> i) == 0) {
238 printf(
"WARNING: value with tkeep=0 at i=%u\n", i);
241 v.data = (ap_uint<INPUT_PTR_WIDTH>)(word.
tdata >> i*8);
244 img_in_axi_stream.write(v.data);
245 bytes_with_keep += bytes_per_loop;
247 if (*processed_bytes_rx < max_data_transfer){
249 (*processed_bytes_rx) += bytes_with_keep;
250 if (!sImageLoaded.full()) {
251 sImageLoaded.write(
false);
255 printf(
"DEBUG in storeWordToAxiStream: WARNING - you've reached the max depth of img. Will put *processed_bytes_rx = 0.\n");
256 *processed_bytes_rx = 0;
257 if (!sImageLoaded.full()) {
258 sImageLoaded.write(
true);
267 template<
typename TInImg, const
unsigned int img_pckts>
270 unsigned int *processed_word,
unsigned int *image_loaded)
274 img[*processed_word] = (TInImg)
input;
275 printf(
"DEBUG in storeWordToArray: input = %u = 0x%16.16llX \n",
input,
input);
276 printf(
"DEBUG in storeWordToArray: img[%u]= %u = 0x%16.16llX \n", *processed_word,
277 (uint64_t)
img[*processed_word], (uint64_t)
img[*processed_word]);
278 if (*processed_word < img_pckts-1) {
282 printf(
"DEBUG in storeWordToArray: WARNING - you've reached the max depth of img[%u]. Will put *processed_word = 0.\n", *processed_word);
301 template<
typename Tin,
typename Tout,
unsigned int counter_precision=64>
302 void perfCounterProc(hls::stream<Tin>& cmd, hls::stream<Tout>&
out,
int direction,
int burst_length,
int nmbr_outstanding)
304 #pragma HLS INLINE off
308 ap_uint<counter_precision> cnt = cmd.read();
311 while (cmd.read_nb(input_cmd) ==
false) {
313 #if DEBUG_LEVEL == TRACE_ALL
314 #ifndef __SYNTHESIS__
315 printf(
"DEBUG perfCounterProc counter value = %s\n", cnt.to_string().c_str());
336 template<
typename Tin,
typename Tout,
unsigned int counter_precision=64>
341 ap_uint<counter_precision> cnt = cmd.read();
344 while (cmd.read_nb(input_cmd) ==
false) {
345 #pragma HLS LOOP_TRIPCOUNT min = 1 max = max_counter_cc
348 #if DEBUG_LEVEL == TRACE_ALL
349 #ifndef __SYNTHESIS__
350 printf(
"DEBUG perfCounterProc counter value = %s\n", cnt.to_string().c_str());
370 template<
typename Tin,
typename Tout,
unsigned int counter_precision=64>
375 ap_uint<counter_precision> cnt = cmd.read();
378 while (cmd.read_nb(input_cmd) ==
false) {
379 #pragma HLS LOOP_TRIPCOUNT min = 1 max = max_counter_cc
382 #if DEBUG_LEVEL == TRACE_ALL
383 #ifndef __SYNTHESIS__
384 printf(
"DEBUG perfCounterProc counter value = %s\n", cnt.to_string().c_str());
406 template<
typename Tin,
typename Tout,
unsigned int counter_precision=64>
411 ap_uint<counter_precision> cnt = cmd.read();
414 while (cmd.read_nb(input_cmd) ==
false) {
415 #pragma HLS LOOP_TRIPCOUNT min = 1 max = max_counter_cc
417 #if DEBUG_LEVEL == TRACE_ALL
418 #ifndef __SYNTHESIS__
419 printf(
"DEBUG perfCounterProc counter value = %s\n", cnt.to_string().c_str());
438 template<
typename Tin,
typename Tout,
unsigned int counter_precision=64>
440 #pragma HLS interface ap_ctrl_none port=return
444 ap_uint<counter_precision> cnt = cmd.read();
446 while (input_cmd != 0)
448 #pragma HLS LOOP_TRIPCOUNT min = 1 max = max_counter_cc
449 #if DEBUG_LEVEL == TRACE_ALL
450 #ifndef __SYNTHESIS__
456 while (cmd.read_nb(input_cmd) ==
false) {
457 #pragma HLS LOOP_TRIPCOUNT min = 1 max = max_counter_cc
458 #pragma HLS PIPELINE II=1
460 #if DEBUG_LEVEL == TRACE_ALL
461 #ifndef __SYNTHESIS__
466 input_cmd=cmd.read();
485 template<
typename Tevent=
bool, const
unsigned int counter_w
idth=32, const
unsigned int maximum_counter_value_before_reset=4000000>
487 hls::stream<Tevent> &sOfEnableCCIncrement,
488 hls::stream<Tevent> &sOfResetCounter,
489 hls::stream<Tevent> &sOfGetTheCounter,
490 hls::stream<ap_uint<counter_width> > &oSClockCounter)
493 static ap_uint<counter_width> internal_counter = 0;
494 static bool pop_the_counter =
false;
495 #pragma HLS reset variable=internal_counter
496 #pragma HLS reset variable=pop_the_counter
498 if(!sOfGetTheCounter.empty()){
499 pop_the_counter = sOfGetTheCounter.read();
501 if (pop_the_counter && !oSClockCounter.full())
503 oSClockCounter.write(internal_counter);
504 pop_the_counter=
false;
506 if(!sOfResetCounter.empty()){
507 bool reset_or_not = sOfResetCounter.read();
510 internal_counter = 0;
513 if(!sOfEnableCCIncrement.empty()){
514 bool increment = sOfEnableCCIncrement.read();
517 if(internal_counter==maximum_counter_value_before_reset){
522 #if DEBUG_LEVEL == TRACE_ALL
523 #ifndef __SYNTHESIS__
524 printf(
"DEBUG pCountClockCycles counter value = %s\n", internal_counter.to_string().c_str());
const unsigned long int max_counter_cc
void pCountClockCycles(hls::stream< Tevent > &sOfEnableCCIncrement, hls::stream< Tevent > &sOfResetCounter, hls::stream< Tevent > &sOfGetTheCounter, hls::stream< ap_uint< counter_width > > &oSClockCounter)
Count Clock Cycles between two events first sketch TODO: make it working without counting with the st...
void perfCounterProc2MemCountIncremental(hls::stream< Tin > &cmd, Tout *out)
Count Clock Cycles between two events, the first event init the counter the second stop the count and...
void perfCounterMultipleCounts(hls::stream< Tin > &cmd, Tout *out)
Count Clock Cycles between two events, the first event init the counter the second stop the count,...
void storeWordToAxiStream(NetworkWord word, Tin &img_in_axi_stream, unsigned int *processed_word_rx, unsigned int *processed_bytes_rx, stream< bool > &sImageLoaded)
Store a net word to a local AXI stream.
void perfCounterProc2Mem(hls::stream< Tin > &cmd, Tout *out, int direction, int burst_length, int nmbr_outstanding)
void storeWordToArray(uint64_t input, TInImg img[img_pckts], unsigned int *processed_word, unsigned int *image_loaded)
Store a net word to local memory.
void pReadAxiMemMapped2HlsStreamCountFirst(Tin *main_mem, hls::stream< Tout > &sOut, unsigned int elems, hls::stream< Tcntr > &cmd)
Copy a run-time variable amount of data to an hls stream with a given max it assumes also the initial...
void perfCounterProc2MemCountOnly(hls::stream< Tin > &cmd, Tout *out)
Count Clock Cycles between two events, the first event init the counter the second stop the count.
void pReadAxiMemMapped2HlsStream(Tin *main_mem, hls::stream< Tout > &sOut, unsigned int elems)
Copy a run-time variable amount of data to an hls stream with a given max.
void perfCounterProc(hls::stream< Tin > &cmd, hls::stream< Tout > &out, int direction, int burst_length, int nmbr_outstanding)
void pMyMemtestMemCpy(Tin *in, Tout *out)
Copy a fixed compile time amount of data to another array.
void pReadAxiMemMapped2HlsStreamCountActivated(Tin *main_mem, hls::stream< Tout > &sOut, unsigned int elems, hls::stream< Tcntr > &cmd)
Copy a run-time variable amount of data to an hls stream with a given max it assumes "perfCounterMult...
void pMemCpyCircularBuff(Tin *buff, Tout *out_mem, unsigned int elems, unsigned int offset_buff)
Copy a run-time variable amount of data to another array employing the src as circular buffer i....