Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
839acd3e
Commit
839acd3e
authored
Oct 10, 2015
by
Davis King
Browse files
Setup CMake and related things to build dlib with CUDA support.
parent
caf87fa4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
9 deletions
+102
-9
dlib/CMakeLists.txt
dlib/CMakeLists.txt
+61
-4
dlib/config.h
dlib/config.h
+6
-3
dlib/config.h.in
dlib/config.h.in
+3
-2
dlib/dnn/cuda.cu
dlib/dnn/cuda.cu
+29
-0
dlib/dnn/cuda.h
dlib/dnn/cuda.h
+3
-0
No files found.
dlib/CMakeLists.txt
View file @
839acd3e
...
...
@@ -58,6 +58,8 @@ if (NOT TARGET dlib)
"Disable this if you don't want to use a BLAS library"
)
set
(
DLIB_USE_LAPACK_STR
"Disable this if you don't want to use a LAPACK library"
)
set
(
DLIB_USE_CUDA_STR
"Disable this if you don't want to use NVIDIA CUDA"
)
set
(
DLIB_PNG_SUPPORT_STR
"Disable this if you don't want to link against libpng"
)
set
(
DLIB_JPEG_SUPPORT_STR
...
...
@@ -81,6 +83,7 @@ if (NOT TARGET dlib)
option
(
DLIB_USE_BLAS
${
DLIB_USE_BLAS_STR
}
ON
)
option
(
DLIB_USE_LAPACK
${
DLIB_USE_LAPACK_STR
}
ON
)
option
(
DLIB_USE_CUDA
${
DLIB_USE_CUDA_STR
}
ON
)
option
(
DLIB_PNG_SUPPORT
${
DLIB_PNG_SUPPORT_STR
}
ON
)
option
(
DLIB_JPEG_SUPPORT
${
DLIB_JPEG_SUPPORT_STR
}
ON
)
option
(
DLIB_LINK_WITH_SQLITE3
${
DLIB_LINK_WITH_SQLITE3_STR
}
ON
)
...
...
@@ -368,6 +371,44 @@ if (NOT TARGET dlib)
endif
()
if
(
DLIB_USE_CUDA
)
find_package
(
CUDA
)
if
(
CUDA_FOUND
)
if
(
CUDA_VERSION_STRING LESS
"7.0"
)
message
(
FATAL_ERROR
"dlib requires CUDA version 7.0 or higher"
)
endif
()
message
(
STATUS
"Looking for cuDNN install..."
)
# Look for cudnn, we will look in the same place as other CUDA
# libraries and also a few other places as well.
find_path
(
cudnn_include cudnn.h
HINTS
${
CUDA_INCLUDE_DIRS
}
PATHS /usr/local/include
)
get_filename_component
(
cudnn_hint_path
${
CUDA_CUBLAS_LIBRARIES
}
PATH
)
find_library
(
cudnn cudnn
HINTS
${
cudnn_hint_path
}
PATHS /usr/local/lib64
/usr/local/cuda/lib64
/usr/local/cuda/lib
/usr/local/lib
)
mark_as_advanced
(
cudnn cudnn_include
)
endif
()
if
(
CUDA_FOUND AND cudnn AND cudnn_include
)
message
(
STATUS
"Found cuDNN: "
${
cudnn
}
)
set
(
source_files
${
source_files
}
dnn/cuda.cu
)
set
(
dlib_needed_libraries
${
dlib_needed_libraries
}
${
CUDA_CUBLAS_LIBRARIES
}
${
cudnn
}
)
include_directories
(
${
cudnn_include
}
)
else
()
set
(
DLIB_USE_CUDA OFF CACHE STRING
${
DLIB_USE_BLAS_STR
}
FORCE
)
message
(
STATUS
"cuDNN NOT FOUND. DLIB WILL NOT USE CUDA"
)
endif
()
endif
()
if
(
DLIB_LINK_WITH_SQLITE3
)
find_library
(
sqlite sqlite3
)
...
...
@@ -398,12 +439,22 @@ if (NOT TARGET dlib)
mark_as_advanced
(
fftw fftw_path
)
endif
()
add_library
(
dlib STATIC
${
source_files
}
)
target_link_libraries
(
dlib
${
dlib_needed_libraries
}
)
# Tell CMake to build dlib via add_library()/cuda_add_library()
if
(
DLIB_USE_CUDA
)
cuda_add_library
(
dlib STATIC
${
source_files
}
)
else
()
add_library
(
dlib STATIC
${
source_files
}
)
endif
()
target_link_libraries
(
dlib
${
dlib_needed_libraries
}
)
if
(
UNIX AND NOT DLIB_IN_PROJECT_BUILD
)
add_library
(
dlib-shared SHARED
${
source_files
}
)
target_link_libraries
(
dlib-shared
${
dlib_needed_libraries
}
)
if
(
DLIB_USE_CUDA
)
cuda_add_library
(
dlib-shared SHARED
${
source_files
}
)
else
()
add_library
(
dlib-shared SHARED
${
source_files
}
)
endif
()
target_link_libraries
(
dlib-shared
${
dlib_needed_libraries
}
)
endif
()
endif
()
##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
...
...
@@ -488,6 +539,12 @@ if (NOT TARGET dlib)
remove_global_define
(
DLIB_USE_FFTW
)
endif
()
if
(
DLIB_USE_CUDA AND NOT DLIB_ISO_CPP_ONLY
)
add_global_define
(
DLIB_USE_CUDA
)
else
()
remove_global_define
(
DLIB_USE_CUDA
)
endif
()
if
(
DLIB_USE_BLAS AND blas_found
)
add_global_define
(
DLIB_USE_BLAS
)
...
...
dlib/config.h
View file @
839acd3e
...
...
@@ -10,12 +10,15 @@
//#define ENABLE_ASSERTS // asserts always enabled
//#define DLIB_DISABLE_ASSERTS // asserts always disabled
//#define DLIB_ISO_CPP_ONLY
//#define DLIB_NO_GUI_SUPPORT
//#define DLIB_ENABLE_STACK_TRACE
// You should also consider telling dlib to link against libjpeg, libpng, fftw, and a BLAS
// and LAPACK library. To do this you need to uncomment the following #defines.
// You should also consider telling dlib to link against libjpeg, libpng, fftw, CUDA, and a
// BLAS and LAPACK library. To do this you need to uncomment the following #defines.
// #define DLIB_JPEG_SUPPORT
// #define DLIB_PNG_SUPPORT
// #define DLIB_USE_FFTW
// #define DLIB_USE_BLAS
// #define DLIB_USE_LAPACK
// #define DLIB_USE_CUDA
dlib/config.h.in
View file @
839acd3e
...
...
@@ -14,10 +14,11 @@
#cmakedefine DLIB_NO_GUI_SUPPORT
#cmakedefine DLIB_ENABLE_STACK_TRACE
// You should also consider telling dlib to link against libjpeg, libpng, fftw, and a
BLAS
// and LAPACK library. To do this you need to uncomment the following #defines.
// You should also consider telling dlib to link against libjpeg, libpng, fftw,
CUDA,
and a
//
BLAS
and LAPACK library. To do this you need to uncomment the following #defines.
#cmakedefine DLIB_JPEG_SUPPORT
#cmakedefine DLIB_PNG_SUPPORT
#cmakedefine DLIB_USE_FFTW
#cmakedefine DLIB_USE_BLAS
#cmakedefine DLIB_USE_LAPACK
#cmakedefine DLIB_USE_CUDA
dlib/dnn/cuda.cu
0 → 100644
View file @
839acd3e
#include <stdlib.h>
#include <stdio.h>
#define CHECK(call) \
{ \
const cudaError_t error = call; \
if (error != cudaSuccess) \
{ \
fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__); \
fprintf(stderr, "code: %d, reason: %s\n", error, \
cudaGetErrorString(error)); \
exit(1); \
} \
}
__global__
void
helloFromGPU
()
{
printf
(
"Hello World from GPU!
\n
"
);
}
void
hello_cuda
()
{
printf
(
"Hello World from CPU!
\n
"
);
helloFromGPU
<<<
1
,
10
>>>
();
CHECK
(
cudaDeviceReset
());
}
dlib/dnn/cuda.h
View file @
839acd3e
...
...
@@ -7,6 +7,9 @@
#include "tensor.h"
// TODO, remove this cruft
void
hello_cuda
();
namespace
dlib
{
namespace
cuda
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment