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.
This commit is contained in:
DrasLorus 2022-04-20 20:05:09 +02:00
parent eaa9177962
commit b10024004e
Signed by: moniere
GPG key ID: 14C4DE44B8DD6F35
3 changed files with 13 additions and 8 deletions

View file

@ -140,18 +140,18 @@ endif ()
if (ENABLE_TESTING) if (ENABLE_TESTING)
find_package (Catch2 REQUIRED) find_package (Catch2 REQUIRED)
add_library (catch_common OBJECT sources/tb/main_catch2.cpp) add_library (catch_common_${PROJECT_NAME} OBJECT sources/tb/main_catch2.cpp)
target_link_libraries (catch_common PUBLIC Catch2::Catch2) target_link_libraries (catch_common_${PROJECT_NAME} PUBLIC Catch2::Catch2)
add_executable (cordicabs_tb sources/tb/cordicabs_tb.cpp) 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 (CTest)
include (Catch) include (Catch)
catch_discover_tests (cordicabs_tb) catch_discover_tests (cordicabs_tb WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
if (ENABLE_XILINX) 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) if (CMAKE_VERSION VERSION_LESS 3.19.0)
cmake_policy (SET CMP0110 OLD) cmake_policy (SET CMP0110 OLD)
add_test (NAME "\"Xilinx C-Simulation Testbench\"" COMMAND cordicabs_xilinx_tb add_test (NAME "\"Xilinx C-Simulation Testbench\"" COMMAND cordicabs_xilinx_tb

View file

@ -46,8 +46,8 @@ public:
static constexpr const unsigned In_W = TIn_W; static constexpr const unsigned In_W = TIn_W;
static constexpr const unsigned In_I = TIn_I; static constexpr const unsigned In_I = TIn_I;
static constexpr const unsigned Out_W = In_W + 3; static constexpr const unsigned Out_W = In_W + 2;
static constexpr const unsigned Out_I = In_I + 3; static constexpr const unsigned Out_I = In_I + 2;
static constexpr const unsigned nb_stages = Tnb_stages; 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 static constexpr unsigned kn_i = unsigned(kn_values[nb_stages - 1] * double(1U << 4)); // 4 bits are enough

View file

@ -19,6 +19,8 @@
#include "CCordicAbs/CCordicAbs.hpp" #include "CCordicAbs/CCordicAbs.hpp"
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -144,7 +146,6 @@ TEST_CASE("Constexpr CordicAbs works with AP-Types", "[CORDICABS]") {
typedef CCordicAbs<16, 4, 6> cordic_abs; typedef CCordicAbs<16, 4, 6> cordic_abs;
string input_fn = "../data/input.dat"; // _8_14_4_17_5_19_7_12 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; 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"); 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 // Init test vector
for (unsigned i = 0; i < n_lines; i++) { for (unsigned i = 0; i < n_lines; i++) {
double a, b, r; double a, b, r;