Skip to content

Commit 51682b0

Browse files
authored
Clean API (luoyetx#10)
* remove im2col layer, remove V0 LayerParameter * move file structure * clean * update * update * memory usage * move layer factory
1 parent 64c1a75 commit 51682b0

File tree

101 files changed

+630
-2186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+630
-2186
lines changed

cmake/Cuda.cmake

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@ if(NOT USE_CUDA)
22
return()
33
endif()
44

5+
include(CheckCXXCompilerFlag)
6+
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
7+
8+
################################################################################################
9+
# Removes duplicates from list(s)
10+
# Usage:
11+
# caffe_list_unique(<list_variable> [<list_variable>] [...])
12+
macro(caffe_list_unique)
13+
foreach(__lst ${ARGN})
14+
if(${__lst})
15+
list(REMOVE_DUPLICATES ${__lst})
16+
endif()
17+
endforeach()
18+
endmacro()
19+
520
# Known NVIDIA GPU achitectures Caffe can be compiled for.
621
# This list will be used for CUDA_ARCH_NAME = All option
7-
set(Caffe_known_gpu_archs "30 35 50 60 61")
22+
set(Caffe_known_gpu_archs "20 21(20) 30 35 50 60 61")
823

924
################################################################################################
1025
# A function for automatic detection of GPUs installed (if autodetection is enabled)
@@ -29,20 +44,32 @@ function(caffe_detect_installed_gpus out_variable)
2944
" }\n"
3045
" return 0;\n"
3146
"}\n")
32-
47+
if(MSVC)
48+
# Add directory of "cl.exe" to system path, otherwise "nvcc --run" will fail with "Cannot find compiler 'cl.exe' in PATH"
49+
get_filename_component(CL_DIR ${CMAKE_C_COMPILER} DIRECTORY)
50+
set(ENV{PATH} "$ENV{PATH};${CL_DIR}")
51+
endif()
3352
execute_process(COMMAND "${CUDA_NVCC_EXECUTABLE}" "--run" "${__cufile}"
3453
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/"
3554
RESULT_VARIABLE __nvcc_res OUTPUT_VARIABLE __nvcc_out
36-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
55+
ERROR_QUIET
56+
OUTPUT_STRIP_TRAILING_WHITESPACE)
3757

3858
if(__nvcc_res EQUAL 0)
39-
set(CUDA_gpu_detect_output ${__nvcc_out} CACHE INTERNAL "Returned GPU architetures from caffe_detect_gpus tool" FORCE)
59+
# nvcc outputs text containing line breaks when building with MSVC.
60+
# The line below prevents CMake from inserting a variable with line
61+
# breaks in the cache
62+
string(REGEX MATCH "([1-9].[0-9])" __nvcc_out "${__nvcc_out}")
63+
string(REPLACE "2.1" "2.1(2.0)" __nvcc_out "${__nvcc_out}")
64+
set(CUDA_gpu_detect_output ${__nvcc_out} CACHE INTERNAL "Returned GPU architetures from mshadow_detect_gpus tool" FORCE)
65+
else()
66+
message(WARNING "Running GPU detection script with nvcc failed: ${__nvcc_out}")
4067
endif()
4168
endif()
4269

4370
if(NOT CUDA_gpu_detect_output)
44-
message(STATUS "Automatic GPU detection failed. Building for all known architectures.")
45-
set(${out_variable} ${Caffe_known_gpu_archs} PARENT_SCOPE)
71+
message(WARNING "Automatic GPU detection failed. Building for all known architectures (${mshadow_known_gpu_archs}).")
72+
set(${out_variable} ${mshadow_known_gpu_archs} PARENT_SCOPE)
4673
else()
4774
set(${out_variable} ${CUDA_gpu_detect_output} PARENT_SCOPE)
4875
endif()
@@ -55,7 +82,7 @@ endfunction()
5582
# caffe_select_nvcc_arch_flags(out_variable)
5683
function(caffe_select_nvcc_arch_flags out_variable)
5784
# List of arch names
58-
set(__archs_names "Kepler" "Maxwell" "Pascal" "All" "Manual")
85+
set(__archs_names "Fermi" "Kepler" "Maxwell" "Pascal" "All" "Manual")
5986
set(__archs_name_default "All")
6087
if(NOT CMAKE_CROSSCOMPILING)
6188
list(APPEND __archs_names "Auto")
@@ -82,7 +109,9 @@ function(caffe_select_nvcc_arch_flags out_variable)
82109
unset(CUDA_ARCH_PTX CACHE)
83110
endif()
84111

85-
if(${CUDA_ARCH_NAME} STREQUAL "Kepler")
112+
if(${CUDA_ARCH_NAME} STREQUAL "Fermi")
113+
set(__cuda_arch_bin "20 21(20)")
114+
elseif(${CUDA_ARCH_NAME} STREQUAL "Kepler")
86115
set(__cuda_arch_bin "30 35")
87116
elseif(${CUDA_ARCH_NAME} STREQUAL "Maxwell")
88117
set(__cuda_arch_bin "50")
@@ -137,21 +166,24 @@ endfunction()
137166
macro(caffe_cuda_compile objlist_variable)
138167
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
139168
set(${var}_backup_in_cuda_compile_ "${${var}}")
140-
141169
# we remove /EHa as it generates warnings under windows
142170
string(REPLACE "/EHa" "" ${var} "${${var}}")
143-
144171
endforeach()
145172

146173
if(UNIX OR APPLE)
147174
list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC)
175+
if(SUPPORT_CXX11)
176+
list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC --std=c++11)
177+
endif()
148178
endif()
149179

150180
if(APPLE)
151181
list(APPEND CUDA_NVCC_FLAGS -Xcompiler -Wno-unused-function)
152182
endif()
153183

154184
if(MSVC)
185+
# disable noisy warnings:
186+
# 4819: The file contains a character that cannot be represented in the current code page (number).
155187
list(APPEND CUDA_NVCC_FLAGS -Xcompiler "/wd4819")
156188
endif()
157189

@@ -177,56 +209,17 @@ function(detect_cuDNN)
177209
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDA_TOOLKIT_INCLUDE}
178210
DOC "Path to cuDNN include directory." )
179211

180-
# dynamic libs have different suffix in mac and linux
181-
if(APPLE)
182-
set(CUDNN_LIB_NAME "libcudnn.dylib")
183-
elseif(WIN32)
184-
set(CUDNN_LIB_NAME "cudnn.lib")
185-
else()
186-
set(CUDNN_LIB_NAME "libcudnn.so")
187-
endif()
188-
189212
get_filename_component(__libpath_hist ${CUDA_CUDART_LIBRARY} PATH)
190-
find_library(CUDNN_LIBRARY NAMES ${CUDNN_LIB_NAME}
191-
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE} ${__libpath_hist} ${__libpath_hist}/../lib
192-
DOC "Path to cuDNN library.")
213+
find_library(CUDNN_LIBRARY NAMES libcudnn.so cudnn.lib # libcudnn_static.a
214+
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE} ${__libpath_hist}
215+
DOC "Path to cuDNN library.")
193216

194217
if(CUDNN_INCLUDE AND CUDNN_LIBRARY)
195218
set(HAVE_CUDNN TRUE PARENT_SCOPE)
196219
set(CUDNN_FOUND TRUE PARENT_SCOPE)
197220

198-
file(READ ${CUDNN_INCLUDE}/cudnn.h CUDNN_VERSION_FILE_CONTENTS)
199-
200-
# cuDNN v3 and beyond
201-
string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)"
202-
CUDNN_VERSION_MAJOR "${CUDNN_VERSION_FILE_CONTENTS}")
203-
string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1"
204-
CUDNN_VERSION_MAJOR "${CUDNN_VERSION_MAJOR}")
205-
string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)"
206-
CUDNN_VERSION_MINOR "${CUDNN_VERSION_FILE_CONTENTS}")
207-
string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1"
208-
CUDNN_VERSION_MINOR "${CUDNN_VERSION_MINOR}")
209-
string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)"
210-
CUDNN_VERSION_PATCH "${CUDNN_VERSION_FILE_CONTENTS}")
211-
string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1"
212-
CUDNN_VERSION_PATCH "${CUDNN_VERSION_PATCH}")
213-
214-
if(NOT CUDNN_VERSION_MAJOR)
215-
set(CUDNN_VERSION "???")
216-
else()
217-
set(CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}")
218-
endif()
219-
220-
message(STATUS "Found cuDNN: ver. ${CUDNN_VERSION} found (include: ${CUDNN_INCLUDE}, library: ${CUDNN_LIBRARY})")
221-
222-
string(COMPARE LESS "${CUDNN_VERSION_MAJOR}" 3 cuDNNVersionIncompatible)
223-
if(cuDNNVersionIncompatible)
224-
message(FATAL_ERROR "cuDNN version >3 is required.")
225-
endif()
226-
227-
set(CUDNN_VERSION "${CUDNN_VERSION}" PARENT_SCOPE)
228221
mark_as_advanced(CUDNN_INCLUDE CUDNN_LIBRARY CUDNN_ROOT)
229-
222+
message(STATUS "Found cuDNN (include: ${CUDNN_INCLUDE}, library: ${CUDNN_LIBRARY})")
230223
endif()
231224
endfunction()
232225

0 commit comments

Comments
 (0)