TensorFlow-GPU2.6.0 C++版编译遇到的问题及解决办法

Python版本与Numpy版本兼容性问题

问题描述:

Python3.9与TensorFlow2.6.0版本所要求的Numpy1.19.2版本存在兼容性问题,在安装Python3.9后,可能出现Numpy安装失败的情况,具体报错信息如下:

解决方法:

  1. 将Python版本降低为Python3.8(该方法可能导致后面编译时与MSCV2019产生版本冲突,因此不建议采用)。

  2. 将Numpy版本升级为1.19.5(经测试在windows10系统下,GPU为3080可正常编译)。

MSVC2019版本问题导致编译出错

问题描述:

采用MSVC编译TensorFlow C++动态库时报错为找不到“copysign”标识符,报错信息如下:

ERROR: C:/sdks/tensorflow/tensorflow/python/util/BUILD:610:27: C++ compilation of rule '//tensorflow/python/util:fast_module_type.so' failed (Exit 2): cl.exe failed: error executing commandcd C:/users/adam/_bazel_adam/e7merofc/execroot/org_tensorflowSET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrtSET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\\Extensions\Microsoft\IntelliCode\CLI;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\devinit;C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\NinjaSET PWD=/proc/self/cwdSET PYTHON_BIN_PATH=C:/Users/Adam/anaconda3/envs/tensorflow/python.exeSET PYTHON_LIB_PATH=C:/Users/Adam/anaconda3/envs/tensorflow/lib/site-packagesSET RUNFILES_MANIFEST_ONLY=1SET TEMP=C:\Users\Adam\AppData\Local\TempSET TF2_BEHAVIOR=1SET TMP=C:\Users\Adam\AppData\Local\TempC:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30037/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-opt/bin /Iexternal/eigen_archive /Ibazel-out/x64_windows-opt/bin/external/eigen_archive /Iexternal/com_google_absl /Ibazel-out/x64_windows-opt/bin/external/com_google_absl /Iexternal/nsync /Ibazel-out/x64_windows-opt/bin/external/nsync /Iexternal/local_config_python /Ibazel-out/x64_windows-opt/bin/external/local_config_python /Iexternal/pybind11 /Ibazel-out/x64_windows-opt/bin/external/pybind11 /Iexternal/bazel_tools /Ibazel-out/x64_windows-opt/bin/external/bazel_tools /Ibazel-out/x64_windows-opt/bin/external/pybind11/_virtual_includes/pybind11 /Ithird_party/eigen3/mkl_include /Ibazel-out/x64_windows-opt/bin/third_party/eigen3/mkl_include /Iexternal/eigen_archive /Ibazel-out/x64_windows-opt/bin/external/eigen_archive /Iexternal/nsync/public /Ibazel-out/x64_windows-opt/bin/external/nsync/public /Iexternal/local_config_python/python_include /Ibazel-out/x64_windows-opt/bin/external/local_config_python/python_include /Iexternal/pybind11/include /Ibazel-out/x64_windows-opt/bin/external/pybind11/include /DEIGEN_MPL2_ONLY /DEIGEN_MAX_ALIGN_BYTES=64 /showIncludes /MD /O2 /Oy- /DNDEBUG /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Gy /Gw /W0 /D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOGDI /experimental:preprocessor /d2ReducedOptimizeHugeFunctions /arch:AVX /std:c++14 -fno-strict-aliasing -fexceptions /Fobazel-out/x64_windows-opt/bin/tensorflow/python/util/_objs/fast_module_type.so/fast_module_type.obj /c tensorflow/python/util/fast_module_type.cc
Execution platform: @local_execution_config_platform//:platform
cl : Command line warning D9035 : option 'experimental:preprocessor' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'Zc:preprocessor' instead of 'experimental:preprocessor'
cl : Command line warning D9002 : ignoring unknown option '-fno-strict-aliasing'
cl : Command line warning D9002 : ignoring unknown option '-fexceptions'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\include\complex(675): error C2039: 'copysign': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\include\complex(675): error C3861: 'copysign': identifier not found
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 69.130s, Critical Path: 6.47s
INFO: 29 processes: 24 internal, 5 local.
FAILED: Build did NOT complete successfully

解决办法:

该问题主要是由于MSVC2019版本的complex文件存在兼容性问题,可以下载MSVC2017生成工具,然后用MSVC2017中的complex文件去替换MSVC2019中的complex文件。

编译过程内存,线程,硬盘空间等资源超出导致编译失败

问题描述:

TensorFlow编译过程需要大量的内存和硬盘空间,具体的大小与编译时同时进行的线程数量呈正相关。如果资源超出则会报错。报错信息为编译器堆空间不足:

unsupported\Eigen\CXX11\src\Tensor\TensorBroadcasting.h(653) : fatal error C1002: compiler is out of heap space in pass 2

解决方法:

通过配置bazel编译选项来分配编译所使用的资源,主要的config选项及参数如下:

--output_user_root 编译文件输出目录,指定其他盘可以减小C盘存储空间压力
--local_resources = 内存大小,CPU数量,线程数 设置编译过程中使用的最大内存大小,CPU数量,线程数量
--jobs = 线程数 线程数量与所用内存大小呈正相关,所以可以只限制线程数量来保证内存资源不超出

CUDA10.0版本编译出错

问题描述:

对于要求CUDA版本为10.0的TensorFlow版本而言,在编译C++动态库时会出现cudafe++.exe文件执行错误,报错信息为:

nvcc error : 'cudafe++' died with status 0xC0000005 (ACCESS_VIOLATION)

解决办法:

将CUDA升级为10.1(该操作可能导致与TensorFlow版本存在兼容性问题)。建议放弃依赖于CUDA10.0版本的TensorFlow版本编译。

C++ TensorFlow代码无法解析外部符号问题

问题描述:

在配置好VS环境后,对C++测试代码进行编译可能出现无法解析外部符号的报错,具体信息如下:

无法解析的外部符号 "class tensorflow::Status __cdecl tensorflow::NewSession(struct tensorflow::SessionOptions const &,class tensorflow::Session * *)" (?NewSession@tensorflow@@YA?AVStatus@1@AEBUSessionOptions@1@PEAPEAVSession@1@@Z)
无法解析的外部符号 "public: __cdecl tensorflow::SessionOptions::SessionOptions(void)" (??0SessionOptions@tensorflow@@QEAA@XZ)

解决方法:

  • Step1: 在TensorFlow源码的根目录下找到def_file_filter.py.tpl文件,具体路径为:ROOT\tensorflow\tools\def_file_filter\def_file_filter.py.tpl

  • Step2: 使用文本编辑器打开,然后通过查找功能搜索args.target找到如下代码:

  • Step3: 根据代码格式,将编译报错时出现的无法解析的外部符号添加到文件中,在本文例子中则是将以下两行代码添加到文件红色框内位置。

  • def_fp.write("\t ?NewSession@tensorflow@@YA?AVStatus@1@AEBUSessionOptions@1@PEAPEAVSession@1@@Z\n")
    def_fp.write("\t ??0SessionOptions@tensorflow@@QEAA@XZ\n")
    
  • Step4: 重新编译dll、lib以及includes文件。

  • dll文件编译,输入指令如下:

    bazel --output_user_root=D:\tf\tfcp build --config=opt --config=cuda --define=no_tensorflow_py_deps=true //tensorflow:tensorflow_cc.dll
    

    然后是lib文件编译,输入指令如下:

    bazel --output_user_root=D:\tf\tfcp build --config=opt --config=cuda --define=no_tensorflow_py_deps=true //tensorflow:tensorflow_cc_dll_import_lib
    

    最后是头文件的编译,输入指令如下:

    bazel --output_user_root=D:\tf\tfcp build --config=opt --config=cuda --define=no_tensorflow_py_deps=true //tensorflow:install_headers
    
  • Step5: 将重新编译的dll文件替换到VS项目根目录ROOT\x64\Release路径下。

efine=no_tensorflow_py_deps=true //tensorflow:install_headers


- **Step5:** 将重新编译的dll文件替换到VS项目根目录`ROOT\x64\Release`路径下。

TensorFlow C++版编译遇到的问题及解决办法相关推荐

  1. VS 2010 中文版正式版无法安装Silverlight4 Tools的解决办法

    http://www.blueidea.com/microsoft/vs2010/2010_con/2010053101.htm VS 2010 中文版正式版无法安装Silverlight4 Tool ...

  2. Visual studio 2010 sp1中文版正式版无法安装Silverlight5_Tools rc1 的解决办法

    现象参考:Visual studio 2010 中文版正式版无法安装Silverlight4 Tools的解决办法 解决办法如下: 编辑:ParameterInfo.xml 替换:1033 为 205 ...

  3. PHP编译安装时常见错误解决办法,php编译常见错误

    PHP编译安装时常见错误解决办法,php编译常见错误 1.configure: error: xslt-config not found. Please reinstall the libxslt & ...

  4. linux libvpx编译安装,linux编译安装时常见错误解决办法

    **configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution** 复 ...

  5. linux编译安装的报错,linux编译安装时常见错误解决办法

    This article is post on https://coderwall.com/p/ggmpfa 原文链接:http://www.bkjia.com/PHPjc/1008013.html ...

  6. 火线精英手游服务器维护,火线精英手机版登录失败进不去解决办法

    火线精英手机版登录失败进不去怎么办?火线精英手机版开测以来受到很多喜欢射击游戏的玩家喜爱,但是有玩家表示在游戏中遇到了登录失败进不去的情况,下面小编就为玩家们介绍一下火线精英手机版登录失败进不去的解决 ...

  7. 我的世界java版怎么输入不了汉字_我的世界中国版文字消失的6种解决办法

    原标题:我的世界中国版文字消失的6种解决办法 告示牌和书,对于沙盒游戏的mc玩家而言,是极其重要的.然而中国版在<我的世界>一刀切地抹去文字这件事,饱受玩家争议,因为mc把"草方 ...

  8. 灵图天行者9PC版、PPC版搜索不到卫星信号解决办法

    灵图天行者9PC版.PPC版搜索不到卫星信号解决办法 当然,前提是你需要确定你的硬件是没有问题的. 以PPC版的灵图9进行说明: 在灵图安装目录下有一个configfile的文件夹,里面有一个gps_ ...

  9. php源码安装失败,php编译安装常见错误及解决办法

    php编译安装常见错误及解决办法 1.configure: error: No curses/termcap library found 网上有的说法是:–with-named-curses-libs ...

最新文章

  1. ubuntu虚拟机卡住开机_虚拟机Ubuntu开机问题及解决方法
  2. python控制手机自动刷新闻_python +adb控制手机自动化签到
  3. selenium之 chromedriver与chrome版本映射表(更新至v2.43)
  4. 准备 macvlan 环境 - 每天5分钟玩转 Docker 容器技术(54)
  5. VS2005最近项目和最近文件清除
  6. 为什么要有环回路由(zz)
  7. 数据库常用的sql语句大全--sql
  8. php对字符数组进行排序,php数组去重_php对数组中字符串去重并排序例子
  9. 中国移动计算机岗专业知识,【中国移动】计算机技术岗面经
  10. strcmp()函数用法及其详解
  11. 程序员的数学【线性代数高级】
  12. 三极管构成的流水灯电路分析
  13. flutter 里面读取和复制内容到手机剪切板
  14. 那些著名的黑客事件 四
  15. python总结大纲:适合初学者与有经验的人快速查找遗忘的知识点
  16. 借助HttpCombiner让你的网站加速
  17. 详解5种网站 静态网站、动态网站、伪静态网站、云计算网站都是什么
  18. Git常用命令、及常见报错处理:You have not concluded your merge (MERGE_HEAD exists)
  19. Tief Meer alt singen nennen Papa.Magnam natus consequuntur corporis laudantium.
  20. websocket + node 手把手实现简陋聊天室

热门文章

  1. 为何TVS二极管被称为ESD静电的克星?
  2. java int的最大值_int 最大值
  3. 【快手API】根据ID取商品详情 API 返回值说明
  4. 近20年最全目标检测综述(第二期)
  5. 【论文阅读】2023 MTS-Mixers
  6. C# swich, constant, readonly,static, StringBuilder 和字段与属性
  7. 树莓派连接WiFi与查找IP
  8. SpringBoot美化日志输出——自定义Banner艺术字体
  9. 西门子s7 200smart与3台施耐德ATV12变频器通讯
  10. VMWare15安装MacOS系统及设置分辨率