From b10024004ebeddc7e15e137a05be02225d274f04 Mon Sep 17 00:00:00 2001 From: DrasLorus Date: Wed, 20 Apr 2022 20:05:09 +0200 Subject: [PATCH] Fix include bugs and revert to lower quantization - Only 2 bits more than input is enough, CoSimulation works (test succeed, even if VitisHLS reports failure on some computers...). - Rename `catch_common` to `catch_common_${PROJECT_NAME}` to avoid problems when included in a cmake top project. - Add a sanity check to unit tests to avoid SEGV. --- CMakeLists.txt | 10 +++++----- sources/CCordicAbs/CCordicAbs.hpp | 4 ++-- sources/tb/cordicabs_tb.cpp | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04b84d2..e70da00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,18 +140,18 @@ endif () if (ENABLE_TESTING) find_package (Catch2 REQUIRED) - add_library (catch_common OBJECT sources/tb/main_catch2.cpp) - target_link_libraries (catch_common PUBLIC Catch2::Catch2) + add_library (catch_common_${PROJECT_NAME} OBJECT sources/tb/main_catch2.cpp) + target_link_libraries (catch_common_${PROJECT_NAME} PUBLIC Catch2::Catch2) add_executable (cordicabs_tb sources/tb/cordicabs_tb.cpp) - target_link_libraries (cordicabs_tb catch_common cordicabs) + target_link_libraries (cordicabs_tb catch_common_${PROJECT_NAME} cordicabs) include (CTest) include (Catch) - catch_discover_tests (cordicabs_tb) + catch_discover_tests (cordicabs_tb WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data) if (ENABLE_XILINX) - find_file (INPUT_DAT_TB input.dat HINTS ${CMAKE_SOURCE_DIR}/data REQUIRED) + find_file (INPUT_DAT_TB input.dat HINTS data REQUIRED) if (CMAKE_VERSION VERSION_LESS 3.19.0) cmake_policy (SET CMP0110 OLD) add_test (NAME "\"Xilinx C-Simulation Testbench\"" COMMAND cordicabs_xilinx_tb diff --git a/sources/CCordicAbs/CCordicAbs.hpp b/sources/CCordicAbs/CCordicAbs.hpp index 8911546..710a64a 100644 --- a/sources/CCordicAbs/CCordicAbs.hpp +++ b/sources/CCordicAbs/CCordicAbs.hpp @@ -46,8 +46,8 @@ public: static constexpr const unsigned In_W = TIn_W; static constexpr const unsigned In_I = TIn_I; - static constexpr const unsigned Out_W = In_W + 3; - static constexpr const unsigned Out_I = In_I + 3; + static constexpr const unsigned Out_W = In_W + 2; + static constexpr const unsigned Out_I = In_I + 2; static constexpr const unsigned nb_stages = Tnb_stages; static constexpr unsigned kn_i = unsigned(kn_values[nb_stages - 1] * double(1U << 4)); // 4 bits are enough diff --git a/sources/tb/cordicabs_tb.cpp b/sources/tb/cordicabs_tb.cpp index 58e84c2..39de600 100644 --- a/sources/tb/cordicabs_tb.cpp +++ b/sources/tb/cordicabs_tb.cpp @@ -19,6 +19,8 @@ #include "CCordicAbs/CCordicAbs.hpp" #include +#include +#include #include #include @@ -144,7 +146,6 @@ TEST_CASE("Constexpr CordicAbs works with AP-Types", "[CORDICABS]") { typedef CCordicAbs<16, 4, 6> cordic_abs; string input_fn = "../data/input.dat"; // _8_14_4_17_5_19_7_12 - string output_fn = "../data/output.dat"; // _8_14_4_17_5_19_7_12 constexpr unsigned n_lines = 100000; @@ -156,6 +157,10 @@ TEST_CASE("Constexpr CordicAbs works with AP-Types", "[CORDICABS]") { FILE * INPUT = fopen(input_fn.c_str(), "r"); + if (!bool(INPUT)) { + throw(string("fopen failed for ") + input_fn + string(": ") + string(strerror(errno))); + } + // Init test vector for (unsigned i = 0; i < n_lines; i++) { double a, b, r;