Skip to content

Commit 84ad787

Browse files
authored
Merge pull request #1254 from haoyanwa/oneapi_backend/experiment
oneAPI BSP Support
2 parents 97c187d + 496846d commit 84ad787

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

docs/api/configuration.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ Finally, one then uses the configuration to create an hls model:
101101
backend='Vitis'
102102
)
103103
104+
To target an oneAPI Board Support Package (BSP) enabled FPGA for offload acceleration, you can specify the ``part`` argument to be the path to your BSP and the BSP variant. Then, set ``use_oneapi_bsp=True``.
105+
106+
.. code-block:: python
107+
108+
hls_model = hls4ml.converters.convert_from_keras_model(
109+
model,
110+
hls_config=config,
111+
output_dir="my_project_dir",
112+
io_type="io_parallel",
113+
backend="oneAPI",
114+
part="/path/to/my/bsp:bsp_variant",
115+
use_oneapi_bsp=True
116+
)
117+
104118
See :py:class:`~hls4ml.converters.convert_from_keras_model` for more information on the various options. Similar functions exist for ONNX and PyTorch.
105119

106120
----
@@ -132,6 +146,9 @@ It looks like this:
132146
ClockPeriod: 5
133147
IOType: io_parallel # options: io_parallel/io_stream
134148
149+
# oneAPI Offload Acceleration flag.
150+
UseOneAPIBSP: True
151+
135152
HLSConfig:
136153
Model:
137154
Precision: fixed<16,6>
@@ -156,6 +173,7 @@ The backend-specific section of the configuration depends on the backend. You ca
156173
For Vivado backend the options are:
157174

158175
* **Part**\ : the particular FPGA part number that you are considering, here it's a Xilinx Virtex UltraScale+ VU13P FPGA
176+
* **UseOneAPIBSP**\ : path to the oneAPI Board Support Package (and the BSP variant) to enable offload acceleration with an Altera FPGA. This is only needed if you are using the oneAPI backend.
159177
* **ClockPeriod**\ : the clock period, in ns, at which your algorithm runs
160178
Then you have some optimization parameters for how your algorithm runs:
161179
* **IOType**\ : your options are ``io_parallel`` or ``io_stream`` which defines the type of data structure used for inputs, intermediate activations between layers, and outputs. For ``io_parallel``, arrays are used that, in principle, can be fully unrolled and are typically implemented in RAMs. For ``io_stream``, HLS streams are used, which are a more efficient/scalable mechanism to represent data that are produced and consumed in a sequential manner. Typically, HLS streams are implemented with FIFOs instead of RAMs. For more information see `here <https://docs.xilinx.com/r/en-US/ug1399-vitis-hls/pragma-HLS-stream>`__.

hls4ml/backends/oneapi/oneapi_backend.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def get_default_flow(self):
129129
def get_writer_flow(self):
130130
return self._writer_flow
131131

132-
def create_initial_config(self, part='Arria10', clock_period=5, io_type='io_parallel', write_tar=False, **_):
132+
def create_initial_config(
133+
self, part='Arria10', clock_period=5, io_type='io_parallel', write_tar=False, use_oneapi_bsp=False, **_):
133134
"""Create initial configuration of the oneAPI backend.
134135
135136
Args:
@@ -153,10 +154,7 @@ def create_initial_config(self, part='Arria10', clock_period=5, io_type='io_para
153154
# TODO: add namespace
154155
'WriteTar': write_tar,
155156
}
156-
157-
if 'use_bsp' in _:
158-
config['IS_BSP'] = True
159-
157+
config['UseOneAPIBSP'] = use_oneapi_bsp
160158
return config
161159

162160
def compile(self, model):

hls4ml/templates/oneapi/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ set(LIBRARY_NAME myproject-${LIB_STAMP})
3939
# specific part number (E.g. "10AS066N3F40E2SG") to generate a standalone IP.
4040
if(NOT DEFINED FPGA_DEVICE)
4141
set(FPGA_DEVICE "Agilex7")
42+
set(BSP_FLAG "")
4243
endif()
4344

45+
# Set the target to a BSP if we target an actual accelerator board.
46+
# hls-fpga-machine-learning insert oneapi_bsp_cmake_flag
47+
4448
# Use cmake -DUSER_FPGA_FLAGS=<flags> to set extra flags for FPGA backend
4549
# compilation.
4650
# -Xsoptimize=latency Turns off the hyper-optimized handshake
4751
set(USER_FPGA_FLAGS -Wno-unused-label;${USER_FPGA_FLAGS};-Xsoptimize=latency)
4852

4953
# Use cmake -DUSER_FLAGS=<flags> to set extra flags for general compilation.
50-
set(USER_FLAGS -Wno-unused-label -fconstexpr-steps=134217728 ${USER_FLAGS})
54+
set(USER_FLAGS -Wno-unused-label -fconstexpr-steps=134217728 ${USER_FLAGS} ${BSP_FLAG})
5155

5256
# Use cmake -DUSER_INCLUDE_PATHS=<paths> to set extra paths for general
5357
# compilation.

hls4ml/templates/oneapi/firmware/myproject.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using PipeProps = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext
1111
// Pipe properties for host pipes. Host pipes connect to the data source DMA and sink DMA.
1212
// They are connected to the first and the last layer to stream data into and out from the kernel.
1313
using HostPipePropertiesT = decltype(sycl::ext::oneapi::experimental::properties(
14-
sycl::ext::intel::experimental::ready_latency<0>, sycl::ext::intel::experimental::bits_per_symbol<8>,
14+
sycl::ext::intel::experimental::ready_latency<0>, sycl::ext::intel::experimental::bits_per_symbol<16>,
1515
sycl::ext::intel::experimental::uses_valid<true>, sycl::ext::intel::experimental::first_symbol_in_high_order_bits<true>,
1616
sycl::ext::intel::experimental::protocol_avalon_streaming_uses_ready));
1717

@@ -127,12 +127,15 @@ template <class src_pipe, class dst_T> struct DMA_convert_data_back {
127127
class MyProjectID;
128128

129129
struct MyProject {
130-
130+
#ifndef IS_BSP
131131
// kernel property method to config invocation interface
132132
auto get(sycl::ext::oneapi::experimental::properties_tag) {
133133
return sycl::ext::oneapi::experimental::properties{sycl::ext::intel::experimental::streaming_interface<>,
134134
sycl::ext::intel::experimental::pipelined<>};
135135
}
136+
#else
137+
// kernel properties and pipelining is not supported in BSP.
138+
#endif
136139

137140
SYCL_EXTERNAL void operator()() const;
138141
};

hls4ml/writer/oneapi_writer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ def write_build_script(self, model):
557557
if 'set(FPGA_DEVICE' in line:
558558
line = f' set(FPGA_DEVICE "{device}")\n'
559559

560+
if model.config.get_config_value('UseOneAPIBSP'):
561+
if 'hls-fpga-machine-learning insert oneapi_bsp_cmake_flag' in line:
562+
line = f'set(BSP_FLAG "-DIS_BSP")'
563+
560564
fout.write(line)
561565

562566
def write_nnet_utils(self, model):

0 commit comments

Comments
 (0)