HLS_Tutorial
HLS_Tutorial
Simone Bologna
[email protected]
University of Bristol
23 October 2019
Outline
● What is VHDL?
– VHSIC Hardware Design Language
● Very High Speed Integrated Circuit Hardware Description Language
– … ergh…
– Used to describe circuits that will be implemented on FPGA via code
– Not covered here!
● High-Level Synthesis (HLS) enables user to transform (synthesise)
C/C++/SystemC code into VHDL
– Enables users to program FPGA in high-level languages!
– Focusing on C++
● Analogies with assembly and high-level languages are stretched
– Each language works better in specific situations
● HLS file, C/C++ code that will be synthesised and run on FPGA
● Test bench (TB) file, C/C++ code that is run to test the HLS code. It
calls the HLS functions and can run tests on their output, e.g. C
asserts.
● Tcl scripts, set of tcl instructions executed by the Vivado HLS shell
● Synthesis, C/C++ → HDL lang (VHDL/Verilog)
● Project, collection of HLS and test bench (TB) files
– Has a top-level function name that is the starting point for synthesis
● Solution, specific implementation of a project
– Runs on a specific device at a specific clock frequency
● C simulation, HLS + TB files are compiled with gcc against HLS
headers and lib and plainly run as any other executable
● C/RTL cosimulation, synthesised HLS code is run on a simulator and
results tested on the C/C++ test bench
Introduction to HLS, Simone Bologna - 23 October 2019 10/42
Setting up your first project
● Problem
● Define your inputs & output
– They will translate as the parameters of your HLS top-level function
● Write up your code
● Test your C++ code
● Synthesis, i.e. convert to VHDL code
– Optimise it to get the desired performance while staying in your HW limits
● Test synthesised design
● Export design, typically in Vivado IP (Intellectual Property) format
● Implement in Vivado on actual FPGA
● Problem definition:
– We want to design a high-throughput vector adder and multiplier
● Throughput: amount of data items passing through the process
Code time!
https://github.com/simonecid/VivadoTutorial
Introduction to HLS, Simone Bologna - 23 October 2019 15/42
Testing
● If the design is working and has been tested, you can proceed with the
synthesis
– Run csyn (abbreviation of csynth_design)
● Vivado HLS synthetises VHDL and Verilog (another HDL language) from
your C++ code
● Synthesis starts from a top-level function, declared in you .tcl file with
set_top
● Parameters of the top-level functions are translated into ports, by
default:
– N-bit variables are translated into STD_LOGIC_VECTORS, i.e. array of 1-bit
ports
– Structs and classes are converted to ports by creating ports for each one
of their attributes
– Arrays are translated into ports able to read from an external memory
Base design
throughput
1.2 Gb/s
Pipelined
throughput
4.7 Gb/s
Base design
throughput
1.2 Gb/s
Pipelined
throughput
4.7 Gb/s
Unrolled
throughput
120 Gb/s
Base design
throughput
1.2 Gb/s
Pipelined
throughput
4.7 Gb/s
Unrolled
throughput
120 Gb/s
Fully
pipelined
throughput
960 Gb/s
Introduction to HLS, Simone Bologna - 23 October 2019 27/42
Finishing touches
● You can use C++11 and higher constructs, e.g. auto or constexpr:
add_files -cflags "-std=c++11 "<HLS_FILE>"
● Run thorough tests on software, do not be lazy like me!
– Debugging stuff at later stages Is just way harder and confusing
● If you do not trust me, ask Aaron!
● Read the list of pragmas and experiment a lot with them
– Array_partition, pipeline, and unroll accept options, study them!
– Pragmas try to bridge the gap between C++ and HLS, master them
● HLS likes ternary operators, if possible use them instead of if
statements!
Ternary operator
Equivalent if statement
● Final timing and resource usage results are only obtainable after
implementation
● Vivado HLS provides tools to implement design without using Vivado
– Not sure how it works, I presume it makes some basic assumptions on
how you are going to place your design in a FPGA and implements it
● By running it you can get a more accurate estimates of timing and
resource usage, although not final they tend to be much closer
● Run export_design -format ip_catalog -evaluate vhdl
– This implements the VHDL design on FPGA
– 10 minutes to run for the small test design, against XX for synthesis
– Results in <ProjectName>/<SolutionName>/impl/report/vhdl/
● FOR THE LOVE OF GOD DO NOT USE THE C/C++ STANDARD LIBRARY!
– I have heard it gives horrible results
● I do not even know how they managed to get HLS to synthesise
● Do not reinvent the wheel!
– Vivado HLS has libraries doing many interesting things
● It is all in the manual
– For instance, #include <hls_math.h> for HLS math libraries
Code time!
https://github.com/simonecid/VivadoTutorial/tree/cpp_version
Introduction to HLS, Simone Bologna - 23 October 2019 38/42
Using C++ constructs