tensorflow-2.0-gpu-c++安装与使用

安装参考:https://blog.csdn.net/wd1603926823/article/details/102869208 这是GPU版本;若用CPU版本可参考博主的另一篇。

安装完毕后马上使用是没问题的,如博主一样:

 但是当我将这个tensorflow-2.0-gpu-c++动态库打包到另一台电脑时出现下列问题:

 

 可以看到nvidia-smi和nvcc --version都没问题,而且刚刚的TF动态库在那台电脑证实没问题,实例代码都一样,为什么转移过来就报错了呢,环境变量也配置好了啊。

原来是:

1,因为版本不对,注意细看参考博主给的那些链接“tensorflow各个版本需要的CUDA版本以及Cudnn的对应关系” 我这里不符合,所以才会有报错。我用的是CUDA 9.0与我编译的TF-2.0-gpu-c++不一致!

所以我升级CUDA到11.0,但还是报错。

2,原来是cudnn没有安装,于是我按照刚刚博主的步骤在https://developer.nvidia.com/rdp/cudnn-archive#a-collapse742-10 下载安装合适的cudnn

 

为什么还是报错呢?!!!! 为什么listDevices里就没有检测到GPU呢???!

 

 

*******************************************************************************

 我在另一台电脑上重新编译 TF-1.12.0-C++-gpu,过程如下:

1,
root@jumper-MS-7B47:/home/jumper/workspace/tensorflow-1.12.0# bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
WARNING: The following configs were expanded more than once: [cuda]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
DEBUG: /root/.cache/bazel/_bazel_root/91cd994d0333ccb0b9ba0208e99963c2/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5: 
Auto-Configuration Warning: 'TMP' environment variable is not set, using 'C:\Windows\Temp' as default
ERROR: /home/jumper/workspace/tensorflow-1.12.0/tensorflow/core/kernels/BUILD:6589:1: no such package '@icu//': java.io.IOException: Error downloading [https://mirror.bazel.build/github.com/unicode-org/icu/archive/release-62-1.tar.gz, https://github.com/unicode-org/icu/archive/release-62-1.tar.gz] to /root/.cache/bazel/_bazel_root/91cd994d0333ccb0b9ba0208e99963c2/external/icu/release-62-1.tar.gz: Checksum was 86b85fbf1b251d7a658de86ce5a0c8f34151027cc60b01e1b76f167379acf181 but wanted e15ffd84606323cbad5515bf9ecdf8061cc3bf80fb883b9e6aa162e485aa9761 and referenced by '//tensorflow/core/kernels:unicode_script_op'
ERROR: Analysis of target '//tensorflow:libtensorflow_cc.so' failed; build aborted: Analysis failed
INFO: Elapsed time: 50.466s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (133 packages loaded)

#####################################################################
solution: change 'workspace.bzl' file in path of tensorflow-1.12.0/third_party/icu
from:
sha256 = "e15ffd84606323cbad5515bf9ecdf8061cc3bf80fb883b9e6aa162e485aa9761"
to:
sha256 = "86b85fbf1b251d7a658de86ce5a0c8f34151027cc60b01e1b76f167379acf181"

2,
INFO: From Compiling tensorflow/core/common_runtime/hierarchical_tree_broadcaster.cc [for host]:
tensorflow/core/common_runtime/hierarchical_tree_broadcaster.cc: In member function 'int tensorflow::HierarchicalTreeBroadcaster::GetDeviceTask(int, const std::vector<int>&)':
tensorflow/core/common_runtime/hierarchical_tree_broadcaster.cc:71:72: warning: 'task_hi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   LOG(FATAL) << "Unexpected device rank " << device_rank << " for " << task_hi
                                                                        ^
ERROR: /home/jumper/workspace/tensorflow-1.12.0/tensorflow/compiler/tf2xla/cc/BUILD:31:1: Linking of rule '//tensorflow/compiler/tf2xla/cc:ops/xla_jit_ops_gen_cc' failed (Exit 1)
/usr/bin/ld: warning: libcublas.so.9.0, needed by bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libcufft.so.9.0, needed by bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libcurand.so.9.0, needed by bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so, not found (try using -rpath or -rpath-link)
bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `cublasGemmEx@libcublas.so.9.0'
bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `cublasZhpmv_v2@libcublas.so.9.0'
bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `cufftExecD2Z@libcufft.so.9.0'
bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `cublasSrotg_v2@libcublas.so.9.0'
bazel-out/host/bin/_solib_local/_U_S_Stensorflow_Scompiler_Stf2xla_Scc_Cops_Sxla_Ujit_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `cufftExecR2C@libcufft.so.9.0'

######################################################################
solution:
在~/.bashrc加入了下面环境变量:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64
export PATH=$PATH:/usr/local/cuda-9.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-9.0
重启


3,

ERROR: /home/jumper/workspace/tensorflow-1.12.0/tensorflow/compiler/tf2xla/cc/BUILD:31:1: Executing genrule //tensorflow/compiler/tf2xla/cc:xla_jit_op_gen_genrule failed (Exit 127)
bazel-out/host/bin/tensorflow/compiler/tf2xla/cc/ops/xla_jit_ops_gen_cc: error while loading shared libraries: libcublas.so.9.0: cannot open shared object file: No such file or directory
Target //tensorflow:libtensorflow_cc.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2311.809s, Critical Path: 102.53s
INFO: 7035 processes: 7035 local.
FAILED: Build did NOT complete successfully

#######################################################################
solution:
cp /usr/local/cuda/lib64/libcublas.so.9.0 /usr/local/lib/libcublas.so.9.0 && sudo ldconfig


4,
root@jumper-MS-7B47:/home/jumper/workspace/tensorflow-1.12.0# ./tensorflow/contrib/makefile/build_all_linux.sh
PROTOC = "protoc"
CC_PREFIX = ""
rm -rf /home/jumper/workspace/tensorflow-1.12.0/tensorflow/contrib/makefile/gen
rm -rf tensorflow/core/util/version_info.cc
downloading https://bitbucket.org/eigen/eigen/get/fd6845384b86.tar.gz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

#######################################################################
solution:open ./tensorflow/contrib/makefile/download_dependencies.sh and change it:
from:
EIGEN_URL="$(grep -o 'http.*bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
to:
EIGEN_URL="$(grep -o 'https://mirror.bazel.build/bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"

5,

downloading https://github.com/google/googletest/archive/release-1.8.0.tar.gz

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now

######################################################################
solution:change https://github.com to https://mirror.bazel.build/github.com

6,

downloading https://github.com/abseil/abseil-cpp/archive/48cd2c3f351ff188bc85684b84a91b6e6d17d896.tar.gz

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
######################################################################
solution:change https://github.com to https://mirror.bazel.build/github.com

This is the changed section of my download_dependencies.sh file:
#EIGEN_URL="$(grep -o 'http.*bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
#https://mirror.bazel.build/bitbucket.org/eigen/eigen/get/fd6845384b86.tar.gz
EIGEN_URL="$(grep -o 'https://mirror.bazel.build/bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"
GEMMLOWP_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)"
#GOOGLETEST_URL="https://github.com/google/googletest/archive/release-1.8.0.tar.gz"
GOOGLETEST_URL="https://mirror.bazel.build/github.com/google/googletest/archive/release-1.8.0.tar.gz"
NSYNC_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/nsync/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"
# Note: The Protobuf source in `tensorflow/workspace.bzl` in TensorFlow
# 1.10 branch does not work. `make distclean` fails and blocks the build
# process. For now we're hardcoding to the version which is used by
# TensorFlow 1.9.
PROTOBUF_URL="https://mirror.bazel.build/github.com/google/protobuf/archive/396336eb961b75f03b25824fe86cf6490fb75e3a.tar.gz"
# TODO (yongtang): Replace the following with 'https://mirror.bazel.build/github.com/google/re2/.*tar\.gz' once
# the archive has been propagated in mirror.bazel.build.
#RE2_URL="$(grep -o 'https://github.com/google/re2/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"
RE2_URL="$(grep -o 'https://github.com/google/re2/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
FFT2D_URL="$(grep -o 'http.*fft\.tgz' "${BZL_FILE_PATH}" | grep -v bazel-mirror | head -n1)"
DOUBLE_CONVERSION_URL="$(grep -o "https.*google/double-conversion.*\.zip" "${BZL_FILE_PATH}" | head -n1)"
#ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | head -n1)"
ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
CUB_URL="$(grep -o 'https.*cub/archive.*zip' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"

7,
downloading https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/48cd2c3f351ff188bc85684b84a91b6e6d17d896.tar.gz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now


##################################################################
solution:download by hand

8,
https://github.com/NVlabs/cub/zip/1.8.0

#############################################################
solution: https://www.pianshen.com/article/27071582636/

9,

  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_device_scan.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_device_select_if.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_device_select_unique.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_grid_barrier.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_iterator.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_util.h  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_warp_reduce.cu  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/test/test_warp_scan.cu  
   creating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/tune/
 extracting: /tmp/tmp.S5I9CEs02b/cub-1.8.0/tune/.gitignore  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/tune/Makefile  
  inflating: /tmp/tmp.S5I9CEs02b/cub-1.8.0/tune/tune_device_reduce.cu  
download_dependencies.sh completed successfully.
g++ -M -std=c++11 -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal ../../internal/*.c ../../testing/*.c ../../platform/linux/src/nsync_semaphore_futex.c ../../platform/c++11/src/per_thread_waiter.cc ../../platform/c++11/src/yield.cc ../../platform/c++11/src/time_rep_timespec.cc ../../platform/c++11/src/nsync_panic.cc \
      ../../platform/c++11/src/start_thread.cc > dependfile
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/common.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/counter.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/cv.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/debug.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/dll.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/mu.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/mu_wait.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/note.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/once.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/sem_wait.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/time_internal.c
g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../internal/wait.c
set -x; \
for x in ../../platform/linux/src/nsync_semaphore_futex.c ../../platform/c++11/src/per_thread_waiter.cc ../../platform/c++11/src/yield.cc ../../platform/c++11/src/time_rep_timespec.cc ../../platform/c++11/src/nsync_panic.cc $empty; do  g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c $x || exit 1; done; \
for x in  $empty; do o=`basename $x .s`; as  $x -o `basename $o .S`.o || exit 1; done; \
for x in  $empty; do g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O  -c $x || exit 1; done
+ g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../platform/linux/src/nsync_semaphore_futex.c
+ g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../platform/c++11/src/per_thread_waiter.cc
+ g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../platform/c++11/src/yield.cc
+ g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../platform/c++11/src/time_rep_timespec.cc
+ g++ -DNSYNC_USE_CPP11_TIMEPOINT -DNSYNC_ATOMIC_CPP11 -I../../platform/c++11.futex -I../../platform/c++11 -I../../platform/gcc -I../../platform/posix -pthread -I../../public -I../../internal -O -std=c++11 -Werror -Wall -Wextra -pedantic -c ../../platform/c++11/src/nsync_panic.cc
ar cr libnsync.a common.o counter.o cv.o debug.o dll.o mu.o mu_wait.o note.o once.o sem_wait.o time_internal.o wait.o nsync_semaphore_futex.o per_thread_waiter.o yield.o time_rep_timespec.o nsync_panic.o
case "" in "") ;; *)  libnsync.a;; esac
cp libnsync.a nsync.a
case "" in "") ;; *)  nsync.a;; esac
Google Mock not present.  Fetching gmock-1.7.0 from the web...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:02:31 --:--:--     0
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.
root@jumper-MS-7B47:/home/jumper/workspace/tensorflow-1.12.0# 

####################################################################
reason:change autogen.sh in path ./tensorflow/contrib/makefile/downloads/protobuf
from:
curl $curlopts -L -O https://github.com/google/googlemock/archive/release-1.7.0.zip
to:
curl $curlopts -L -O https://https://mirror.bazel.build/github.com/google/googlemock/archive/release-1.7.0.zip


10,

/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/graph.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
 #error This file was generated by a newer version of protoc which is
  ^
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/graph.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
 #error incompatible with your Protocol Buffer headers.  Please update
  ^
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/graph.pb.h:14:2: error: #error your headers.
 #error your headers.
  ^
In file included from ../src/linkuang.h:18:0,
                 from ../src/linkuang.cpp:8:
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/graph.pb.h:27:50: fatal error: google/protobuf/inlined_string_field.h: 没有那个文件或目录
compilation terminated.
make: *** [src/linkuang.o] Error 1
src/subdir.mk:21: recipe for target 'src/linkuang.o' failed

########################################################################
solution:https://www.jianshu.com/p/d46596558640
编译eigen:
tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/eigen/build:cmake -DCMAKE_INSTALL_PREFIX=/tmp/eigen/ ../
tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/eigen/build:make install
Then copy Eigen from /tmp/eigen/include/eigen3 to tensorflow_cc_1.12.0/include 反正最后编译工程时却什么要么从/tmp/eigen下拷贝,要么从tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/eigen下拷贝过去
编译Protobuf
Error occurs when run 'make install':
libtool:   error: error: cannot install 'libprotoc.la' to a directory not ending in /home/jumper/workspace/tensorflow-1.12.0/tensorflow/contrib/makefile/gen/protobuf/lib
Makefile:2144: recipe for target 'install-libLTLIBRARIES' failed
make[3]: *** [install-libLTLIBRARIES] Error 1
make[3]: Leaving directory '/home/jumper/workspace/tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/protobuf/src'
Makefile:8033: recipe for target 'install-am' failed
make[2]: *** [install-am] Error 2
make[2]: Leaving directory '/home/jumper/workspace/tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/protobuf/src'
Makefile:8027: recipe for target 'install' failed
make[1]: *** [install] Error 2
make[1]: Leaving directory '/home/jumper/workspace/tensorflow-1.12.0/tensorflow/contrib/makefile/downloads/protobuf/src'
Makefile:1564: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1
    ######################################
solution:make clean
     make && make install

Error occurs when build project of 'TF-1.12.0-C++-inference':
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/api_def.pb.h:2153:19: error: ‘struct google::protobuf::internal::ArenaStringPtr’ has no member named ‘UnsafeArenaRelease’
   return summary_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
                   ^
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/api_def.pb.h: In member function ‘void tensorflow::ApiDef::unsafe_arena_set_allocated_summary(std::__cxx11::string*)’:
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/api_def.pb.h:2164:12: error: ‘struct google::protobuf::internal::ArenaStringPtr’ has no member named ‘UnsafeArenaSetAllocated’
   summary_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
            ^
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/api_def.pb.h: In member function ‘void tensorflow::ApiDef::clear_description()’:
/home/jumper/workspace/tensorflow_cc_1.12.0/include/bazel-genfiles/tensorflow/core/framework/api_def.pb.h:2171:110: error: no matching function for call to ‘google::protobuf::internal::ArenaStringPtr::ClearToEmpty(const string*, google::protobuf::Arena*)’
   description_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
...
error:This file was generated by a newer version of protoc which is
incompatible with your Protocol Buffer headers.  Please update
your headers.
...
error:This file was generated by an older version of protoc which is
incompatible with your Protocol Buffer headers.  Please
regenerate this file with a newer version of protoc.

      ##################################################
Reason:protobuf version in use is still not compatible with protobuf version in tensorflow and you can run ./protoc --version see the version in use.Mine is 3.5.0 in use:
root@jumper-MS-7B47:~# protoc --version
libprotoc 3.5.0
root@jumper-MS-7B47:~# 

What's more,you can open workspace.bzl file in tensorflow-1.12.0/tensorflow to check the protobuf version tensorflow requires.(According to https://blog.csdn.net/Li_suhuan/article/details/121041248 我选择的是第一种方式,重新下载编译tf要求的protobuf版本即可)
something like these:
PROTOBUF_URLS = [
        "https://mirror.bazel.build/github.com/google/protobuf/archive/v3.6.0.tar.gz",
        "https://github.com/google/protobuf/archive/v3.6.0.tar.gz",
    ]

So i download v3.6.0.tar.gz by hand and then compile it:
./autogen.sh
./configure --prefix=/tmp/proto-v3.6.0
make clean
make && make install

In the end,copy the include files in v3.6.0 to tensorflow_cc_1.12.0/include .接下来工程就可以正确编译了。


11,然而运行工程时run the project:
Invalid argument: Cannot assign a device for operation dropout_1/keras_learning_phase: {{node dropout_1/keras_learning_phase}}was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
     [[dropout_1/keras_learning_phase]]
terminate called after throwing an instance of 'std::runtime_error'
  what():  ERROR: Creating graph in session failed...
如果不指定gpu就可以正常运行即只能运用CPU版本的tf-1.12.0-inference。为什么明明我已经重新编译--cuda并且无任何报错了。为何啊?????

看无错误,而且可以跑CPU,为什么一指定GPU 就不行呢??

 

posted @ 2021-12-10 10:04  秦时明月卫庄  阅读(244)  评论(0编辑  收藏  举报