VS2017为何编译Dlib DNN系列代码hangup

Dlib 19.7 + VS2017

http://dlib.net/faq.html#Whyisdlibslow

Why can't I use the DNN module with Visual Studio?

You can, but you need to use Visual Studio 2015 Update 3 or newer since prior versions had bad C++11 support. To make this as confusing as possible, Microsoft has released multiple different versions of "Visual Studio 2015 Update 3". As of October 2016, the version available from the Microsoft web page has good enough C++11 support to compile the DNN tools in dlib. So make sure you have a version no older than October 2016.
However, as of this writing, the newest version of Visual Studio is Visual Studio 2017, which has WORSE C++11 support that Visual Studio 2015. In particular, if you try to use the DNN tooling in Visual Studio 2017 the compiler will just hang. So use Visual Studio 2015.

It should also be noted that not even Visual Studio 2015 has perfect C++11 support. Specifically, the larger and more complex imagenet and metric learning training examples don't compile in Visual Studio 2015.

编译结果

PS D:\work\book\new Book\MachineLearn(DeepLearn)\OpenSourceFramework\dlib\dlib-master\examples\build> cmake -G "Visual Studio 14 2015 Win64" ..
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Enabling SSE2 instructions
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- A library with BLAS API not found. Please specify library location.
-- LAPACK requires BLAS
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0 (found suitable version "9.0", minimum required is "7.5")
-- Looking for cuDNN install...
-- Found cuDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/lib/x64/cudnn.lib
-- Building a CUDA test project to see if your compiler is compatible with CUDA...
-- Checking if you have the right version of cuDNN installed.
-- Enabling CUDA support for dlib.  DLIB WILL USE CUDA
-- C++11 activated.
OpenCV not found, so we won't build the webcam_face_pose_ex example.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/work/book/new Book/MachineLearn(DeepLearn)/OpenSourceFramework/dlib/dlib-master/examples/build

VS2015对C++11 的SFINAE 支持比较好。其他版本暂时没有支持

https://github.com/davisking/dlib/issues/946


最新版本 把递归函数改成inline 放入头文件,能节省 很多 RAM 占用率。        

 [20171201 UTC]
davisking commented 5 days ago
Someone discovered that disabling inlining of recursive functions in visual studio 2015 significantly improves the RAM usage and build times of the DNN examples. I pushed this change to github last night. So at least you can compile all the DNN examples with visual studio 2015 in reasonable time. VC2017 still has additional C++11 bugs that prevent it from working though.

在VS 2015 Update 3 中对SFINAE表达式的改进
https://blogs.msdn.microsoft.com/c/2016/06/16/在vs-2015-update-3-中对sfinae表达式的改进/

什么是SFINAE?

提醒一下,SFINAE是‘Substitution Failure Is Not An Error’的缩写。其理念是当编译器尝试在重载解析时去特化一个函数模板,即使特化失败,只要还有其他的有效对象就可以。C++11介绍了诸如像decltype和constexpr的功能,并且在模板参数推导和替换过程中有表达式更为普遍。C++标准委员会阐明了C++11中SFINAE表达式的规则。

cppreference sfinae

=============20171204

https://github.com/davisking/dlib/issues/946

 davisking commented 3 days ago 

Sweet. I just tried it with the newest version of VS2017 and they all work now. Also, if you give -T host=x64 to cmake when generating the project it will use the 64bit toolchain. That allowed me to compile the examples that would otherwise cause VS to run out of RAM and crash.

So at this point it looks like the newest VS2017 works correctly for everything!

嗯,赶紧删了VS2015

posted @ 2017-11-08 22:26  scott_h  阅读(1306)  评论(0编辑  收藏  举报