Skip to content

Commit e003234

Browse files
committed
Quartus custom Stream & distinction between g++ (nnet::stream) and i++ (ihc::stream)
1 parent 2233a68 commit e003234

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

hls4ml/templates/quartus/firmware/defines.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
#ifndef DEFINES_H_
22
#define DEFINES_H_
33

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+
413
#ifndef __INTELFPGA_COMPILER__
14+
515
#include "ac_int.h"
616
#include "ac_fixed.h"
717
#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+
827
#else
28+
929
#include "HLS/hls.h"
1030
#include "HLS/ac_int.h"
1131
#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+
1240
#endif
1341

1442
//hls-fpga-machine-learning insert numbers

0 commit comments

Comments
 (0)