Skip to content

Commit

Permalink
Rebalanced lookup implementation code to go mostly into header file.
Browse files Browse the repository at this point in the history
  • Loading branch information
preusser committed Sep 9, 2022
1 parent 8ac23b1 commit 8408b45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 15 additions & 2 deletions custom_hls/lookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,36 @@ void StreamingLookup_ext(
hls::stream<T_DST> &out,
T_DST const *const mem,
unsigned const size,
unsigned &oob_count
unsigned &oob_count,
bool &oob_irq
) {
#pragma HLS pipeline II=EmbeddingSize+9 style=flp

static unsigned oob_count_li;
static unsigned oob_count_int;
#pragma HLS reset variable=oob_count_li
#pragma HLS reset variable=oob_count_int

if(oob_count != oob_count_li) {
oob_count_int -= oob_count_li;
oob_count_li = oob_count;
}
if(!in0.empty()) {
T_SRC const x = in0.read();

// Map out-of-bounds inputs to an offset of zero and increment counter
bool const oob = x >= T_SRC(size);
ap_uint<T_SRC::width+EmbeddingAlign> const ofs =
((oob? T_SRC(0) : x), ap_uint<EmbeddingAlign>(0));
oob_count += oob;
oob_count_int += oob;

// Stream lookup data (burst inferred)
for(unsigned i = 0; i < EmbeddingSize; i++) {
#pragma HLS pipeline II=1 style=flp
out.write(mem[ofs+i]);
}
}
oob_count = oob_count_int;
oob_irq = (oob_count_int != 0);
}
#endif
15 changes: 1 addition & 14 deletions src/finn/custom_op/fpgadataflow/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,7 @@ def docompute(self):
]
elif mem_mode == "external":
self.code_gen_dict["$DOCOMPUTE$"] = [
"""
static unsigned oob_count_li;
static unsigned oob_count_int;
#pragma HLS reset variable=oob_count_li
#pragma HLS reset variable=oob_count_int
if(oob_count != oob_count_li) {
oob_count_int -= oob_count_li;
oob_count_li = oob_count;
}
StreamingLookup_ext<EmbeddingSize>(in0, out, mem, size, oob_count_int);
oob_count = oob_count_int;
oob_irq = (oob_count_int != 0);
"""
"StreamingLookup_ext<EmbeddingSize>(in0, out, mem, size, oob_count, oob_irq);"
]

def blackboxfunction(self):
Expand Down

0 comments on commit 8408b45

Please sign in to comment.