cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
sobel.hpp
Go to the documentation of this file.
1 
17 
38 #ifndef _ROLE_SOBEL_H_
39 #define _ROLE_SOBEL_H_
40 
41 #include <stdio.h>
42 #include <iostream>
43 #include <fstream>
44 #include <string>
45 #include <math.h>
46 #include <hls_stream.h>
47 #include "ap_int.h"
48 #include <stdint.h>
49 #include "network.hpp"
50 #include "memory_utils.hpp"
51 
52 using namespace hls;
53 
54 // Define this option to load data from network to DDR memory before calling the kernel.
55 #define ENABLE_DDR
56 
57 
60 enum EchoCtrl {
63  ECHO_OFF = 2
64 };
65 
66 #define ROLE_IS_SOBEL
67 
68 #define WAIT_FOR_META 0
69 #define WAIT_FOR_STREAM_PAIR 1
70 #define PROCESSING_PACKET 2
71 #define LOAD_IN_STREAM 3
72 #define SOBEL_RETURN_RESULTS 4
73 #define SOBEL_RETURN_RESULTS_ABSORB_DDR_LAT 5
74 #define SOBEL_RETURN_RESULTS_UNPACK 6
75 #define SOBEL_RETURN_RESULTS_FWD 7
76 #define WAIT_FOR_TX 8
77 #define FSM_IDLE 9
78 #define FSM_CHK_SKIP 10
79 #define FSM_CHK_PROC_BYTES 11
80 #define FSM_CHK_WRT_CHNK_TO_DDR_PND 12
81 #define FSM_WR_PAT_CMD 13
82 #define FSM_WR_PAT_LOAD 14
83 #define FSM_WR_PAT_DATA 15
84 #define FSM_WR_PAT_STS_A 16
85 #define FSM_WR_PAT_STS_B 17
86 #define FSM_WR_PAT_STS_C 18
87 #define PacketFsmType uint8_t
88 
89 
90 #define DEFAULT_TX_PORT 2718
91 #define DEFAULT_RX_PORT 2718
92 
93 #define Data_t_in ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0>
94 #define Data_t_out ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0>
95 
96 
97 #define MAX_NB_OF_ELMT_READ 16
98 typedef uint8_t mat_elmt_t; // change to float or double depending on your needs
99 
100 #define MAX_NB_OF_WORDS_READ (MAX_NB_OF_ELMT_READ*sizeof(mat_elmt_t)/BPERDW) // =2 if double =1 if float
101 #define MAX_NB_OF_ELMT_PERDW (BPERDW/sizeof(mat_elmt_t)) // =8 if double =16 if float
102 
103 
104 //------------------------------------ Declarations for DDR ----------------------------------------
105 
106 /* General memory Data Width is set as a parameter*/
107 /* 52-bit host AXI data width*/
108 #define MEMDW_512 512 // 512 Bus width in bits for cF DDR memory
109 #define BPERMDW_512 (MEMDW_512/8) // Bytes per DDR Memory Data Word, if MEMDW=512 => BPERMDW_512 = 64
110 #define KWPERMDW_512 (BPERMDW_512/sizeof(TYPE)) // Number of Sobel kernel words per DDR memory word
111 typedef ap_uint<MEMDW_512> membus_512_t; /* 512-bit ddr memory access */
113 #define TOTMEMDW_512 (1 + (IMGSIZE - 1) / BPERMDW_512)
114 
115 
120 #define CHECK_CHUNK_SIZE 0x1000
121 #define BYTE_PER_MEM_WORD BPERMDW_512 // 64
122 #define TRANSFERS_PER_CHUNK (CHECK_CHUNK_SIZE/BYTE_PER_MEM_WORD) //64
123 #define TRANSFERS_PER_CHUNK_DIVEND (TOTMEMDW_512-(TOTMEMDW_512/TRANSFERS_PER_CHUNK)*TRANSFERS_PER_CHUNK)
124 
125 
126 #define fsmStateDDRdef uint8_t
127 
128 // The maximum number of cycles allowed to acknowledge a write to DDR (i.e. read the status stream)
129 #define CYCLES_UNTIL_TIMEOUT 0x0100
130 #define TYPICAL_DDR_LATENCY 4
131 // The latency cycles of cF DDR. We've measured 52, but experimentally we take it if we divide by
132 // 4.769230769, taking into account the II=2 and the latency of the FSM
133 #define DDR_LATENCY (52/4)
134 #define EXTRA_DDR_LATENCY_DUE_II (64 + 8) // 8 is the write from input stream to local stream, 64 is read from local stream to DDR
135 /*
136  * A generic unsigned AXI4-Stream interface used all over the cloudFPGA place.
137  */
138 //Consider using axi_utils.hpp header?
139 // though some difference in the init
140 template<int D>
141 struct Axis {
142  ap_uint<D> tdata;
143  ap_uint<(D+7)/8> tkeep;
144  ap_uint<1> tlast;
145  Axis() {}
146  Axis(ap_uint<D> single_data) : tdata((ap_uint<D>)single_data), tkeep(1), tlast(1) {}
147 };
148 
149 void sobel(
150 
151  ap_uint<32> *pi_rank,
152  ap_uint<32> *pi_size,
153  //------------------------------------------------------
154  //-- SHELL / This / Udp/TCP Interfaces
155  //------------------------------------------------------
156  stream<NetworkWord> &siSHL_This_Data,
157  stream<NetworkWord> &soTHIS_Shl_Data,
158  stream<NetworkMetaStream> &siNrc_meta,
159  stream<NetworkMetaStream> &soNrc_meta,
160  ap_uint<32> *po_rx_ports
161 
162  #ifdef ENABLE_DDR
163  ,
164  //------------------------------------------------------
165  //-- SHELL / Role / Mem / Mp0 Interface
166  //------------------------------------------------------
167  //---- Read Path (MM2S) ------------
168  // stream<DmCmd> &soMemRdCmdP0,
169  // stream<DmSts> &siMemRdStsP0,
170  // stream<Axis<MEMDW_512 > > &siMemReadP0,
171  //---- Write Path (S2MM) -----------
172  stream<DmCmd> &soMemWrCmdP0,
173  stream<DmSts> &siMemWrStsP0,
174  stream<Axis<MEMDW_512> > &soMemWriteP0,
175  //------------------------------------------------------
176  //-- SHELL / Role / Mem / Mp1 Interface
177  //------------------------------------------------------
180  #endif
181 );
182 
183 
184 #endif
185 
186 
membus_512_t membus_t
Definition: memtest.hpp:92
ap_uint< 512 > membus_512_t
Definition: memtest.hpp:91
EchoCtrl
Definition: memtest.hpp:49
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
#define ENABLE_DDR
Definition: sobel.hpp:55
membus_512_t membus_t
Definition: sobel.hpp:112
ap_uint< 512 > membus_512_t
Definition: sobel.hpp:111
uint8_t mat_elmt_t
Definition: sobel.hpp:98
void sobel(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports, stream< DmCmd > &soMemWrCmdP0, stream< DmSts > &siMemWrStsP0, stream< Axis< 512 > > &soMemWriteP0, membus_t *lcl_mem0, membus_t *lcl_mem1)
Main process of the Sobel Application directives.
Definition: sobel.cpp:51
@ ECHO_STORE_FWD
Definition: sobel.hpp:62
@ ECHO_OFF
Definition: sobel.hpp:63
@ ECHO_PATH_THRU
Definition: sobel.hpp:61
Axis(ap_uint< D > single_data)
Definition: sobel.hpp:146
Axis()
Definition: sobel.hpp:145