41 #ifndef _ROLE_SOBEL_LIBRARY_HPP_
42 #define _ROLE_SOBEL_LIBRARY_HPP_
46 #include <hls_stream.h>
49 #include "../../../../../HOST/vision/sobel/languages/cplusplus/include/config.h"
50 #include "memory_utils.hpp"
55 #define FSM_WRITE_NEW_DATA 0
57 #define PortFsmType uint8_t
61 #define PORTS_OPENED 0x1F
64 #if TRANSFERS_PER_CHUNK_DIVEND == 0
65 #define TRANSFERS_PER_CHUNK_LAST_BURST TRANSFERS_PER_CHUNK
67 #define TRANSFERS_PER_CHUNK_LAST_BURST TRANSFERS_PER_CHUNK_DIVEND
89 stream<NodeId> &sDstNode_sig,
90 ap_uint<32> *po_rx_ports
94 #pragma HLS INLINE off
97 #pragma HLS reset variable=port_fsm
103 printf(
"DEBUG in pPortAndDestionation: port_fsm - FSM_WRITE_NEW_DATA\n");
105 if(!sDstNode_sig.full())
107 NodeId dst_rank = (*pi_rank + 1) % *pi_size;
108 #if DEBUG_LEVEL == TRACE_ALL
109 printf(
"rank: %d; size: %d; \n", (
int) *pi_rank, (
int) *pi_size);
111 sDstNode_sig.write(dst_rank);
117 printf(
"DEBUG in pPortAndDestionation: port_fsm - FSM_DONE\n");
140 stream<NetworkWord> &siSHL_This_Data,
141 stream<NetworkMetaStream> &siNrc_meta,
142 stream<NetworkMetaStream> &sRxtoTx_Meta,
144 stream<ap_uint<INPUT_PTR_WIDTH>> &img_in_axi_stream,
146 unsigned int *processed_word_rx,
147 unsigned int *processed_bytes_rx,
148 stream<bool> &sImageLoaded
152 #pragma HLS INLINE off
153 #pragma HLS pipeline II=1
158 #pragma HLS reset variable=enqueueFSM
163 printf(
"DEBUG in pRXPath: enqueueFSM - WAIT_FOR_META, *processed_word_rx=%u, *processed_bytes_rx=%u\n",
164 *processed_word_rx, *processed_bytes_rx);
165 if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
167 meta_tmp = siNrc_meta.read();
169 sRxtoTx_Meta.write(meta_tmp);
175 printf(
"DEBUG in pRXPath: enqueueFSM - PROCESSING_PACKET, *processed_word_rx=%u, *processed_bytes_rx=%u\n",
176 *processed_word_rx, *processed_bytes_rx);
177 if ( !siSHL_This_Data.empty() && !img_in_axi_stream.full())
180 netWord = siSHL_This_Data.read();
183 if(netWord.
tlast == 1)
205 template<
typename TMemWrd, const
unsigned int loop_cnt, const
unsigned int cTransfers_Per_Chunk>
207 stream<NetworkWord> &siSHL_This_Data,
208 stream<NetworkMetaStream> &siNrc_meta,
209 stream<NetworkMetaStream> &sRxtoTx_Meta,
210 stream<ap_uint<TMemWrd>> &img_in_axi_stream,
211 stream<bool> &sMemBurstRx
215 #pragma HLS INLINE off
221 static ap_uint<TMemWrd> v = 0;
222 static unsigned int cnt_wr_stream = 0, cnt_wr_burst = 0;
223 #pragma HLS reset variable=cnt_wr_stream
224 #pragma HLS reset variable=cnt_wr_burst
226 #pragma HLS reset variable=enqueueRxToStrFSM
231 printf(
"DEBUG in pRXPathNetToStream: enqueueRxToStrFSM - WAIT_FOR_META\n");
233 if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
235 meta_tmp = siNrc_meta.read();
237 sRxtoTx_Meta.write(meta_tmp);
243 printf(
"DEBUG in pRXPathNetToStream: enqueueRxToStrFSM - PROCESSING_PACKET\n");
244 if ( !siSHL_This_Data.empty() && !img_in_axi_stream.full())
247 netWord = siSHL_This_Data.read();
248 printf(
"DEBUG in pRXPathNetToStream: Data write = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
249 netWord.
tdata.to_long(), netWord.
tkeep.to_int(), netWord.
tlast.to_int());
250 if ((netWord.
tkeep >> cnt_wr_stream) == 0) {
251 printf(
"WARNING: value with tkeep=0 at cnt_wr_stream=%u\n", cnt_wr_stream);
253 v(cnt_wr_stream*64, (cnt_wr_stream+1)*64-1) = netWord.
tdata(0,63);
254 if ((cnt_wr_stream++ == loop_cnt-1) || (netWord.
tlast == 1)) {
255 std::cout <<
"DEBUG in pRXPathNetToStream: Pushing to img_in_axi_stream :" << std::hex << v << std::endl;
256 img_in_axi_stream.write(v);
257 if ((cnt_wr_burst++ == cTransfers_Per_Chunk-1) || (netWord.
tlast == 1)) {
258 if (!sMemBurstRx.full()) {
259 sMemBurstRx.write(
true);
263 if (netWord.
tlast == 1) {
286 template <
typename TMemWrd,const
unsigned int loop_cnt,const
unsigned int bytes_per_loop>
288 stream<ap_uint<TMemWrd>> &img_in_axi_stream,
289 stream<bool> &sMemBurstRx,
291 stream<DmCmd> &soMemWrCmdP0,
292 stream<DmSts> &siMemWrStsP0,
295 stream<bool> &sImageLoaded
299 #pragma HLS INLINE off
300 #pragma HLS pipeline II=1
303 static ap_uint<TMemWrd> v = 0;
306 static unsigned int cur_transfers_per_chunk;
307 static unsigned int cnt_wr_stream, cnt_wr_img_loaded;
308 static unsigned int ddr_addr_in;
310 #pragma HLS reset variable=enqueueStrToDdrFSM
316 static DmSts memWrStsP0;
317 static unsigned int processed_bytes_rx;
319 #pragma HLS reset variable=cur_transfers_per_chunk
320 #pragma HLS reset variable=cnt_wr_stream
321 #pragma HLS reset variable=cnt_wr_img_loaded
322 #pragma HLS reset variable=ddr_addr_in
323 #pragma HLS reset variable=patternWriteNum
324 #pragma HLS reset variable=timeoutCnt
325 #pragma HLS reset variable=memP0
326 #pragma HLS reset variable=memWrStsP0
331 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - WAIT_FOR_META, processed_bytes_rx=%u\n",
334 if ( !img_in_axi_stream.empty() )
336 if ((processed_bytes_rx) == 0) {
342 cur_transfers_per_chunk = 0;
357 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_CHK_PROC_BYTES, processed_bytes_rx=%u\n", processed_bytes_rx);
358 if (processed_bytes_rx <
IMGSIZE-bytes_per_loop) {
359 (processed_bytes_rx) += bytes_per_loop;
362 printf(
"DEBUG in pRXPathStreamToDDR: WARNING - you've reached the max depth of img. Will put processed_bytes_rx = 0.\n");
363 processed_bytes_rx = 0;
369 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_CMD\n");
370 if ( !soMemWrCmdP0.full() ) {
372 if (processed_bytes_rx == 0){
387 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_LOAD\n");
390 if (!sMemBurstRx.empty()) {
391 if (sMemBurstRx.read() ==
true) {
398 if((processed_bytes_rx) == 0) {
408 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_DATA\n");
409 if (!soMemWriteP0.full()) {
411 if (!img_in_axi_stream.empty()) {
412 memP0.
tdata = img_in_axi_stream.read();
413 ap_uint<8> keepVal = 0xFF;
414 memP0.
tkeep = (ap_uint<64>) (keepVal, keepVal, keepVal, keepVal, keepVal, keepVal, keepVal, keepVal);
416 printf(
"DEBUG: (patternWriteNum == cur_transfers_per_chunk -1) \n");
418 cnt_wr_img_loaded = 0;
426 std::cout <<
"DEBUG in pRXPathStreamToDDR: Pushing to soMemWriteP0 :" << std::hex << memP0.
tdata << std::endl;
427 soMemWriteP0.write(memP0);
433 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_STS_A\n");
434 if (!siMemWrStsP0.empty()) {
437 siMemWrStsP0.read(memWrStsP0);
453 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_STS_B\n");
454 if ((memWrStsP0.
tag == 0x0) && (memWrStsP0.
okay == 1)) {
455 if ((processed_bytes_rx) == 0) {
456 if (!sImageLoaded.full()) {
457 if (cnt_wr_img_loaded++ >= 1) {
458 sImageLoaded.write(
false);
462 sImageLoaded.write(
true);
476 printf(
"DEBUG in pRXPathStreamToDDR: enqueueStrToDdrFSM - FSM_WR_PAT_STS_C\n");
477 if((processed_bytes_rx) == 0) {
514 stream<NetworkWord> &soTHIS_Shl_Data,
515 stream<NetworkMetaStream> &soNrc_meta,
516 stream<NetworkWord> &sProcpToTxp_Data,
517 stream<NetworkMetaStream> &sRxtoTx_Meta,
518 stream<NodeId> &sDstNode_sig,
519 unsigned int *processed_word_tx,
525 #pragma HLS INLINE off
530 #pragma HLS reset variable=dequeueFSM
531 #pragma HLS reset variable=dst_rank
536 #pragma HLS reset variable=netWordTx
542 if(!sDstNode_sig.empty())
544 dst_rank = sDstNode_sig.read();
550 #if DEBUG_LEVEL == TRACE_ALL
551 printf(
"DEBUG in pTXPath: dequeueFSM=%d - WAIT_FOR_STREAM_PAIR, *processed_word_tx=%u\n",
558 *processed_word_tx = 0;
561 if (( !sProcpToTxp_Data.empty() && !sRxtoTx_Meta.empty()
562 && !soTHIS_Shl_Data.full() && !soNrc_meta.full() ))
564 netWordTx = sProcpToTxp_Data.read();
571 soTHIS_Shl_Data.write(netWordTx);
573 meta_in = sRxtoTx_Meta.read().tdata;
575 meta_out_stream.
tlast = 1;
576 meta_out_stream.
tkeep = 0xFF;
586 soNrc_meta.write(meta_out_stream);
588 (*processed_word_tx)++;
589 printf(
"DEBUG: Checking netWordTx.tlast...\n");
590 if(netWordTx.
tlast != 1)
598 #if DEBUG_LEVEL == TRACE_ALL
599 printf(
"DEBUG in pTXPath: dequeueFSM=%d - PROCESSING_PACKET, *processed_word_tx=%u\n",
602 if( !sProcpToTxp_Data.empty() && !soTHIS_Shl_Data.full())
604 netWordTx = sProcpToTxp_Data.read();
606 if(netWordTx.
tlast == 1)
614 (*processed_word_tx)++;
615 if (((*processed_word_tx)*8) %
PACK_SIZE == 0)
618 printf(
"DEBUG: A netWordTx.tlast=1 ... sRxpToTxp_Data.empty()==%u \n", sRxpToTxp_Data.empty());
622 soTHIS_Shl_Data.write(netWordTx);
ap_uint< 32 > patternWriteNum
void storeWordToAxiStream(NetworkWord word, stream< ap_axiu< 64, 0, 0, 0 > > &img_in_axi_stream, unsigned int *processed_word_rx, unsigned int *image_loaded)
Store a word from ethernet to a local AXI stream.
#define TRANSFERS_PER_CHUNK
#define FSM_CHK_PROC_BYTES
#define CYCLES_UNTIL_TIMEOUT
#define PROCESSING_PACKET
#define WAIT_FOR_STREAM_PAIR
void pPortAndDestionation(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NodeId > &sDstNode_sig, ap_uint< 32 > *po_rx_ports)
pPortAndDestionation - Setup the port and the destination rank.
#define FSM_WRITE_NEW_DATA
void pRXPathStreamToDDR(stream< ap_uint< TMemWrd >> &img_in_axi_stream, stream< bool > &sMemBurstRx, stream< DmCmd > &soMemWrCmdP0, stream< DmSts > &siMemWrStsP0, stream< Axis< TMemWrd > > &soMemWriteP0, stream< bool > &sImageLoaded)
Receive Path - From RX path stream word aligned to store towards the DDR.
void pTXPath(stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &soNrc_meta, stream< NetworkWord > &sProcpToTxp_Data, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NodeId > &sDstNode_sig, unsigned int *processed_word_tx, ap_uint< 32 > *pi_rank)
Transmit Path - From THIS to SHELL.
void pRXPathNetToStream(stream< NetworkWord > &siSHL_This_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< ap_uint< TMemWrd >> &img_in_axi_stream, stream< bool > &sMemBurstRx)
Receive Path - From SHELL to THIS. Function for accumulating a memory word and write it Not ready for...
void pRXPath(stream< NetworkWord > &siSHL_This_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< ap_uint< INPUT_PTR_WIDTH >> &img_in_axi_stream, NetworkMetaStream meta_tmp, unsigned int *processed_word_rx, unsigned int *processed_bytes_rx, stream< bool > &sImageLoaded)
Receive Path - From SHELL to THIS. FIXME: never checked, just substitute this one from DID.