From 55e87546264df337a6e7af20f9756af0d80a775f Mon Sep 17 00:00:00 2001 From: DrasLorus Date: Sat, 11 Jun 2022 19:58:11 +0200 Subject: [PATCH] MSVC++ Support - Add cl.exe support using CMake and DepFetch module. - Inlining doesn't work, but it compiles --- .gitignore | 5 +- CMakeLists.txt | 82 +++++++++++++---- .../RomGeneratorConst/RomGeneratorConst.hpp | 2 +- .../CCordicRotateConstexpr.hpp | 4 +- sources/tb/catchy/cordic_rom_tb.cpp.in | 30 +++---- sources/tb/catchy/cordic_tb.cpp | 90 +++++++++---------- 6 files changed, 133 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index 9db3a33..66092a9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ RomGenerators/sources/main_generator_??*_*.cpp sources/CCordicRotateRom/CCordicRotateRom_*.?pp sources/CordicRoms/cordic_rom_*.?pp sources/tb/catchy/cordic_rom_tb_??*_*.?pp -sources/tb/catch_less/cordic_rom_aptypes_tb_??*_*.?pp \ No newline at end of file +sources/tb/catch_less/cordic_rom_aptypes_tb_??*_*.?pp + +CMakeSettings.json +.vs \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index f398235..816e638 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,24 @@ project ( VERSION 0.1 ) + if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.2)) + # message ( FATAL_ERROR "This project require a GNU compiler version greater than 6.2." "\nNote: + # If you tried to use g++-4.6.3 as provided by Xilinx Vivado v2019.1, use directly the TCL script + # " "in the folder `hls_files/cordicabs_16_4_6`." ) + set (IS_GNU_LEGACY ON) +else () + set (IS_GNU_LEGACY OFF) + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options (/Zc:__cplusplus) + if (CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + add_compile_options (/Ob0) # Disable inlining, that makes CL.EXE crash. + endif () + endif () +endif () + + +if (IS_GNU_LEGACY) set (CMAKE_CXX_STANDARD 11) else () set (CMAKE_CXX_STANDARD 14) @@ -50,16 +67,26 @@ option (ENABLE_SOFTWARE option (PEDANTIC "use -Wall and -pedantic." ON) +option (ENABLE_DEPFETCH "Allow to fetch dependency from external sources." OFF) + # ################################################################################################## if (PEDANTIC) - add_compile_options (-Wall -pedantic) + add_compile_options (-Wall) + if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options (-pedantic) + endif () endif () if (EXPORT_COMMANDS) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) endif () +if (ENABLE_DEPFETCH) + include (FetchContent) +endif () + + if (ENABLE_XILINX) set ( XILINX_HOME @@ -79,18 +106,32 @@ if (ENABLE_XILINX) endif () message (STATUS "AP headers must lie under ${AP_INCLUDE_DIR}") else () - set ( - AP_TYPES_HINT - /usr/include - CACHE PATH "location of ap_types include directory." - ) - - find_file ( - AP_FIXED ap_fixed.h - HINTS ${AP_TYPES_HINT} - PATH_SUFFIXES ap_types hls_ap_types/include REQUIRED - ) - + if (ENABLE_DEPFETCH) + FetchContent_Declare ( + hlsaptypes + GIT_REPOSITORY https://github.com/DrasLorus/HLS_arbitrary_Precision_Types.git + ) + + FetchContent_MakeAvailable (hlsaptypes) + + find_file ( + AP_FIXED ap_fixed.h + HINTS ${hlsaptypes_SOURCE_DIR} + PATH_SUFFIXES "include" + ) + else () + set ( + AP_TYPES_HINT + /usr/include + CACHE PATH "location of ap_types include directory." + ) + + find_file ( + AP_FIXED ap_fixed.h + HINTS ${AP_TYPES_HINT} + PATH_SUFFIXES ap_types hls_ap_types/include REQUIRED + ) + endif () get_filename_component (AP_INCLUDE_DIR ${AP_FIXED} DIRECTORY) endif () @@ -189,7 +230,7 @@ target_link_libraries (cordic PUBLIC romgen cordic_rom_gen) if (ENABLE_TESTING) include (CTest) - if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.2)) + if (IS_GNU_LEGACY) string ( CONFIGURE ${CMAKE_CURRENT_SOURCE_DIR}/sources/tb/catch_less/cordic_rom_aptypes_tb_${ROM_TYPE}_${CORDIC_W}_${CORDIC_STAGES}_${CORDIC_Q}_${CORDIC_DIVIDER}.cpp @@ -223,7 +264,18 @@ if (ENABLE_TESTING) endforeach () else () - find_package (Catch2 REQUIRED) + if (ENABLE_DEPFETCH) + FetchContent_Declare ( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.13.9 + ) + + FetchContent_MakeAvailable (Catch2) + list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib) + else () + find_package (Catch2 REQUIRED) + endif () string ( CONFIGURE diff --git a/RomGenerators/sources/RomGeneratorConst/RomGeneratorConst.hpp b/RomGenerators/sources/RomGeneratorConst/RomGeneratorConst.hpp index 8bf8ec8..fa0255c 100644 --- a/RomGenerators/sources/RomGeneratorConst/RomGeneratorConst.hpp +++ b/RomGenerators/sources/RomGeneratorConst/RomGeneratorConst.hpp @@ -104,7 +104,7 @@ private: R = beta < 0 ? R | mask : R & nmask; - const double factor = sigma / double(1U << (u - 1)); + const double factor = sigma / double(1LU << (u - 1)); const double I = A + B * factor; B = B - A * factor; diff --git a/sources/CCordicRotateConstexpr/CCordicRotateConstexpr.hpp b/sources/CCordicRotateConstexpr/CCordicRotateConstexpr.hpp index f6c69af..998b0c3 100644 --- a/sources/CCordicRotateConstexpr/CCordicRotateConstexpr.hpp +++ b/sources/CCordicRotateConstexpr/CCordicRotateConstexpr.hpp @@ -90,8 +90,8 @@ public: const int64_t Ri = (R & mask) == mask ? 1 : -1; - const int64_t I = A + Ri * (B / int64_t(1U << (u - 1))); - B = B - Ri * (A / int64_t(1U << (u - 1))); + const int64_t I = A + Ri * (B / int64_t(1LU << (u - 1))); + B = B - Ri * (A / int64_t(1LU << (u - 1))); A = I; } diff --git a/sources/tb/catchy/cordic_rom_tb.cpp.in b/sources/tb/catchy/cordic_rom_tb.cpp.in index 1ada926..9bd0c30 100644 --- a/sources/tb/catchy/cordic_rom_tb.cpp.in +++ b/sources/tb/catchy/cordic_rom_tb.cpp.in @@ -38,10 +38,10 @@ TEST_CASE("ROM-based Cordic (TPL @ROM_TYPE@, @CORDIC_W@, @CORDIC_STAGES@, @CORDI constexpr unsigned n_lines = 100000; - complex values_in[n_lines]; - complex values_out[n_lines]; + vector> values_in(n_lines); + vector> values_out(n_lines); - complex results[n_lines]; + vector> results(n_lines); ifstream INPUT(input_fn); @@ -93,13 +93,13 @@ TEST_CASE("ROM-based Cordic (TPL @ROM_TYPE@, @CORDIC_W@, @CORDIC_STAGES@, @CORDI constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); FILE * INPUT = fopen(input_fn.c_str(), "r"); @@ -148,13 +148,13 @@ TEST_CASE("ROM-based Cordic (TPL @ROM_TYPE@, @CORDIC_W@, @CORDIC_STAGES@, @CORDI constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); FILE * INPUT = fopen(input_fn.c_str(), "r"); diff --git a/sources/tb/catchy/cordic_tb.cpp b/sources/tb/catchy/cordic_tb.cpp index 656ab90..e76b514 100644 --- a/sources/tb/catchy/cordic_tb.cpp +++ b/sources/tb/catchy/cordic_tb.cpp @@ -19,8 +19,10 @@ #include "CCordicRotateConstexpr/CCordicRotateConstexpr.hpp" #include "CCordicRotateSmart/CCordicRotateSmart.hpp" + #include #include +#include #include @@ -36,14 +38,14 @@ TEST_CASE("Adaptive CORDIC work as intended", "[!mayfail][!hide][WIP]") { string output_fn = "../data/output.dat"; // _8_14_4_17_5_19_7_12 constexpr unsigned n_lines = 100000; - ap_fixed<17, 5> values_re_in[n_lines]; - ap_fixed<17, 5> values_im_in[n_lines]; - ap_fixed<14, 4> angles_in[n_lines]; - ap_fixed<19, 7> values_re_out[n_lines]; - ap_fixed<19, 7> values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> angles_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double exp_re_out[n_lines]; - double exp_im_out[n_lines]; + vector exp_re_out(n_lines); + vector exp_im_out(n_lines); FILE * INPUT = fopen(input_fn.c_str(), "r"); FILE * RESULTS = fopen(output_fn.c_str(), "r"); @@ -104,10 +106,10 @@ TEST_CASE("ROM-based Cordic works with C-Types", "[CORDIC]") { constexpr unsigned n_lines = 100000; - complex values_in[n_lines]; - complex values_out[n_lines]; + vector> values_in(n_lines); + vector> values_out(n_lines); - complex results[n_lines]; + vector> results(n_lines); // ofstream FILE; @@ -165,7 +167,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { SECTION("W:16 - I:4 - Stages:6 - q:64") { typedef CCordicRotateConstexpr<16, 4, 6, 64> cordic_rom; - static constexpr cordic_rom cordic {}; + //static constexpr cordic_rom cordic {}; string input_fn = "../data/input.dat"; @@ -176,13 +178,13 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); // ofstream out_stream; @@ -197,7 +199,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { values_re_in[i] = int64_t(a * double(cordic_rom::in_scale_factor)); values_im_in[i] = int64_t(b * double(cordic_rom::in_scale_factor)); - const complex e = c * exp(complex(0., rotation / q * (i & cnt_mask))); + const complex e = c * exp(complex(0., rotation / q * double(i & cnt_mask))); results_re[i] = e.real(); results_im[i] = e.imag(); } @@ -208,7 +210,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { // ofstream out_stream("results_ap.dat"); // FILE * romf = fopen("rom.dat", "w"); - constexpr double abs_margin = double(1 << (cordic.Out_I - 1)) * 2. / 100.; + constexpr double abs_margin = double(1 << (cordic_rom::Out_I - 1)) * 2. / 100.; // Executing the encoder for (unsigned iter = 0; iter < n_lines; iter++) { @@ -242,7 +244,6 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { SECTION("W:16 - I:4 - Stages:6 - q:64 - internal scaling") { typedef CCordicRotateConstexpr<16, 4, 6, 64> cordic_rom; - static constexpr cordic_rom cordic {}; string input_fn = "../data/input.dat"; @@ -253,13 +254,13 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); // ofstream out_stream; @@ -274,7 +275,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { values_re_in[i] = int64_t(a * double(cordic_rom::in_scale_factor)); values_im_in[i] = int64_t(b * double(cordic_rom::in_scale_factor)); - const complex e = c * exp(complex(0., rotation / q * (i & cnt_mask))); + const complex e = c * exp(complex(0., rotation / q * double(i & cnt_mask))); results_re[i] = e.real(); results_im[i] = e.imag(); } @@ -285,7 +286,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { // out_stream.open("results_ap.dat"); // FILE * romf = fopen("rom.dat", "w"); - constexpr double abs_margin = double(1 << (cordic.Out_I - 1)) * 3. / 100.; // Internal scaling create noise + constexpr double abs_margin = double(1 << (cordic_rom::Out_I - 1)) * 3. / 100.; // Internal scaling create noise // Executing the encoder for (unsigned iter = 0; iter < n_lines; iter++) { @@ -324,8 +325,6 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { SECTION("W:16 - I:4 - Stages:6 - q:64 - divider:4") { typedef CCordicRotateConstexpr<16, 4, 6, 64, 4> cordic_rom; - static constexpr cordic_rom cordic {}; - string input_fn = "../data/input.dat"; constexpr double rotation = cordic_rom::rotation; @@ -335,13 +334,13 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); // ofstream out_stream; @@ -356,7 +355,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { values_re_in[i] = int64_t(a * double(cordic_rom::in_scale_factor)); values_im_in[i] = int64_t(b * double(cordic_rom::in_scale_factor)); - const complex e = c * exp(complex(0., rotation / q * (i & cnt_mask))); + const complex e = c * exp(complex(0., rotation / q * double(i & cnt_mask))); results_re[i] = e.real(); results_im[i] = e.imag(); } @@ -367,7 +366,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { // out_stream.open("results_ap.dat"); // FILE * romf = fopen("rom.dat", "w"); - constexpr double abs_margin = double(1 << (cordic.Out_I - 1)) * 2. / 100.; + constexpr double abs_margin = double(1 << (cordic_rom::Out_I - 1)) * 2. / 100.; // Executing the encoder for (unsigned iter = 0; iter < n_lines; iter++) { @@ -401,7 +400,6 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { SECTION("W:16 - I:4 - Stages:6 - q:64 - divider:4 - internal scaling") { typedef CCordicRotateConstexpr<16, 4, 7, 64, 4> cordic_rom; - static constexpr cordic_rom cordic {}; string input_fn = "../data/input.dat"; @@ -412,13 +410,13 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { constexpr unsigned Out_W = cordic_rom::Out_W; constexpr unsigned In_W = cordic_rom::In_W; - ap_int values_re_in[n_lines]; - ap_int values_im_in[n_lines]; - ap_int values_re_out[n_lines]; - ap_int values_im_out[n_lines]; + vector> values_re_in(n_lines); + vector> values_im_in(n_lines); + vector> values_re_out(n_lines); + vector> values_im_out(n_lines); - double results_re[n_lines]; - double results_im[n_lines]; + vector results_re(n_lines); + vector results_im(n_lines); ofstream out_stream; @@ -444,7 +442,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") { // out_stream.open("results_ap.dat"); // FILE * romf = fopen("rom.dat", "w"); - constexpr double abs_margin = double(1 << (cordic.Out_I - 1)) * 3. / 100.; // Internal scaling creates noise + constexpr double abs_margin = double(1 << (cordic_rom::Out_I - 1)) * 3. / 100.; // Internal scaling creates noise // Executing the encoder for (unsigned iter = 0; iter < n_lines; iter++) {