From 0dc96a2796f448ec4b924ba100cac5046a5d212a Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Mon, 17 Jul 2017 09:34:22 +1200 Subject: [PATCH 1/2] Added sin example. --- .../examples/sin_taylor_series/hls_config.py | 8 ++++ hlsclt/examples/sin_taylor_series/src/dut.cpp | 37 +++++++++++++++++++ hlsclt/examples/sin_taylor_series/src/dut.h | 1 + .../sin_taylor_series/tb/testbench.cpp | 31 ++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 hlsclt/examples/sin_taylor_series/hls_config.py create mode 100644 hlsclt/examples/sin_taylor_series/src/dut.cpp create mode 100644 hlsclt/examples/sin_taylor_series/src/dut.h create mode 100644 hlsclt/examples/sin_taylor_series/tb/testbench.cpp diff --git a/hlsclt/examples/sin_taylor_series/hls_config.py b/hlsclt/examples/sin_taylor_series/hls_config.py new file mode 100644 index 0000000..4365c7f --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/hls_config.py @@ -0,0 +1,8 @@ +# Config file for Sine Taylor Series HLS Project + +top_level_function_name = "sin_taylor_series" +src_files = ["dut.h","dut.cpp"] +tb_files = ["testbench.cpp"] +part_name = "xc7z020clg484-1" +clock_period = "4" +language = "vhdl" diff --git a/hlsclt/examples/sin_taylor_series/src/dut.cpp b/hlsclt/examples/sin_taylor_series/src/dut.cpp new file mode 100644 index 0000000..054cdea --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/src/dut.cpp @@ -0,0 +1,37 @@ +double fact(int x) { + // Comment out the pragma below this line to revert to 'partially optimised'. + #pragma HLS inline off + double result_int = 1.0; + fact_loop: for (int i=1; i<=x; i++) { + #pragma HLS PIPELINE + result_int=result_int*i; + } + return result_int; +} + +double power (double x, int y) { + // Comment out the pragma below this line to revert to 'partially optimised'. + #pragma HLS INLINE OFF + double result_int = 1.0; + power_loop: for (int i=1; i<=y; i++) { + #pragma HLS PIPELINE + result_int=result_int*x; + } + return result_int; +} + +double sin_taylor_series (double x){ + + #pragma HLS DATAFLOW + + int n = 20; + double sum_positive = 0.0; + double sum_negative= 0.0; + + sum_loop: for (int i=1; i<=n; i+=4) { + sum_positive = sum_positive + (power (x,i) / fact (i)); + sum_negative = sum_negative + (power (x,i+2) / fact (i+2)); + } + + return (sum_positive - sum_negative); +} diff --git a/hlsclt/examples/sin_taylor_series/src/dut.h b/hlsclt/examples/sin_taylor_series/src/dut.h new file mode 100644 index 0000000..a0db4ae --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/src/dut.h @@ -0,0 +1 @@ +double sin_taylor_series (double x); diff --git a/hlsclt/examples/sin_taylor_series/tb/testbench.cpp b/hlsclt/examples/sin_taylor_series/tb/testbench.cpp new file mode 100644 index 0000000..a3c1886 --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/tb/testbench.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "../src/dut.h" + +int main(void) { + + // Setup some required variables + const double pi = 3.1415; + const double rad2deg = 180/pi; + const double deg2rad = pi/180; + double x = 0.0; + double result, expected_result; + int error_count = 0; + + // Test Loop + while (x < 90*deg2rad) { + // Call dut + result = sin_taylor_series(x); + // Generate expected_result + expected_result = sin(x); + // Check result and output some visual check + if (fabs(result - expected_result) > expected_result*0.001) { + error_count++; + } + printf("Sin(%d) - Expected result: %f, Got Result: %f\n", int(round(x*rad2deg)), expected_result, result); + x = x + (5*deg2rad); + } + + return error_count; + +} From 16cd6e923638cc90bbea1f8454671522d57600bb Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Mon, 17 Jul 2017 09:34:49 +1200 Subject: [PATCH 2/2] Updated version number. --- hlsclt/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hlsclt/_version.py b/hlsclt/_version.py index b32d6f1..26d7acc 100644 --- a/hlsclt/_version.py +++ b/hlsclt/_version.py @@ -1 +1 @@ -__version__ = '1.0.0.a2' +__version__ = '1.0.0.a3'