Note: I also posted this question here https://openmodelica.org/forum/default-topic/2570-linux-mint,-python-3-6-omc-server-is-down-please-start-it and I hope to reach a larger group with tensorflow experience as well.
I want to use the Tensorflow C++ API in a Modelica Model.
For this, I created a class in C++ that encapsulates the Tensorflow details. Moreover, the same file contains 3 functions (to call the constructor, destructor and a function that uses an existing instance of my class. These functions are declared "extern" in the respective header file (only if read by a C++ compiler, I am using __cplusplus to differentiate).
I then compiled said file (the class and the 3 functions) into a .so using g++ (I did make use of -fPIC and -shared). In /usr/lib, I created a symlink to said shared object library.
(For completeness, I should mention that I had trouble with the "LibraryDirectory" and "IncludeDirectory" annotations. This is why I created symlinks to the contents of all the directories I would pass to g++/gcc using -L and -I (for my test program) right into Model/Resources/Library and Model/Resources/Include directories. As there were no more compilation errors, I thought that this was okay.)
Now the strange thing is:
I can use the 3 functions in a test program compiled with gcc. I linked it against all Tensorflow libraries (and libm, libstdc++ and my .so from above) and it just works as expected. However, when I try to use these 3 functions in a) a Modelica Class (constructor and destructor), and b) a function using an "external" function call, it will compile fine but a runtime error occurs:
stdout | OMEditInfo |
/tmp/OpenModelica_fred/OMEdit/TestCpp -port=44382 -logFormat=xmltcp -override=startTime=0,stopTime=1,stepSize=0.002,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=TestCpp_res.mat -w -lv=LOG_STATS
stdout | error |2018-11-22 10:47:00.153977: F tensorflow/core/framework/function.cc:1440] Check failed: GetOpGradFactory()->insert({op, func}).second Duplicated gradient for MapAccumulate
stdout | error |
Process crashed
stdout | error |Process crashed
Simulation process failed. Exited with code 6.
How is this possible? I am not able to do anything in my test program with the 3 functions that leads to the same error. What could the OMC-generated executable be doing with them that I am not in my test program?
I found a solution pointing the symlink "clang" in /usr/bin to "gcc".
For instructions, check https://openmodelica.org/forum/default-topic/2570-linux-mint,-python-3-6-omc-server-is-down-please-start-it .