-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example accelerator using HLS #2056
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f9bdb6
Add HLS example accelerator
89a1c0b
Remove commented code
298cf8a
Remove HLS accel from CI run-tests
e5ac978
Compress C accel into 1 file + fix spacing
61f19f1
Move HLS example to chipyard/example
aa950a8
Merge HLS config fragment into existing fragment
6b14034
Fix broken path
669f7ae
Fix HLS accel config name
d030088
Fix newline error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.. _incorporating-hls: | ||
|
||
Incorporating HLS | ||
============================ | ||
|
||
High Level Synthesis (HLS) is a method for iterating quickly on | ||
different hardware algorithms that automatically generates an RTL | ||
circuit to match a specification in a high level language like C. | ||
|
||
Here, we will integrate an HLS-generated accelerator that computes | ||
the Great Common Denominator (GCD) of two integers. This tutorial | ||
builds on the sections :ref:`mmio-accelerators` and | ||
:ref:`incorporating-verilog-blocks`. | ||
|
||
Adding an HLS project | ||
--------------------------------------- | ||
|
||
In this tutorial, we use Vitis HLS. The user guide for this tool | ||
can be found at https://docs.amd.com/r/en-US/ug1399-vitis-hls. | ||
|
||
Our project consists of 3 HLS files: | ||
* C program of the GCD algorithm: :gh-file-ref:`generators/chipyard/src/main/resources/hls/HLSAccel.cpp` | ||
* TCL script to run Vitis HLS: :gh-file-ref:`generators/chipyard/src/main/resources/hls/run_hls.tcl` | ||
* Makefile to run HLS and move verilog files: :gh-file-ref:`generators/chipyard/src/main/resources/hls/Makefile` | ||
|
||
This example implements an iterative GCD algorithm, which is manually connected to | ||
a TileLink register node in the ``HLSGCDAccel`` class in | ||
:gh-file-ref:`generators/chipyard/src/main/scala/example/GCD.scala`. | ||
HLS also supports adding AXI nodes to accelerators using compiler directives and | ||
the HLS stream library. See the Vitis HLS user guide for AXI implementation information. | ||
|
||
The HLS code is synthesized for a particular FPGA target, in this case, | ||
an AMD Alveo U200. The target FPGA part is specified in ``run_hls.tcl`` using | ||
the ``set_part command``. The clock period, used for design optimization purposes, | ||
is also set in ``run_hls.tcl`` using the ``create_clock`` command. | ||
|
||
To generate the verilog files, as well as synthesis reports, run: | ||
|
||
.. code-block:: none | ||
|
||
vitis_hls run_hls.tcl | ||
|
||
The files can be found in a generated folder named proj\_\<your\_project\_name>, | ||
in our case, ``proj_gcd_example``. | ||
|
||
In our case, we include a ``Makefile`` to run HLS and to move files to | ||
their intended locations. To generate the verilog files using the Makefile, run: | ||
|
||
.. code-block:: none | ||
|
||
make | ||
|
||
To delete the generated files, run: | ||
|
||
.. code-block:: none | ||
|
||
make clean | ||
|
||
Creating the Verilog black box | ||
--------------------------------------- | ||
|
||
.. Note:: This section discusses automatically running HLS within a Verilog black box. Please consult :ref:`incorporating-verilog-blocks` for background information on writing a Verilog black box. | ||
|
||
We use Scala to run ``make``, which runs HLS and copies the files into :gh-file-ref:`generators/chipyard/src/main/resources/vsrc`. | ||
Then, we add the path to each file. This code will execute during Chisel elaboration, conveniently handling | ||
file generation for the user. | ||
|
||
.. literalinclude:: ../../generators/chipyard/src/main/scala/example/GCD.scala | ||
:language: scala | ||
:start-after: DOC include start: HLS blackbox | ||
:end-before: DOC include end: HLS blackbox | ||
|
||
Running the example | ||
--------------------------------------- | ||
|
||
To test if the accelerator works, use the test program in :gh-file-ref:`tests/gcd.c`. | ||
Compile the program with ``make``. Then, run: | ||
|
||
.. code-block:: none | ||
|
||
cd sims/vcs | ||
make run-binary CONFIG=HLSAcceleratorRocketConfig BINARY=../../tests/gcd.riscv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef _GCD_EX_H_ | ||
#define _GCD_EX_H_ | ||
|
||
#include <ap_int.h> | ||
|
||
#define DATA_WIDTH 32 | ||
|
||
typedef ap_uint<DATA_WIDTH> io_t; | ||
|
||
io_t HLSGCDAccelBlackBox(io_t x, io_t y) { | ||
io_t tmp; | ||
io_t gcd; | ||
|
||
tmp = y; | ||
gcd = x; | ||
|
||
while(tmp != 0) { | ||
if (gcd > tmp) { | ||
gcd = gcd - tmp; | ||
} else { | ||
tmp = tmp - gcd; | ||
} | ||
} | ||
|
||
return gcd; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
base_dir=$(abspath ../../../..) | ||
hls_dir=$(abspath .) | ||
hls_vlog_gendir=$(hls_dir)/proj_gcd_example/solution1/syn/verilog | ||
vsrc_dir=$(base_dir)/src/main/resources/vsrc | ||
|
||
.PHONY: default run-hls clean | ||
|
||
HLS_CMD = vitis_hls | ||
TCL_SCRIPT = run_hls.tcl | ||
ACCEL_C = HLSAccel.cpp | ||
|
||
default: run-hls | ||
|
||
run-hls: $(ACCEL_C) $(TCL_SCRIPT) | ||
$(HLS_CMD) $(TCL_SCRIPT) | ||
cp -r $(hls_vlog_gendir)/. $(vsrc_dir) | ||
|
||
clean: | ||
rm -rf $(hls_dir)/proj_gcd_example | ||
rm -f $(hls_dir)/vitis_hls.log | ||
rm -f $(vsrc_dir)/HLSGCDAccelBlackBox* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open_project -reset proj_gcd_example | ||
add_files HLSAccel.cpp | ||
set_top HLSGCDAccelBlackBox | ||
open_solution -reset "solution1" | ||
|
||
# Specify FPGA board and clock frequency | ||
set_part {xcu200-fsgd2104-2-e} | ||
create_clock -period 10 | ||
|
||
csynth_design | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also mention the TODO of how to connect up to an AXI interface.