What's the difference between tf_kernel_library and cc_library - build

I am learning bazel build to compile the tensorflow source code.
In this bazel build file, I see '''tf_kernel_library''' and '''cc_library'''.
What is the exact difference between these two?

"tf_kernel_library" is a custome rule and "cc_library" is a bazel buildin rule
"tf_kernel_library" is a rule to build a TensorFlow OpKernel. The biggest difference from "cc_library" is that "tf_kernel_library" compiles cu.cc and cu.h in addition to .cc and .h, while "cc_library" does not.
"cc_library" builds .cc and .h only for c++

Related

How do I indicate where Emscripten should locate source files during compile?

Being a Javascript programmer, I'm really not quite familiar with the compiling process. My problem is locating source files during compilation with Emscripten. My "include"-commands refer to source code, such as "Core/main.h", which in turn refers to other source files in the same folder, yet using a similar address, (e.g. "Core/app.h")
How do I overcome these "File not found" errors? How do I indicate to the Emscripten compiler that it should look in the source folder? I've been reading the documentation, but what I'm finding discusses, I think, virtual file systems for use during run time, not included directories during compilation.
It's the one argument that is the same on virtually every C/C++ compiler: -I
emcc -Idir1 -Idir2 ... foo.c
Where the file is at dir1/Core/app.h.

Cannot create the final binary using tensorflow AOT compilation for CPU backend

I followed the tutorial here: TensorFlow AOT compilation
According to Step 1 and 2, I compiled the subgraph and generated the header (test_graph_tfmatmul.h) and object (test_graph_tfmatmul.o) files;
According to Step 3, I used the example code (named as my_code.cc) to invoke the subgraph;
According to Step 4, I added the code snippet cc_binary to the existing BUILD file (//tensorflow/compiler/aot/tests/BUILD), and tried to create the final binary with the command:
bazel build //tensorflow/compiler/aot/tests:my_binary
but I got the following error:
undeclared inclusion(s) in rule '//tensorflow/compiler/aot/tests:my_binary':
this rule is missing dependency declarations for the following files included by 'tensorflow/compiler/aot/tests/tfcompile_test.cc':
'/home/tensorFlow_src/tensorflow/tensorflow/compiler/aot/tests/test_graph_tfmatmul.h'
Any advice is welcome. Thanks.
This problem is finally figured out by using tf_library to build the cc_library in Step 2, instead of using tfcompile directly. I.e., tf_library will run tfcompile to generate the header and object files.
Please refer to https://github.com/tensorflow/tensorflow/issues/13482 for more detailed information.
Bazel complaints that in the tfcompile_test.cc you #include "tensorflow/compiler/aot/tests/test_graph_tfmatmul.h", but there is no dependency providing that header declared in the BUILD file. Did you add ":test_graph_tfmatmul" into the deps of my_binary?

Compiled file tells makefile how to compile

What I am asking might sound illogical but it is very important for me.
Lets assume we have such file and folders
project_rat/
project_cat/
project_rabbit/
Makefile
The user might add any project folder here. The Makefile has the following config variable:
model_name:= project_rat
The user might change this model_namevariable to any of the folders.
and the makefile compiles the appropriate project folder.
g++ -std=c++11 $(model_name)/main.cpp
Now my problem is that I want to add a debug/release variable into the Makefile and based on that I turn on the appropriate optimizer. I want this variable be determined from my project. It must depend on each individual project. One project might need -O2 and the other -O3.
Can I influence Makefile from any C++ code?
Assuming that you're using GNU make (a safe bet, given your usage of gcc), add this to your Makefile:
include $(model_name)/Makefile.opts
Now, create a file Makefile.opts in each project directory, that sets the Makefile options for that project.
This works just like the C/C++ #include preprocessor directive.
If you do not want to require a Makefile.opts in each project directory, use sinclude instead of include.

Eclipse CDT - How to build googletest unit tests as a separate project?

I have two projects. One called projectA and the other called projectA-tests.
The first project is my actual project, and the second project contains GoogleTest unit tests for classes in projectA.
I have coded one very simple unit test so far and everything builds OK. Note that this first simple test depends on a single .h file of projectA that has only a static class method defined in the same .h file (no .cpp file). It's actually a "StringUtils" class with methods like ::startsWith() and so on.
After adding a second test I'm having linking problems. This second test depends con a Class of projectA that is declared in a .h file and defined in a .cpp file. I'm getting an undefined reference regarding this Class, trying to build this second test.
projectA-tests compiler settings are configured to include projectA/src in project -> properties -> C/C++ build -> settings -> C++ compiler -> includes. (I guess this is why the first compiles ok, because it only requires a .h file which is covered by this "includes" setting).
What I don't know is how to configure the C++ linker in projectA-test to include all .o files of projectA in the linkage process.
I'm more experienced in Java, and the equivalent would be simply adding the other project source folder as dependency of the build path. Whay is Eclipse CDT's C++ equivalent?
Thanks!

Using alglib without compiling every time

I'm using some methods from the c++ AlgLib library. In other libraries I've used there were some instructions for installation, after which I could include .h files and compile with -l (e.g. using the GMP-library and compiling with -lgmp). However with alglib the only thing I've been able to get running is using a makefile and compiling all needed .cpp files - every time I compile my program. Here is an example of a makefile:
all:
g++ name.cpp ap.cpp integration.cpp interpolation.cpp alglibinternal.cpp linalg.cpp
alglibmisc.cpp specialfunctions.cpp solvers.cpp optimization.cpp -o name
As compiling all these files every time is relatively time consuming, is there a way to avoid it?
You can use the make feature.
Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files.
View the page: http://www.gnu.org/software/make/ to use this tool.