Question about the Tensorflow framework C++ libraries

174 views
Skip to first unread message

Dimitar Gueorguiev

unread,
May 8, 2020, 6:35:44 AM5/8/20
to SIG Build
Hello,

I have the following question - I have built successfully the tensorflow framework shared library by executing the following targets: 

bazel build --config=opt --verbose_failures -c dbg --strip=never //tensorflow:libtensorflow_cc.so

bazel build --config=opt --verbose_failures -c dbg --strip=never //tensorflow:libtensorflow_framework.so

Also I have built the python pip package without an issue:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package


How can I compile and link a simple C++ API example as the one shown here:

https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/public


I tried using simple CMakeLists.txt file like the one below but I am getting some compilation errors which are related to Eigen which is not included correctly.

/opt/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/src/FixedPoint/MatMatProduct.h:236:1: error: 'EIGEN_DONT_INLINE' does not name a type

  236 | EIGEN_DONT_INLINE void gebp_kernel<QUInt8, QInt8, Index, DataMapper, mr, nr,

      | ^~~~~~~~~~~~~~~~~


Am I missing something?


Below are included my CMakeLists.txt and TensorflowApp.cxx.


Thank you in advance,

Dimitar Gueorguiev



######################CMakeLists.txt########################################

#

#

cmake_minimum_required(VERSION 3.10)


# set the project name and version

project(TensorflowApp VERSION 1.0)


set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_STANDARD_REQUIRED True)


option(USE_TF2_FRAMEWORK "Use tensorflow v2 framework library" ON)

option(USE_TF2_LIBRARY "Use tensorflow v2 cc library" ON)



configure_file(TensorflowAppConfig.h.in TensorflowAppConfig.h)


if(USE_TF2_FRAMEWORK)

  list(APPEND EXTRA_LIBS tensorflow_framework)

endif()


if(USE_TF2_LIB)

  list(APPEND EXTRA_LIBS tensorflow_cc)

endif()


if(USE_TF2_LIB)

  add_library(tensorflow_cc SHARED IMPORTED) # or STATIC instead of SHARED

  set_target_properties(tensorflow_cc PROPERTIES

    IMPORTED_LOCATION "${TF_HOME}/bazel-bin/tensorflow/libtensorflow_cc.so"

    INTERFACE_INCLUDE_DIRECTORIES "${TF_HOME}/bazel-tensorflow;${TF_HOME}/bazel-bin;${TF_HOME}/bazel-tensorflow/third_party/eigen3;${TF_HOME}/bazel-tensorflow/external/eigen_archive;${TF_HOME}/bazel-tensorflow/external/com_google_absl;${TF_HOME}/bazel-tensorflow/external/com_google_protobuf/src"

  )

endif()


if(USE_TF2_FRAMEWORK)

  add_library(tensorflow_framework SHARED IMPORTED) # or STATIC instead of SHARED

  set_target_properties(tensorflow_framework PROPERTIES

    IMPORTED_LOCATION "${TF_HOME}/bazel-bin/tensorflow/libtensorflow_framework.so"

    INTERFACE_INCLUDE_DIRECTORIES "${TF_HOME}/bazel-tensorflow;${TF_HOME}/bazel-bin;${TF_HOME}/bazel-tensorflow/third_party/eigen3;${TF_HOME}/bazel-tensorflow/external/eigen_archive;${TF_HOME}/bazel-tensorflow/external/com_google_absl;${TF_HOME}/bazel-tensorflow/external/com_google_protobuf/src"

  )

endif()


add_executable(TensorflowApp TensorflowApp.cxx)


target_include_directories(TensorflowApp PUBLIC "${PROJECT_BINARY_DIR}")


if(USE_TF2_LIB)

  target_link_libraries(TensorflowApp tensorflow_cc)

endif()

if(USE_TF2_FRAMEWORK)

  target_link_libraries(TensorflowApp tensorflow_framework)

endif()



####################TensorflowApp.cxx##################################

#

#include <iostream>

#include <memory>

#include <string>

#include <vector>

#include "tensorflow/core/framework/graph.pb.h"

#include "tensorflow/core/public/session.h"

#include "tensorflow/core/framework/tensor.h"


#include "TensorflowAppConfig.h"


using namespace tensorflow;

using tensorflow::string;

using tensorflow::int32;


int main (int argc, char *argv[]) {

   std::cout << argv[0] << " Version " << TensorflowApp_VERSION_MAJOR << "."

           << TensorflowApp_VERSION_MINOR << std::endl;


   return 0;

}

Paige Bailey

unread,
May 8, 2020, 6:44:57 AM5/8/20
to Dimitar Gueorguiev, SIG Build, Brian Zhao
Adding +Brian Zhao for C++ API questions.

--
To unsubscribe from this group and stop receiving emails from it, send an email to build+un...@tensorflow.org.

Dimitar Gueorguiev

unread,
May 8, 2020, 11:33:12 AM5/8/20
to SIG Build
Never mind, I figured out the problem - i needed to build and install manually protobuf, eigen and absl from the supplied sources TF_SRC_ROOT_FOLDER/bazel-tenrsorflow/external/com_google_protbuf, TF_SRC_ROOT_FOLDER/bazel-tenrsorflow/external/eigen_archive and TF_SRC_ROOT_FOLDER/bazel-tenrsorflow/external/com_google_absl. Now the following CMakeLists works just fine:

if(USE_TF2_LIB)
  add_library(tensorflow_cc SHARED IMPORTED) # or STATIC instead of SHARED
  set_target_properties(tensorflow_cc PROPERTIES
    IMPORTED_LOCATION "${TF_HOME}/bazel-bin/tensorflow/libtensorflow_cc.so"
    INTERFACE_INCLUDE_DIRECTORIES "${TF_HOME}/bazel-tensorflow;${TF_HOME}/bazel-bin;${PROTOBUF_HOME}/include;${EIGEN_HOME}/include;${EIGEN_HOME}/include/eigen3;${ABSL_HOME}/include"
  )
endif()

cmake -DTF_HOME=/opt/tensorflow -DPROTOBUF_HOME=/opt/protobuf-build -DEIGEN_HOME=/opt/eigen-build -DABSL_HOME=/opt/absl-build .

Thanks!
Dimitar
Reply all
Reply to author
Forward
0 new messages