I am trying to implement an MLP using HLS4ML following the tutorial https://github.com/Gabriele-bot/PYNQ_IA/blob/main/NN_train/MNIST_Test/MNIST_CNN_train.ipynb
The command to synthesize the generated C files
hls_model.build(csim=False,synth=True,export=True)
produces the error
error: use of overloaded operator '<<' is ambiguous (with operand
types 'basic_ostream<char, std::char_traits >' and 'const T_in'
(aka 'const ap_fixed<8, 3>'))
I have tried synthesizing the design using Vivado HLS 2018.3 and 2020.1. But both produces similar error. Has anybody experienced and resolved such errors with HLS4ML generated codes?
The failed synthesis report shows a long list of candidates, such as the following:
ERROR: [HLS 200-70] Compilation errors found: In file included from
firmware/myproject_axi.cpp:1: In file included from
firmware/myproject_axi.cpp:1: firmware/myproject_axi.h:17:35: error:
use of overloaded operator '<<' is ambiguous (with operand types
'basic_ostream<char, std::char_traits >' and 'const T_in' (aka
'const ap_fixed<8, 2>'))
{ return stream << "{ data: " << in.data << ", last: " << in.last << " }" << std::endl; }
~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~
/tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:166:7:
note: candidate function
operator<<(long __n)
^
/tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:170:7:
note: candidate function
operator<<(unsigned long __n)
^ /tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:174:7:
note: candidate function
operator<<(bool __n)
I am also attaching a screen capture of the myproject_axi.h file which is creating the issue.
Related
I'm using Clang 14 (on Apple M1), which has full support for C++ 17, and I'm trying to utilize the new to_chars function. Here's my very simple test file:
#include <charconv>
#include <iostream>
int main() {
char a[10];
double pi = 3.141592;
std::to_chars_result res = std::to_chars(a, a+10, pi);
*res.ptr = '\0';
std::cout << a << std::endl;
}
My compile command is clang -std=c++17 test_to_chars.cpp, and the output is below:
test_to_chars.cpp:8:30: error: call to deleted function 'to_chars'
std::to_chars_result res = std::to_chars(a, a+10, pi);
^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/charconv:166:6: note: candidate function has been explicitly deleted
void to_chars(char*, char*, bool, int = 10) = delete;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/charconv:450:1: note: candidate template ignored: requirement 'is_integral<double>::value' was not satisfied [with _Tp = double]
to_chars(char* __first, char* __last, _Tp __value)
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/charconv:458:1: note: candidate function template not viable: requires 4 arguments, but 3 were provided
to_chars(char* __first, char* __last, _Tp __value, int __base)
^
test_to_chars.cpp:8:24: error: no viable conversion from 'void' to 'std::to_chars_result'
std::to_chars_result res = std::to_chars(a, a+10, pi);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/charconv:154:25: note: candidate constructor (the implicit copy constructor) not viable: cannot convert argument of incomplete type 'void' to 'const std::to_chars_result &' for 1st argument
struct _LIBCPP_TYPE_VIS to_chars_result
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/charconv:154:25: note: candidate constructor (the implicit move constructor) not viable: cannot convert argument of incomplete type 'void' to 'std::to_chars_result &&' for 1st argument
2 errors generated.
I'm calling to_chars(char*, char*, double) but for some reason it's using an implicit conversion and trying to call to_chars(char*, char*, bool, int = 10) instead, which is a deleted function.
Is there a way for me to tell C++ that I don't want it to convert my double parameter to a bool?
I'm using Clang 14 (on Apple M1), which has full support for C++ 17
This is unfortunately not correct. While the compiler itself has full C++17 support, the stdlib of your clang version (Apple clang 14) does not implement any floating point charconv features.
See the entry "Elementary string conversions" in the cppreference table.
It is important to note that you are not running "clang 14", but "Apple clang 14". Your code snippet compiles just fine on normal clang 14.
I'm getting an error when I try to query an object using a string variable, but not when I directly use a string.
JSON:
{"x": "hello"}
This works:
std::cout << document["x"].GetString();
This doesn't work:
std::string s = "x";
std::cout << document[s].GetString();
I'm getting this error:
error: no viable overloaded operator[] for type 'rapidjson::Document'
(aka 'GenericDocument<UTF8<> >')
std::cout << document[s].GetString();
~~~~~^~
note: candidate function not viable: no known conversion from 'std::string'
(aka 'basic_string<char, char_traits<char>, allocator<char> >') to 'SizeType'
(aka 'unsigned int') for 1st argument
What am I doing wrong?
Try
std::cout << document[s.c_str()].GetString();
It seems the operator was not overloaded for a std::string but for a C-string.
(Reference for the c_str member function)
I'm exploring compiler writing with Flex, Bison and LLVM (latest versions of all) using this example: http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/
Github source is on the last page of that link. I can't get it to compile and any help would be appreciated.
Unfortunately for me, the solution is non-obvious.
Here are the errors:
In file included from codegen.cpp:2:
In file included from ./codegen.h:8:
In file included from /usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManager.h:46:
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManagerInternal.h:298:12: error: use of undeclared identifier 'make_unique'
return make_unique<ResultModelT>(Pass.run(IR, AM));
^
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManagerInternal.h:298:24: error: unexpected type name 'ResultModelT': expected expression
return make_unique<ResultModelT>(Pass.run(IR, AM));
^
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManagerInternal.h:336:12: error: use of undeclared identifier 'make_unique'
return make_unique<ResultModelT>(Pass.run(IR));
^
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManagerInternal.h:336:24: error: unexpected type name 'ResultModelT': expected expression
return make_unique<ResultModelT>(Pass.run(IR));
^
codegen.cpp:36:24: error: no matching conversion for functional-style cast from 'unique_ptr<llvm::Module>' to 'llvm::EngineBuilder'
ExecutionEngine *ee = EngineBuilder( unique_ptr<Module>(module) ).create();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/anaconda/include/llvm/ExecutionEngine/ExecutionEngine.h:493:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion
from 'unique_ptr<llvm::Module>' to 'llvm::EngineBuilder' for 1st argument
class EngineBuilder {
^
/anaconda/include/llvm/ExecutionEngine/ExecutionEngine.h:493:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion
from 'unique_ptr<llvm::Module>' to 'const llvm::EngineBuilder' for 1st argument
/anaconda/include/llvm/ExecutionEngine/ExecutionEngine.h:525:3: note: candidate constructor not viable: no known conversion from 'unique_ptr<llvm::Module>'
to 'llvm::Module *' for 1st argument
EngineBuilder(Module *m) : M(m) {
^
codegen.cpp:131:49: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid'
[-Wpotentially-evaluated-expression]
std::cout << "Generating code for " << typeid(**it).name() << endl;
^
In file included from codegen.cpp:2:
In file included from ./codegen.h:8:
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManager.h:207:22: error: no member named 'getName' in 'llvm::Module'
<< IR.getName() << "\n";
~~ ^
codegen.cpp:30:5: note: in instantiation of member function 'llvm::PassManager<llvm::Module>::run' requested here
pm.run(*module);
^
In file included from codegen.cpp:2:
In file included from ./codegen.h:8:
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManager.h:517:20: error: no member named 'getName' in 'llvm::Module'
<< IR.getName() << "\n";
~~ ^
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManager.h:372:28: note: in instantiation of member function
'llvm::AnalysisManager<llvm::Module>::invalidateImpl' requested here
return derived_this()->invalidateImpl(IR, std::move(PA));
^
/usr/local/Cellar/llvm/3.8.1/include/llvm/IR/PassManager.h:217:22: note: in instantiation of member function
'llvm::detail::AnalysisManagerBase<llvm::AnalysisManager<llvm::Module>, llvm::Module>::invalidate' requested here
PassPA = AM->invalidate(IR, std::move(PassPA));
^
codegen.cpp:30:5: note: in instantiation of member function 'llvm::PassManager<llvm::Module>::run' requested here
pm.run(*module);
^
Well, there is llvm::make_unique in include/llvm/ADT/STLExtras.h. You have not stated if you are writing your own code based on llvm source or compiling llvm or what but I assume llvm::make_unique is there exactly for that reason to fill the missing pieces of C++11.
Moreover, looking at the tutorials it seems that llvm::make_unique is explicitly used everywhere.
Update
So I successfully build the given example against LLVM 3.9.0 from svn. I had to change and fix all the calls to getGlobalContext() since that is gone in LLVM 3.9.0, but I did not encounter any make_unique related issues. However the example itself is a bit broken. codegen.h is missing an include guard, codegen.cpp is missing an include to #include "llvm/IR/LLVMContext.h", even if it wants to use the old getGlobalContext() method. I did this on Windows with MSVC 2015, can you specify your environment and compiler so that I can try the same?
I tried the latest nana (1.1.2/1.1.3) downloaded from Github. The library compiles fine. When I try to compile and link any sample program, with linux (gcc 4.8.4, clang 3.4) I get the following errors:
enter In file included from /installs/nana/include/nana/gui/wvl.hpp:20:
In file included from /installs/nana/include/nana/gui/widgets/form.hpp:16:
In file included from /installs/nana/include/nana/gui/widgets/widget.hpp:17:
/installs/nana/include/nana/internationalization.hpp:69:7: error: invalid operands to binary expression ('std::wstringstream' (aka 'basic_stringstream<wchar_t>') and 'nana::string' (aka 'basic_string<char>'))
ss << nana::string(nana::charset(arg));
~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8 /system_error:186:5: note: candidate function [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>] not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to 'const std::error_code' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:108:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to '__ostream_type &(*)(__ostream_type &)' for 1st argument
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:117:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to '__ios_type &(*)(__ios_type &)' for 1st argument
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:127:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to 'std::ios_base &(*)(std::ios_base &)' for 1st argument
operator<<(ios_base& (*__pf) (ios_base&))
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:166:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to 'long' for 1st argument
operator<<(long __n)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:170:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to 'unsigned long' for 1st argument
operator<<(unsigned long __n)
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:174:7: note: candidate function not viable: no known conversion from 'nana::string' (aka 'basic_string<char>') to 'bool' for 1st argument
operator<<(bool __n)here
CMAKE:
cmake_minimum_required(VERSION 3.2)
project(nana_ui)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11
-DSTD_CODECVT_NOT_SUPPORTED")
SET(NANA_BASE "/installs/nana")
include_directories(${NANA_BASE}/include
/usr/include/freetype2)
link_directories(${NANA_BASE}/lib)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${NANA_BASE}/lib/libnana.a
X11 pthread rt Xft png asound)
Example cpp:
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
int main()
{
using namespace nana;
form fm;
label lb(fm, fm.size());
lb.caption(L"Hello, World");
fm.show();
exec();
}
Any Help is appreciated.
Adding #define NANA_UNICODE in config.hpp, then recompile the library and examples
I'm trying to execute this code nmea2kml.cpp
but I keep getting the following errors. Also the program has command line parameters -f path Read file at given path (e.g. /some/where/nmea.txt) What should I change to run the program? Am I getting the error due to a compiler problem? coz I've messed up with adding cygwin, MinGW compilers to eclipse!! I know the program is correct. Others have used it and got the results.(http://julien.cayzac.name/code/gps/)
Error
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\nmea.o ..\src\nmea.cpp
..\src\nmea.cpp: In function `int main(int, char**)':
..\src\nmea.cpp:195: error: no match for 'operator<' in 'std::cerr < "Converting file \""'
..\src\nmea.cpp:195: note: candidates are: operator<(const char*, const char*) <built-in>
..\src\nmea.cpp:195: note: operator<(void*, void*) <built-in>
..\src\nmea.cpp:336: error: no match for 'operator<' in 'std::cout < "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"'
..\src\nmea.cpp:336: note: candidates are: operator<(const char*, const char*) <built-in>
..\src\nmea.cpp:336: note: operator<(void*, void*) <built-in>
..\src\nmea.cpp:336: error: `std::endl(std::basic_ostream<_CharT, _Traits>&)' cannot appear in a constant-expression
..\src\nmea.cpp:355: error: parse error in template argument list
..\src\nmea.cpp:336: error: `endl<<expression error> >' cannot appear in a constant-expression
..\src\nmea.cpp:406: error: parse error in template argument list
..\src\nmea.cpp:336: error: `endl<<expression error> >' cannot appear in a constant-expression
..\src\nmea.cpp:406: error: parse error in template argument list
..\src\nmea.cpp:336: error: `endl<<expression error> >' cannot appear in a constant-expression
..\src\nmea.cpp:406: error: parse error in template argument list
..\src\nmea.cpp:406: error: expected `;' before '}' token
..\src\nmea.cpp:193: warning: unused variable 'outfile'
Build error occurred, build is stopped
It looks like you have written std::cerr < "..." (the < operator) where you meant to write std::cerr << "..." (the << operator).
Try using the bit-shift "<<" instead of the less-than "<" operator with your ostreams:
std::cerr << "Converting file \"";
No, the code as shown is not correct. You perform output with std::cout << ..., not std::cout < .... Probably some HTML conversion messed it up.