版权声明:本文为博主原创文章,未经作者允许请勿转载。 https://blog.csdn.net/heiheiya https://blog.csdn.net/heiheiya/article/details/89310825
接上篇【Tensorflow】Windows以cmake+visual studio方式编译cpu版tensorflow.dll和tensorflow.lib,这里就简略介绍了。
前提是先安装好CUDA和CUDNN。
除了【Tensorflow】Windows以cmake+visual studio方式编译cpu版tensorflow.dll和tensorflow.lib里编译cpu篇提到的CMakeList.txt里修改的部分,还可以按需要修改如下几个地方。
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_30,code=\"sm_30,compute_30\";-gencode arch=compute_35,code=\"sm_35,compute_35\";-gencode arch=compute_52,code=\"sm_52,compute_52\";-gencode arch=compute_61,code=\"sm_61,compute_61\")
if (WIN32)
add_definitions(-DGOOGLE_CUDA=1 -DTF_EXTRA_CUDA_CAPABILITIES=3.0,3.5,5.2,6.1)
else (WIN32)
# Without these double quotes, cmake in Linux makes it "-DTF_EXTRA_CUDA_CAPABILITIES=3.0, -D3.5, -D5.2" for cc, which incurs build breaks
add_definitions(-DGOOGLE_CUDA=1 -D"TF_EXTRA_CUDA_CAPABILITIES=3.0,3.5,5.2,6.1")
endif (WIN32)
FILE(WRITE ${tensorflow_source_dir}/third_party/gpus/cuda/cuda_config.h
"#ifndef CUDA_CUDA_CONFIG_H_\n"
"#define CUDA_CUDA_CONFIG_H_\n"
"#define TF_CUDA_CAPABILITIES CudaVersion(\"3.0\"),CudaVersion(\"3.5\"),CudaVersion(\"5.2\"),CudaVersion(\"6.1\")\n"
"#define TF_CUDA_VERSION \"64_${short_CUDA_VER}\"\n"
"#define TF_CUDNN_VERSION \"64_${tensorflow_CUDNN_VERSION}\"\n"
"#define TF_CUDA_TOOLKIT_PATH \"${CUDA_TOOLKIT_ROOT_DIR}\"\n"
"#endif // CUDA_CUDA_CONFIG_H_\n"
)
主要是根据GPU的计算能力进行修改,设置更多的计算能力,相应的增加编译时长。
这里cmake的配置勾选tensorflow_ENABLE_GPU。
生成之后,就可以用visual studio打开tensorflow.sln进行编译。
编译过程可能遇到的错误请参考链接:
【Tensorflow】more than one instance of overloaded function "__hadd" matches the argument list错误的解决方法,但是注意cmake方式编译修改的文件是tensorflow-master\tensorflow\contrib\cmake\build\external\eigen_archive\Eigen\src\Core\arch\CUDA\Half.h。