Cmake Tensorflow

Integrate TensorFlow with CMake projects effortlessly. TensorFlow is an amazing tool for machine learning and intelligence using computational graphs. TensorFlow includes APIs for both Python and C, although the C API is slightly less documented. TensorFlow CMake/C Collection. Looking at the official docs: What do you see? Now, guess what: This is a bazel-free zone. We use CMake here! This collection contains reliable and dead-simple examples to use TensorFlow in C, C, Go and Python: load a pre-trained model or compile a custom operation with or without CUDA.

  1. Cmake Tensorflow Windows
  2. Tensorflow C++ Cmake

This directory contains CMake files for building TensorFlow on MicrosoftWindows. CMake is a cross-platform tool that cangenerate build scripts for multiple build systems, including MicrosoftVisual Studio.

N.B. We provide Linux build instructions primarily for the purpose oftesting the build. We recommend using the standard Bazel-based build onLinux.

Current Status¶

Tensorflow cmake buildCmake

The CMake files in this directory can build the core TensorFlow runtime, anexample C++ binary, and a PIP package containing the runtime and Pythonbindings.

Note: Windows support is in an alpha state, and we welcome your feedback.

Pre-requisites¶

  • CMake version 3.1 up to 3.6
  • Additional pre-requisites for Microsoft Windows:
    • Visual Studio 2015
    • Python 3.5
    • NumPy 1.11.0 or later
  • Additional pre-requisites for Linux:
    • Python 2.7 or later
    • Docker (for automated testing)
    • NumPy 1.11.0 or later

Known-good configurations¶

Cmake
  • Microsoft Windows 10
    • Microsoft Visual Studio Enterprise 2015 with Visual C++ 2015
    • [NVidia CUDA Toolkit 8.0] (https://developer.nvidia.com/cuda-downloads)
    • [NVidia CUDNN 5.1] (https://developer.nvidia.com/cudnn)
  • Ubuntu 14.04
    • Makefile generator
    • Docker 1.9.1 (for automated testing)

Current known limitations¶

Cmake tensorflow windows
  • The Python package supports Python 3.5 only, because that is the onlyversion for which standard Python binaries exist and those binaries arecompatible with the TensorFlow runtime. (On Windows, the standard Pythonbinaries for versions earlier than 3.5 were compiled with older compilersthat do not have all of the features (e.g. C++11 support) needed to compileTensorFlow. We welcome patches for making TensorFlow work with Python 2.7on Windows, but have not yet committed to supporting that configuration.)
  • The following Python APIs are not currently implemented:
    • Loading custom op libraries via tf.load_op_library(). In order to use yourcustom op, please put the source code under the tensorflow/core/user_opsdirectory, and a shape function is required (not optional) for each op.
    • Path manipulation functions (such as tf.gfile.ListDirectory()) are notfunctional.
  • The tf.contrib libraries are not currently included in the PIP package.
  • The following operations are not currently implemented:
    • DepthwiseConv2dNative
    • Digamma
    • Erf
    • Erfc
    • Igamma
    • Igammac
    • ImmutableConst
    • Lgamma
    • Polygamma
    • Zeta
  • Google Cloud Storage support is not currently implemented. The GCS librarycurrently depends on libcurl and boringssl, and the Windows versioncould use standard Windows APIs for making HTTP requests and cryptography(for OAuth). Contributions are welcome for this feature.

We are actively working on improving CMake and Windows support, and addressingthese limitations. We would appreciate pull requests that implement missingops or APIs.

Cmake Tensorflow Windows

  1. Install the pre-requisites detailed above, and set up your environment.

    • The following commands assume that you are using the Windows CommandPrompt (cmd.exe). You will need to set up your environment to use theappropriate toolchain, i.e. the 64-bit tools. (Some of the binary targetswe will build are too large for the 32-bit tools, and they will fail without-of-memory errors.) The typical command to do set up yourenvironment is:

    • When building with GPU support after installing the CUDNN zip file from NVidia, append itsbin directory to your PATH environment variable.In case TensorFlow fails to find the CUDA dll’s during initialization, check your PATH environment variable.It should contain the directory of the CUDA dlls and the directory of the CUDNN dll.For example:

    • We assume that cmake and git are installed and in your %PATH%. Iffor example cmake is not in your path and it is installed inC:ProgramFiles(x86)CMakebincmake.exe, you can add this directoryto your %PATH% as follows:

  2. Clone the TensorFlow repository and create a working directory for yourbuild:

  3. Invoke CMake to create Visual Studio solution and project files.

    N.B. This assumes that cmake.exe is in your %PATH% environmentvariable. The other paths are for illustrative purposes only, and maybe different on your platform. The ^ character is a line continuationand must be the last character on each line.

    To build with GPU support add “^” at the end of the last line above following with:

    Note that the -DCMAKE_BUILD_TYPE=Release flag must match the buildconfiguration that you choose when invoking msbuild. The known-goodvalues are Release and RelWithDebInfo. The Debug build type isnot currently supported, because it relies on a Debug library forPython (python35d.lib) that is not distributed by default.

    There are various options that can be specified when generating thesolution and project files:

    • -DCMAKE_BUILD_TYPE=(Release RelWithDebInfo): Note that theCMAKE_BUILD_TYPE option must match the build configuration that youchoose when invoking MSBuild in step 4. The known-good values areRelease and RelWithDebInfo. The Debug build type is not currentlysupported, because it relies on a Debug library for Python(python35d.lib) that is not distributed by default.

    • -Dtensorflow_BUILD_ALL_KERNELS=(ON OFF). Defaults to ON. You canbuild a small subset of the kernels for a faster build by setting thisoption to OFF.

    • -Dtensorflow_BUILD_CC_EXAMPLE=(ON OFF). Defaults to ON. Generateproject files for a simple C++example training program.

    • -Dtensorflow_BUILD_PYTHON_BINDINGS=(ON OFF). Defaults to ON. Generateproject files for building a PIP package containing the TensorFlow runtimeand its Python bindings.

    • -Dtensorflow_ENABLE_GRPC_SUPPORT=(ON OFF). Defaults to ON. IncludegRPC support and the distributed client and server code in the TensorFlowruntime.

    • -Dtensorflow_ENABLE_SSL_SUPPORT=(ON OFF). Defaults to OFF. IncludeSSL support (for making secure HTTP requests) in the TensorFlow runtime.This support is incomplete, and will be used for Google Cloud Storagesupport.

    • -Dtensorflow_ENABLE_GPU=(ON OFF). Defaults to OFF. IncludeGPU support. If GPU is enabled you need to install the CUDA 8.0 Toolkit and CUDNN 5.1.CMake will expect the location of CUDNN in -DCUDNN_HOME=path_you_unziped_cudnn.

    • -Dtensorflow_BUILD_CC_TESTS=(ON OFF). Defaults to OFF. This builds cc unit tests.There are many of them and building will take a few hours.After cmake, build and execute the tests with

    • -Dtensorflow_BUILD_PYTHON_TESTS=(ON OFF). Defaults to OFF. This enables python kernel tests.After building the python wheel, you need to install the new wheel before running the tests.To execute the tests, use

  4. Invoke MSBuild to build TensorFlow.

    To build the C++ example program, which will be created as a .exeexecutable in the subdirectory .Release:

    To build the PIP package, which will be created as a .whl file in thesubdirectory .tf_pythondist:

This build requires Docker to be installed on thelocal machine.

Tensorflow C++ Cmake

That’s it. Dependencies included.