Compile Tensorflow programs with custom compiler - tensorflow

I'm trying to compile a very simple Tensorflow program (which only prints the Tensorflow version) with my company's c compiler but the libtensorflow.so I downloaded from Tensorflow's offical website is incompatible with our c compiler.
My company's c compiler is pretty much just a standard gcc but gcc can compile the program and our custom compiler cannot.
My colleague told me I have two options: (1) replace Bazel's compiler with our compiler and use Bazel to compile the program or (2) Compile the program with Bazel first then compile the program using our compiler and include the pb.h files generated by Bazel (because those bazel files can only be generated by Bazel).
I'm not sure how to do (!) but I tried (2). The problem with (2) is I got erros saying the protoc was generated by an older version and I'm not sure how to change to the right version.
Some additional information: (1) The OS is Linux, (2) I do not have the privilege to use sudo commands, (3) I cannot access system directories (e.g. /usr/local)
Is there any hope I can make this work? You may ask why not just build the program with Bazel. It's because our company's program needs to be run by our company's simulator and the simulator only accepts program generated by our company's compiler.

Your only option is to build tensorflow with Bazel, and tell Bazel to use your C/C++ compiler. The easiest way is to set the CC and CXX environment variables to point to your compiler's executable. If it is really a drop-in replacement of GCC, then it should work and after building you should get a tensorflow binary compiled with your custom compiler.
If special flags are needed then you should make a custom toolchain in Bazel to tell it how to use your compiler, it is a bit complex but not much. Instructions for that are at https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain

Related

Can I remove gcc compiler after tensorflow installation?

I'm sorry if this is not the right place to ask this. If it is not, let me know and I'll close this question.
I'm trying to set up an environment for a bot we are working on, and part of that will require installing gcc on a server so we can install tensorflow. However, my company has decided that compilers are unsafe, so part of the process for production will require removing the compiler from the server after a set amount of time. After tensor flow is installed, will it be safe to remove the gcc compiler from the server, or will it break my installation?
Provided that tesnorflow itself does not invoke gcc during operation, it should be safe. Unless shared libraries tensorflow depends on are removed with it (can happen if you system packages them as part of the gcc package -- e.g. libstdc++, libgomp, etc).
I'd recommend checking tensorflow executables with ldd -r to find out (after removing gcc -- or query the package manager whether any of the output libraries is owned by the gcc package).

Creating a build environment to build Tensorflow apps with cmake

I am wondering if there is a definitive recipe for using cmake to build tensorflow and tensor for apps. I followed the instructions at https://github.com/cjweeks/tensorflow-cmake without much success and ended up having to build Eigen and Protobuf by hand and then copy relevant headers files into the the header file tree created by the Bazel build of Tensorflow.
I just built TF with CMake, VS2017, and CUDA 9.2, but had to make two manual changes:
Patch Half.h in Eigen
Change CUDA version from "9.0" to "9.2" in the main CMakeLists.txt.
Build has to be single threaded, otherwise VS runs out of heap (on my 16GB laptop). It takes a while and one project fails, but builds enough libraries to run all the examples I wanted.
Another problem with CMake build, vs. Bazel, is that the former rebuilds a bunch of projects (involving protobuf generated files) even when nothing there changes. Bazel is smarter and only compiles the changed code, then statically links all object files into a single executable, which is still faster than CMake build.

Can DIAB compiler produce VXE without VxWorks?

I have wrote a small application in C on VxWorks 6.9 evaluation. It uses sample code and makefile from windriver/target/usr/apps/samples. I would like to compile it for other platforms beside Intel.
I have downloaded DIAB compiler evaluation which comes with an impressive list of targets, however I have issues compiling my app, especially because it's missing make rules from target/usr/make etc.
What are my options to compile a RTP/VXE without VxWorks?
Or should I install DIAB evaluation on top of VxWorks Evaluation?
Thanks!

using Diab, dcc 5.9.4 to compile a windows executable

I'm doing some experiments with an evaluation version of the WindRiver dcc diab compiler. I would like to do some testing on my Windows PC.
However I think I have the wrong target setup.
I've got as far as using the 'dctrl -t' command to get the list of target architectures, but selecting options so far hasn't produced anything i can run on windows.
I'm simply doing:
dcc main.c -o main.exe
Am I missing a step?
do I have the wrong target?
or is it simply not possible to create windows binaries?
I believe that the Diab compiler targets a free-standing environment, so would not produce a Windows executable. Moreover x86 is not a supported target processor in any case; see the product brief.
The compiler is intended for use with VxWorks, though can be separately licensed. The toolchain includes an instruction-set simulator for executing target code in a simulated environment, and if you are using VxWorks, that includes a VxWorks simulator.
If you want to build your code as a native Windows application; you will have to use a Windows targeted compiler. I suggest MinGW/GCC since WindRiver support both their own WindRiver/Diab compiler and GCC for Vxworks development, and they share a great deal of commonality with respect to compiler switches and extension syntax.

Mono to Emscripten

Mono has a LLVM compiler. Is there anyway to use it with Emscripten (compile C# code to JavaScript)?
There is currently no out of the box way to do this. It might be possible, but it would require a lot of work. You would need to run mono in full AOT (ahead of time) compilation mode with the LLVM codegen. But there are many issues:
LLVM is currently not used for all methods, and mono falls back to it's own code generator in a number of cases. You would either need to get the LLVM suport working for all cases, or provide the JS code needed when LLVM cannot be used.
Mono currently has a number of architecture specific files (x86, amd64, arm, etc) and would probably need equivalent for JS, both for the code generation and for the AOT runtime.
And so on...
you can try to use C# Native
have a look here http://csnative.codeplex.com
Even if you run mono in full AOT and compile your program with LLVM it is not possible to use it with emscripten. This is quote from my discussion in mono group:
Besides that, no, it's not possible to use emscripten with mono's llvm output for a lot of reasons.
The output embeds calls to the mono runtime and some trampilines.
Mono use a custom LLVM with custom IR operations and that won't work on emscripten without some work on their end.