Skip to content

Commit 1279b4d

Browse files
minor fixes and testing notebook
1 parent fca966f commit 1279b4d

File tree

7 files changed

+391
-10
lines changed

7 files changed

+391
-10
lines changed

hls4ml/templates/vitis_accelerator/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ all: host kernel
3030
# Building kernel
3131
./build/myproject_kernel.xo: kernel_wrapper.cpp
3232
mkdir -p ./build
33-
v++ -c -t hw --config ./u55c.cfg kernel_wrapper.cpp firmware/myproject.cpp -o ./build/myproject_kernel.xo $(KERN_LIBRARIES)
33+
v++ -c -t hw --config ./accelerator_card.cfg kernel_wrapper.cpp firmware/myproject.cpp -o ./build/myproject_kernel.xo $(KERN_LIBRARIES)
3434

3535
myproject_kernel.xclbin: ./build/myproject_kernel.xo
36-
v++ -l -t hw --config ./u55c.cfg ./build/myproject_kernel.xo -o kernel_wrapper.xclbin
36+
v++ -l -t hw --config ./accelerator_card.cfg ./build/myproject_kernel.xo -o kernel_wrapper.xclbin
3737

3838
# Building Host
3939
INCLUDES += -I$(XILINX_XRT)/include/ -I$(XILINX_VIVADO)/include/ -I$(XILINX_HLS)/include/ \
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
config_interface -m_axi_auto_max_ports=true
1+
config_interface -m_axi_auto_max_ports=true
2+
config_interface -m_axi_offset slave
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include "FpgaObj.hpp"
4+
5+
template <class V, class W>
6+
class DdrFpga : public FpgaObj<V, W> {
7+
public:
8+
DdrFpga(int kernInputSize, int kernOutputSize, int numCU, int numThreads, int numEpochs)
9+
: FpgaObj<V, W>(kernInputSize, kernOutputSize, numCU, numThreads, numEpochs) {
10+
}
11+
12+
void allocateHostMemory(int chan_per_port) {
13+
// Creating Buffer objects in Host memory
14+
/* ***NOTE*** When creating a Buffer with user pointer (CL_MEM_USE_HOST_PTR), under the hood, user pointer
15+
is used if it is properly aligned. when not aligned, runtime has no choice but to create
16+
its own host side Buffer. So it is recommended to use this allocator if user wishes to
17+
create Buffer using CL_MEM_USE_HOST_PTR to align user buffer to page boundary. It will
18+
ensure that user buffer is used when user creates Buffer/Mem object with CL_MEM_USE_HOST_PTR */
19+
size_t vector_size_in_bytes = sizeof(V) * this->_kernInputSize;
20+
size_t vector_size_out_bytes = sizeof(W) * this->_kernOutputSize;
21+
for (int ib = 0; ib < this->_numThreads; ib++) {
22+
for (int ik = 0; ik < this->_numCU; ik++) {
23+
cl::Buffer buffer_in_tmp(this->context,
24+
CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
25+
vector_size_in_bytes,
26+
this->source_in.data() + ((ib*this->_numCU + ik) * this->_kernInputSize));
27+
cl::Buffer buffer_out_tmp(this->context,
28+
CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
29+
vector_size_out_bytes,
30+
this->source_hw_results.data() + ((ib*this->_numCU + ik) * this->_kernOutputSize));
31+
this->buffer_in.push_back(buffer_in_tmp);
32+
this->buffer_out.push_back(buffer_out_tmp);
33+
this->krnl_xil[ib*this->_numCU + ik].setArg(0, this->buffer_in[ib*this->_numCU + ik]);
34+
this->krnl_xil[ib*this->_numCU + ik].setArg(1, this->buffer_out[ib*this->_numCU + ik]);
35+
}
36+
}
37+
}
38+
};

hls4ml/templates/vitis_accelerator/libs/HbmFpga.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class HbmFpga : public FpgaObj<V, W> {
5757
size_t vector_size_out_bytes = sizeof(W) * this->_kernOutputSize;
5858
for (int ib = 0; ib < this->_numThreads; ib++) {
5959
for (int ik = 0; ik < this->_numCU; ik++) {
60-
cl::Buffer buffer_in_tmp (this->context,
60+
cl::Buffer buffer_in_tmp(this->context,
6161
CL_MEM_USE_HOST_PTR | CL_MEM_EXT_PTR_XILINX | CL_MEM_READ_ONLY,
6262
vector_size_in_bytes,
6363
&(this->buf_in_ext[ib*this->_numCU + ik]));

hls4ml/templates/vitis_accelerator/myproject_host_cl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "kernel_wrapper.h"
1010
#include "FpgaObj.hpp"
1111
#include "HbmFpga.hpp"
12+
#include "DdrFpga.hpp"
1213
#include "timing.hpp"
1314
#include "xcl2.hpp"
1415

@@ -34,8 +35,7 @@ int main(int argc, char **argv) {
3435

3536
std::vector<cl::Device> devices = xcl::get_xil_devices(); // Utility API that finds xilinx platforms and return a list of devices connected to Xilinx platforms
3637

37-
// Load xclbin
38-
cl::Program::Binaries bins = xcl::import_binary_file(xclbinFilename);
38+
cl::Program::Binaries bins = xcl::import_binary_file(xclbinFilename); // Load xclbin
3939

4040
fpga.initializeOpenCL(devices, bins);
4141

hls4ml/writer/vitis_accelerator_writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def write_kernel(self, model):
102102
newline += '#define INSTREAMSIZE (BATCHSIZE * DATA_SIZE_IN)' + '\n\n'
103103
newline += '#define DATA_SIZE_OUT ' + format(out.size_cpp()) + '\n'
104104
newline += '#define OUTSTREAMSIZE (BATCHSIZE * DATA_SIZE_OUT)' + '\n\n'
105-
newline += 'typedef ' + format(inp.type.name) + ' in_buffer_t\n'
106-
newline += 'typedef ' + format(out.type.name) + ' out_buffer_t\n'
105+
newline += 'typedef ' + format(inp.type.name) + ' in_buffer_t;\n'
106+
newline += 'typedef ' + format(out.type.name) + ' out_buffer_t;\n'
107107
elif io_type == 'io_stream':
108108
for inp in model_inputs:
109109
for out in model_outputs:
@@ -115,8 +115,8 @@ def write_kernel(self, model):
115115
newline += '#define DATA_SIZE_OUT ' + format(out.size_cpp()) + '\n'
116116
newline += '#define OUTSTREAMSIZE (BATCHSIZE * DATA_SIZE_OUT)' + '\n\n'
117117
precision_str = model.config.backend.convert_precision_string(model.config.model_precision.get('default'))
118-
newline += 'typedef ' + precision_str + ' in_buffer_t\n'
119-
newline += 'typedef ' + precision_str + ' out_buffer_t\n'
118+
newline += 'typedef ' + precision_str + ' in_buffer_t;\n'
119+
newline += 'typedef ' + precision_str + ' out_buffer_t;\n'
120120
else:
121121
newline = line
122122
fout_header.write(newline)

0 commit comments

Comments
 (0)