File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef NNET_STREAM_H
2
+ #define NNET_STREAM_H
3
+
4
+ #include < deque>
5
+
6
+ namespace nnet {
7
+
8
+ /*
9
+ * A struct with the same high-level functionality as Intel's HLS ihc::stream
10
+ * This struct is used during GCC compilation / hls4ml model.predict(...)
11
+ * This is because GCC does not have access to HLS source files (ihc::stream)
12
+ * Software-wise, this struct behaves like a first-in, first-out (FIFO) buffer
13
+ * However, it cannot be used for HLS synthesis, since it uses dynamic memory allocation (deque)
14
+ */
15
+ template <typename T>
16
+ struct stream {
17
+ private:
18
+ std::deque<T> _data;
19
+
20
+ public:
21
+ stream () {}
22
+
23
+ T read () {
24
+ T element = _data.front ();
25
+ _data.pop_front ();
26
+ return element;
27
+ }
28
+
29
+ void write (const T& element) {
30
+ _data.push_back (element);
31
+ }
32
+ };
33
+
34
+ }
35
+
36
+ #endif
Original file line number Diff line number Diff line change 1
1
#ifndef DEFINES_H_
2
2
#define DEFINES_H_
3
3
4
+ /*
5
+ * Intel HLS makes use of three streaming interfaces:
6
+ * (1) stream_in - used as the main input to a component
7
+ * (2) stream_out - used as the main output of a component
8
+ * (3) stream - allows both reading and writing; used for inter-component connections
9
+ * ihc::stream has a implicitly deleted constructor and therefore, cannot be used as the output of a function/component
10
+ * Therefore, variables of type 'stream' are always passed by reference
11
+ */
12
+
4
13
#ifndef __INTELFPGA_COMPILER__
14
+
5
15
#include " ac_int.h"
6
16
#include " ac_fixed.h"
7
17
#define hls_register
18
+
19
+ #include " stream.h"
20
+ template <typename T>
21
+ using stream = nnet::stream<T>;
22
+ template <typename T>
23
+ using stream_in = nnet::stream<T>;
24
+ template <typename T>
25
+ using stream_out = nnet::stream<T>;
26
+
8
27
#else
28
+
9
29
#include " HLS/hls.h"
10
30
#include " HLS/ac_int.h"
11
31
#include " HLS/ac_fixed.h"
32
+
33
+ template <typename T>
34
+ using stream = ihc::stream<T>;
35
+ template <typename T>
36
+ using stream_in = ihc::stream_in<T>;
37
+ template <typename T>
38
+ using stream_out = ihc::stream_out<T>;
39
+
12
40
#endif
13
41
14
42
// hls-fpga-machine-learning insert numbers
You can’t perform that action at this time.
0 commit comments