fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.28k stars 413 forks source link

Unable to run example model in Vivado hls2018.3 #181

Closed pentapatisivani closed 4 years ago

pentapatisivani commented 4 years ago

I tried running the example project by adding all files in nnet_utils in my project but still I am getting this error of datatype mismatch while running synthesis even build.tcl isnt working. How exactly can we include hls4ml in vivado hls? ERROR: [HLS 200-70] Compilation errors found: In file included from Gnet/files/myproject.cpp:1: In file included from Gnet/files/myproject.cpp:21: In file included from Gnet/files/parameters.h:7: In file included from Gnet/files/nnet_dense.h:24: Gnet/files/nnet_helpers.h:177:1: error: unknown type name 'constexpr' constexpr int ceillog2(int x){ ^ Gnet/files/nnet_helpers.h:177:11: error: expected unqualified-id constexpr int ceillog2(int x){ ^ Gnet/files/nnet_helpers.h:181:1: error: unknown type name 'constexpr' constexpr int pow2(int x){ ^ Gnet/files/nnet_helpers.h:181:11: error: expected unqualified-id constexpr int pow2(int x){ ^ In file included from Gnet/files/myproject.cpp:1: In file included from Gnet/files/myproject.cpp:21: In file included from Gnet/files/parameters.h:7: Gnet/files/nnet_dense.h:56:22: error: no template named 'enable_if' in namespace 'std'; did you mean '_ap_type::enable_if'? inline typename std::enable_if<std::is_same<data_T, ap_uint<1>>::value


                     _ap_type::enable_if
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_common.h:190:8: note: '_ap_type::enable_if' declared here
struct enable_if {};
       ^
In file included from Gnet/files/myproject.cpp:1:
In file included from Gnet/files/myproject.cpp:21:
In file included from Gnet/files/parameters.h:7:
Gnet/files/nnet_dense.h:56:37: error: no member named 'is_same' in namespace 'std'
inline typename std::enable_if<std::is_same<data_T, ap_uint<1>>::value
                               ~~~~~^
Gnet/files/nnet_dense.h:56:45: error: 'data_T' does not refer to a value
inline typename std::enable_if<std::is_same<data_T, ap_uint<1>>::value
                                            ^
Gnet/files/nnet_dense.h:55:16: note: declared here
template<class data_T, class weight_T, class ret_T>
               ^
Gnet/files/nnet_dense.h:65:1: error: expected unqualified-id
inline typename std::enable_if<(not std::is_same<data_T, ap_uint<1>>::value)
^
In file included from Gnet/files/myproject.cpp:1:
Gnet/files/myproject.cpp:66:8: error: no member named 'conv_2d' in namespace 'nnet'
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
 ~~~~~~^
Gnet/files/myproject.cpp:66:16: error: unexpected type name 'input_t': expected expression
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
               ^
Gnet/files/myproject.cpp:66:25: error: unexpected type name 'result_t': expected expression
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
                        ^
Gnet/files/myproject.cpp:66:35: error: 'config1' does not refer to a value
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
                                  ^
Gnet/files/parameters.h:39:8: note: declared here
struct config1 : nnet::conv2d_config {
       ^
In file included from Gnet/files/myproject.cpp:1:
Gnet/files/myproject.cpp:66:44: warning: expression result unused [-Wunused-value]
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
                                           ^~~~
Gnet/files/myproject.cpp:66:50: warning: expression result unused [-Wunused-value]
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
                                                 ^~~~~~~~~~
Gnet/files/myproject.cpp:66:62: warning: expression result unused [-Wunused-value]
 nnet::conv_2d<input_t, result_t, config1>(data, layer1_out, w1, b1);
                                                             ^~
Gnet/files/myproject.cpp:81:8: error: no member named 'dense' in namespace 'nnet'
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
 ~~~~~~^
Gnet/files/myproject.cpp:81:14: error: unexpected type name 'input_t': expected expression
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
             ^
Gnet/files/myproject.cpp:81:23: error: unexpected type name 'result_t': expected expression
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
                      ^
Gnet/files/myproject.cpp:81:33: error: 'config2' does not refer to a value
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
                                ^
Gnet/files/parameters.h:73:8: note: declared here
struct config2 : nnet::dense_config {
       ^
In file included from Gnet/files/myproject.cpp:1:
Gnet/files/myproject.cpp:81:42: warning: expression result unused [-Wunused-value]
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
                                         ^~~~~~~~~~~~~~~~~~~~
Gnet/files/myproject.cpp:81:64: warning: expression result unused [-Wunused-value]
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
                                                               ^~~~~~~
Gnet/files/myproject.cpp:81:73: warning: expression result unused [-Wunused-value]
 nnet::dense<input_t, result_t, config2>(layer1_out_flat_relu, logits2, w2, b2);
                                                                        ^~
In file included from Gnet/files/myproject.cpp:1:
In file included from Gnet/files/myproject.cpp:21:
In file included from Gnet/files/parameters.h:5:
In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_int.h:349:
In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed.h:55:
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:837:13: warning: shift count is negative [-Wshift-count-negative]
      ret.V <<= (_AP_I - _AP_W);
            ^   ~~~~~~~~~~~~~~~
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:868:69: note: in instantiation of member function 'ap_fixed_base<52, 42, true, 5, 3, 0>::to_ap_int_base' requested here
  inline __attribute__((always_inline)) int to_int() const { return to_ap_int_base().to_int(); }
                                                                    ^
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:1041:71: note: in instantiation of member function 'ap_fixed_base<52, 42, true, 5, 3, 0>::to_int' requested here
  inline __attribute__((always_inline)) operator int() const { return to_int(); }
                                                                      ^
Gnet/files/nnet_activation.h:252:17: note: in instantiation of member function 'ap_fixed_base<52, 42, true, 5, 3, 0>::operator int' requested here
   data_round = (data_cache[jj]-data_cache[ii])*CONFIG_T::table_size/16;
                ^
Gnet/files/myproject.cpp:84:5: note: in instantiation of function template specialization 'nnet::softmax<ap_fixed<18, 8, 5, 3, 0>, ap_fixed<18, 8, 5, 3, 0>, softmax_config2>' requested here
    nnet::softmax<result_t, result_t, softmax_config2>(logits2, res);
    ^
In file included from Gnet/files/myproject.cpp:1:
In file included from Gnet/files/myproject.cpp:21:
In file included from Gnet/files/parameters.h:5:
In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_int.h:349:
In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed.h:55:
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:837:13: warning: shift count is negative [-Wshift-count-negative]
      ret.V <<= (_AP_I - _AP_W);
            ^   ~~~~~~~~~~~~~~~
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:868:69: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::to_ap_int_base' requested here
  inline __attribute__((always_inline)) int to_int() const { return to_ap_int_base().to_int(); }
                                                                    ^
F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:1041:71: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::to_int' requested here
  inline __attribute__((always_inline)) operator int() const { return to_int(); }
                                                                      ^
Gnet/files/nnet_activation.h:264:27: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::operator int' requested here
      int exp_res_index = exp_res[ii]*CONFIG_T::table_size/64;
                          ^
Gnet/files/myproject.cpp:84:5: note: in instantiation of function template specialization 'nnet::softmax<ap_fixed<18, 8, 5, 3, 0>, ap_fixed<18, 8, 5, 3, 0>, softmax_config2>' requested here
    nnet::softmax<result_t, result_t, softmax_config2>(logits2, res);
    ^
8 warnings and 16 errors generated.
Failed during preprocessing.
    while executing
"source C:/Users/dell/Desktop/conv/solution1/csynth.tcl"
    invoked from within
"hls::main C:/Users/dell/Desktop/conv/solution1/csynth.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 hls::main {*}$args"
    (procedure "hls_proc" line 5)
    invoked from within
"hls_proc $argv"
Finished C synthesis.
Duchstf commented 4 years ago

Hi, what specific example project are you running? Did you try following the workflow in our documentation? Or did you just copy the files over to your project?

Also, I think the example projects in master branch are quite outdated, can you try again with the examples in this repo?

Duc.

thesps commented 4 years ago

Are you integrating the NN into a larger project or just compiling the NN with hls4ml? From your error, it looks like you don't have the C++0x flag. You can see how it's used in the hls4ml build_prj.tcl file, for example: add_files firmware/myproject.cpp -cflags "-std=c++0x" If you're integrating the code into another project, you should add the -cflags "-std=c++0x" flag to your build script. Otherwise, simply use hls4ml build -p your_project -s which will use the build script we generate.

pentapatisivani commented 4 years ago

Hi, what specific example project are you running? Did you try following the workflow in our documentation? Or did you just copy the files over to your project?

Also, I think the example projects in master branch are quite outdated, can you try again with the examples in this repo?

Duc.

Thank you for mentioning about the updated repo. I ran the new tcl script directly in hls terminal to create the project I have got errors related to pre-existing files in vivado hls Screenshot (129) . How can I resolve this issue? (Attaching screenshot of result)

C SIMULATION COMPLETED IN 0h0m41s C/RTL SYNTHESIS INFO: [SCHED 204-61] Option 'relax_ii_for_timing' is enabled, will increase II to preserve clock frequency constraints. INFO: [HLS 200-10] Analyzing design file 'firmware/myproject.cpp' ... ERROR: [HLS 200-70] Compilation errors found: In file included from firmware/myproject.cpp:1: In file included from firmware/myproject.cpp:19: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\iostream:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\ostream:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\ios:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\exception:151: F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\exception_ptr.h:132:13: error: unknown type name 'type_info' const type_info ^ In file included from firmware/myproject.cpp:1: In file included from firmware/myproject.cpp:19: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\iostream:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\ostream:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\ios:39: In file included from F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\exception:151: F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:62:5: error: the parameter for this explicitly-defaulted copy constructor is const, but a member or base requires it to be non-const nested_exception(const nested_exception&) = default; ^ F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:64:23: error: the parameter for this explicitly-defaulted copy assignment operator is const, but a member or base requires it to be non-const nested_exception& operator=(const nested_exception&) = default; ^ F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:77:28: error: exception specification in declaration does not match previous declaration inline nested_exception::~nested_exception() = default; ^ F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:66:20: note: previous declaration is here inline virtual ~nested_exception(); ^ F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:122:61: error: redefinition of default argument __throw_with_nested(_Ex&& __ex, const nested_exception = 0) ^ ~ F:/apps/Vivado/2018.3/win64/tools/clang/bin..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:110:56: note: previous definition is here throw_with_nested(_Ex&&, const nested_exception* = 0) ^ ~ In file included from firmware/myproject.cpp:1: In file included from firmware/myproject.cpp:21: In file included from firmware/myproject.h:24: In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_int.h:349: In file included from F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed.h:55: F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:837:13: warning: shift count is negative [-Wshift-count-negative] ret.V <<= (_AP_I - _AP_W); ^ ~~~ F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:868:69: note: in instantiation of member function 'ap_fixed_base<49, 39, true, 5, 3, 0>::to_ap_int_base' requested here inline attribute((always_inline)) int to_int() const { return to_ap_int_base().to_int(); } ^ F:/apps/Vivado/2018.3/common/technology/autopilot\ap_fixed_base.h:1041:71: note: in instantiation of member function 'ap_fixed_base<49, 39, true, 5, 3, 0>::to_int' requested here inline attribute__((always_inline)) operator int() const { return to_int(); } ^ firmware/nnet_utils/nnet_activation.h:168:22: note: in instantiation of member function 'ap_fixed_base<49, 39, true, 5, 3, 0>::operator int' requested here data_round = data[ii]*CONFIG_T::table_size/16; ^ firmware/myproject.cpp:75:5: note: in instantiation of function template specialization 'nnet::sigmoid<ap_fixed<16, 6, 5, 3, 0>, ap_fixed<16, 6, 5, 3, 0>, sigmoid_config5>' requested here nnet::sigmoid<layer4_t, result_t, sigmoid_config5>(layer4_out, layer5_out); ^ 1 warning and 5 errors generated. Failed during preprocessing. while executing "source [lindex $::argv 1] " ("uplevel" body line 1) invoked from within "uplevel #0 { source [lindex $::argv 1] } " INFO: [Common 17-206] Exiting vivado_hls at Wed Mar 4 21:49:44 2020...

vloncar commented 4 years ago

There is a workaround here, however the side-effects of doing this are unknown since most of us don't use Windows for development.

If you have a contact within Xilinx, I would suggest also complaining about this to them. They ship a standard library that was part of a compiler from 2010, which is no longer funny, now it's just sad.

pentapatisivani commented 4 years ago

Thanks a lot! That fixed the issue and is there any reference or documentation for hls4ml to know what exactly each function is doing? For example there are two functions for conv2d conv2d_latency_cl and conv2d_latency_cf (In this repo: https://github.com/hls-fpga-machine-learning/models ). What exactly is the difference between these 2? and nnet_utils itself has many files and functions and its being difficult to understand what function does what just from the codes and there are multiple functions with similar code. Can you provide any resource with proper documentation of code. And the example models only include 4-5 functions

thesps commented 4 years ago

For the specific case conv2d_latency_cl vs conv2d_latency_cf the cl means 'Channels Last' while cf means 'Channels First'. The function which is used will be determined by the configuration of the trained model you provide.

Usually the function which gets used is controlled either by your model, as above, or your configuration file. For example we have Strategy: Latency, Strategy: Resource, Compression: {True/False}. These, together with the Reuse factor will define which function gets used to give the best balance of FPGA resources, latency and synthesizability. If you want to explore the design space it's better to try out these options in the config than to modify which function is called in the produced C++.

The best documentation for the config file parameters is https://fastmachinelearning.org/hls4ml/setup/CONFIGURATION.html

It seems like your issue is resolved, so I will close this issue.