1

Fail to compile & run basic tensorflow c++ example using bazel under win7 (tensorflow (GPU or CPU) already works fine with keras (python3)). Maybe it is important to know that i operate behind a proxy (pip, pacman do work with http_proxy environment variables, bazel seems so, too).

To me it seems, that a patch can not be applied: (see below) "can't find file to patch at input line 4".

What can I do to accomplish a work-around? (avoid the patch, apply it manually, download an updated version ....)

What do I have to do to check for errors / get more details?

Do I need to (re-)install tensorflow from sources in order to run the c++ examples?

Related Links

As I see, I can not post more than 2 links, so I describe the topics, I'll try out and will give feedback, if there is sth helpful ...

prot_library/WORKSPACE: github cgrushko proto_library Workspace

stackoverflow: bazel rules for the protobuf c compiler

blog bazel build carmi grushko "proto_library is a language-agnostic rule"

stackoverflow: cannot find package google protobuf

stackoverflow: no package rptobuf devel available error

stackoverflow: tensorflow bazel build failed - no such package '@protobuf//'

stackoverflow: bazel rules for the protobuf c++ compiler

stackoverflow: tensorflow buld error with bazel

stackoverflow: tensorflow bazel build falling

System information

OS: win7-64

VS2015

JDK8

Tensorflow installed under win7 via python3 (with GPU) from binary (pip3 install....) version: '1.0.1'

Bazel version: Build label: 0.5.2- (@non-git)

protobuf is installed in python3.5:

 $ pip install protobuf --proxy="http://proxy.com:8080"
 Requirement already satisfied: protobuf in d:\bin\python64-3-anaconda\envs\python64-35\lib\site-packages
 Requirement already satisfied: six>=1.9 in d:\bin\python64-3-anaconda\envs\python64-35\lib\site-packages (from protobuf)
 Requirement already satisfied: setuptools in d:\bin\python64-3-anaconda\envs\python64-35\lib\site-packages\setuptools-27.2.0-py3.5.egg (from protobuf)

patch is installed: (msys2)$ patch --version -> GNU patch 2.7.5

I do not have any protoc ... (some sites mention it, but neither pacman nor pip do know it)

Describe the problem

The problem occurs when i try to build a simple script with tensorflow included https://www.tensorflow.org/api_guides/cc/guide

using msys2 to run bazel in .../Sourcen/external/tensorflow-master/

$ bazel run -c opt //tensorflow/cc/example1:example-out

WARNING: ignoring http_proxy in environment.
WARNING: C:/tools/msys64/tmp/_bazel_xxxxxx/6esgz-yl/external/bazel_tools/tools/cpp/cc_configure.bzl:67:3:
Auto-Configuration Warning: 'BAZEL_VC' is not set, start looking for the latest Visual C++ installed.

WARNING: C:/tools/msys64/tmp/_bazel_xxxxxxx/6esgz-yl/external/bazel_tools/tools/cpp/cc_configure.bzl:67: 3:
Auto-Configuration Warning: Looking for VS%VERSION%COMNTOOLS environment variables,eg. VS140COMNTOOLS.

WARNING: C:/tools/msys64/tmp/_bazel_xxxxxxxx/6esgz-yl/external/bazel_tools/tools/cpp/cc_configure.bzl:67:3:
Auto-Configuration Warning: Visual C++ build tools found at C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC.

ERROR: xxxxxx...../tensorflow-master/tensorflow/cc/example1/BUILD:1:1: error loading package 'tensorflow/core': Encountered error while reading extension file 'protobuf.bzl': no such package '@protobuf//': Traceback (most recent call last):

File "xxxxxxxx.../tensorflow-master/tensorflow/workspace.bzl", line 116 _apply_patch(repo_ctx, repo_ctx.attr.patch_file)

File "xxxxx..../tensorflow-master/tensorflow/workspace.bzl", line 107, in _apply_patch _execute_and_check_ret_code(repo_ctx, cmd)

File "xxxxx..../tensorflow-master/tensorflow/workspace.bzl", line 91, in _execute_and_check_ret_code

fail("Non-zero return code({1}) when ..., <2 more arguments>))

Non-zero return code(1) when executing 'c:/tools/msys64/usr/bin/bash.exe -c patch -p1 -d C:/tools/msys64/tmp/_bazel_xxxxx/6esgz-yl/external/protobuf -i xxxxx..../tensorflow-master/third_party/protobuf/add_noinlines.patch':

Stdout: can't find file to patch at input line 4

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

........................................

|diff -u -r a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
|--- a/src/google/protobuf/compiler/cpp/cpp_file.cc 2017-02-10 23:55:34.000000000 +0100
|+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc 2017-03-21 13:41:46.931979154 +0100

..................................

File to patch:
Skip this patch? [y]
Skipping patch.
3 out of 3 hunks ignored

 Stderr: and referenced by '//tensorflow/cc/example1:example-out'.
 ERROR: Analysis of target '//tensorflow/cc/example1:example-out' failed; 

 build aborted.

 INFO: Elapsed time: 9,402s
 ERROR: Build failed. Not running target.

Source code / logs

In order to understand the problem better, I changed names or the orignal files & directories

The directory .../Sourcen/external/tensorflow-master/tensorflow/cc/example1/ contains 3 files:

  • WORKSPACE
  • BUILD
  • example-code.cc

..... WORKSPACE ........ empty

...... BUILD

cc_binary(
name = "example-out",
srcs = ["example-code.cc"],
 deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/cc:client_session",
 "//tensorflow/core:tensorflow",
],
)

...................................

............ example-code.cc

// tensorflow/cc/example/example.cc
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"

int main() {
  using namespace tensorflow;
  using namespace tensorflow::ops;
  Scope root = Scope::NewRootScope();
  // Matrix A = [3 2; -1 0]
  auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f}});
  // Vector b = [3 5]
  auto b = Const(root, { {3.f, 5.f}});
  // v = Ab^T
  auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
  std::vector outputs;
  ClientSession session(root);
  // Run and fetch v
  TF_CHECK_OK(session.Run({v}, &outputs));
  // Expect outputs[0] == [19; -3]
  LOG(INFO) << outputs[0].matrix();
return 0;
}

..............

BerndSchmitt
  • 384
  • 3
  • 8
  • Some people told me on IRC, that for compiling c++ examples, installation from source is mandatory. – BerndSchmitt Jul 12 '17 at 07:14
  • My first attempts on installing tensorflow from source failed, too: https://stackoverflow.com/questions/45129507/tensorflow-install-from-source-win7-bazel-python-no-module-named-encodin – BerndSchmitt Jul 19 '17 at 10:46
  • Does the directory `C:/tools/msys64/tmp/_bazel_xxxxxxxx/6esgz-yl/external/protobuf/` contain any files? – kris Jul 24 '17 at 19:24
  • Yes, it contains 1667 files, 252 folders, its size is 26.3 MB (dirs: benchmarks, cmake, conformance, csharp, docs, editors, examples, java, javanano, jenkins, js, m4, more_tests, objectivec, php, protoc-artifacts, python, ruby, src, third_party, util, ...) – BerndSchmitt Jul 25 '17 at 10:57

0 Answers0