Category Archives: C

Google Tensor Flow In C On Fedora Linux

Decided to have a look at google tensor flow to see what all the hype is about.

Reading the first page of how to install under Linux just blew my mind. Nice work google.

So apparently you are supposed to run this:

Okay that works.


Oh wait linux generally doesn’t include /usr/local/lib by default from any conf configuration. Well, at least Fedora doesn’t.

Easy fix:

Then they say to run:

Hmm okay, that will never work. What magic voodoo will make that function appear for the linker:

Right to add the lib:

And then run it like google says:

Hey google guess what, linux doesn’t generally have the current directory in the path. What kind of weird linux are you running?

Maybe try:

Wowzer it works.

Google is usually good about their docs.  What happened?  Too many pythons?

Okay so how to use this thing in C?

Oh wait there aren’t any docs for the c library.

Check the header.. that doesn’t look too promising.

Check github project page. Hmm not much there.

So back to the Getting Started python tutorial. See if it can work in C?

Attempt Digging Through c_api.h

Good news the header has a lot of documentation.

The Computational Graph

Found this:

And This:

Must be on to something.

A Tensor


Must be that and:

So how can I get those numbers from the example in there.


So looking for a float holding tensor.

Have this now so far:

Quick valgrind check.

Bunch of leaks.. need to shut something down.

Can’t seem to find a shutdown/free/.. anything.. leave that for later.

Getting Some Output

Need A Session

Found this that must be it, but I need a graph and options to make one??

Okay says something about NULL being ok.


Boom segfault.

So probably the first parameter is the most important.. Try to make a graph.

Nope still segfaults.

Try making options.

Nope still segfaults.

K it’s happy now.. no more crashing.

And clean all those up.

Running exiting ok now.

Run The Session?

That must be it.

Looks like some TF_Operations and array of TF_Sensors for I/O.

After not finding many examples and many attempts at different guesses and reading the test code in and I’ve managed to add two numbers together.

The output tensor is allocated by session run so it has been removed.

The final extremely basic C example

To build and run:


The underlying library is written C++ so there is really no point in doing this unless you have some C code that needs to integrate with tensor flow from their.

Valgrind still finds some left over memory from pthread_create. Couldn’t figure away to clean up the lib completely.  Doesn’t seem to be any function join the internal threads.






Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisShare on RedditShare on StumbleUpon