All posts by goodbits

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.

Then:

Oh wait linux generally doesn’t include /usr/local/lib by default from any ld.so 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

Where?

Must be that and:

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

Docs:

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.

Try:

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 c_api_test.cc and c_test_util.cc 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:

Notes:

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

Building an Apple OSX Kernel Module With CMake – C/C++

If you google around about how to build an osx kext you will find very few results, a few email messages saying not to bother or that it it impossible.

So what’s all the voodoo about.  A few defines, some linker options, some compiler options. Also a special info.c file and Info.plist.

Note: if you want to sign your kernel module you will need to apply to apple for a special kernel module code signing certificate.

Setup basic cmake project. We need 3.8 or newer to use BUNDLE_EXTENSION for the .kext bundle type.

Setup some variables for later. These are both optional if you use the default system sdk or you don’t want to code sign.

Add a debug preprocessor def. This is optional.

Add the special preprocessor defines to access internal kernel structures.

Add include directories for osx kernel headers and private headers.

Add an executable bundle target.

Set the target bundle extension to “kext” and the plist file.

Set a million compile options.  These were taken from a minimal xcode project.

Note: The -mmacosx-version-min=10.10 can be removed or changed to support older versions of OSX.

 

Add the libraries required for the kernel module and linker options.

Note: The -mmacosx-version-min=10.10 can be removed or changed to support older versions of OSX.

Add a custom target to sign the kernel module.  This can be skipped if code signing isn’t needed.

The example.c file:

The example_info.c File.  This is usually generated by xcode during the build process.

It just sets the main entry points to example_start and example_stop

 

The complete cmake file.

The magic Info.plist file.  All references to “example” will need to match the binary and com.example items.

 

GitHub Repository with the example.

 

 

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

Cocos2dx Binary Project Mac OSX – binary template not found

Trying to build cocos2d-x-3.13.1 with a binary template for mac os x?

Problem:

Solution:

Build the prebuilt libraries:

Build the templates

Now it works.

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

Android Studio Mac Extremely Slow

Downloaded the latest Android Studio:  2.1.3 for mac and it won’t boot or run anything.

Seems first off you need to run the emulator on sudo or it will segfault.  After launching from Android Studio you see it tried to run something like: /Users/user/Library/Android/sdk/tools/emulator -netdelay none -netspeed full -avd Galaxy_Nexus_API_22. end then segfaults.

Copy the command and run:

So now it doesnt’ boot or appears to boot but takes days… you reboot because you can’t kill the thing either.  Maybe you have installed Virtual Box on you machine at some point and it turns out the kernel modules form virtual box interfere with the intel/google/android emulator( com.intel.kext.intelhaxm )

Solutions:

Uninstall VirtualBox…

Or

Enjoy the still slow emulator but it seems to work…

 

 

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

How to detect if your system tray icon has gone missing, C/C++, Win32

The Problem:

Sometimes if either the desktop crashes or windows decides to go wrong for whatever reason, it re-creates the system tray. There is no way to detect when that happens and your icon is now missing but your system tray application is still running.

The Solution:

Windows does send a windows message to be notified when the system tray is being created.  It won’t be sent to you unless you register to receive it.

To register to receive the message do the following and store the ID that is returned. The simplest way to do this is to store it in a global variable.

Then later on in your windows message loop handle the message.

 

Related Links

Related Searches

  • how to detect if the system tray is gone msdn
  • how to detect if the system tray is gone
  • systray icon restart after explore.exe crashes
  • catch explore restart message msdn
  • win32 message for when explorer.exe starts msdn
  • windows message for when explorer.exe starts msdn
  • systray icon dissapears after sleep
  • windows message for when system awakes from sleep
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisShare on RedditShare on StumbleUpon

How to get rid of unwanted directories from an subversion checkout

The Problem

Using svn if you’ve checked out a tree but didn’t want the entire tree how can you get rid of some of the subfolders.  This is generally a problem if there are some really big folder slowing down diff or other operations in the tree.

Example

You have checked out http://server/trunk but there is a gigantic folder that was checked out and you want to remove it from the checkout but not svn continues to annoy you saying that you’ve deleted it. Further if you simply delete the folder it will show as deleted every time run svn diff.

Resulting in

The Solution

If That Doesn’t Work

The folder will still be there but it will not cause problems with everyday life.

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