Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
d63c4682
Commit
d63c4682
authored
Oct 19, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some of the cuDNN conv calls.
parent
1022b5b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
3 deletions
+95
-3
cudnn_dlibapi.cpp
dlib/dnn/cudnn_dlibapi.cpp
+73
-2
cudnn_dlibapi.h
dlib/dnn/cudnn_dlibapi.h
+22
-1
No files found.
dlib/dnn/cudnn_dlibapi.cpp
View file @
d63c4682
...
...
@@ -9,6 +9,7 @@
#include "tensor.h"
#include <cudnn.h>
#include <iostream>
#include <string>
#include "cuda_utils.h"
...
...
@@ -31,10 +32,11 @@ namespace dlib
case
CUDNN_STATUS_BAD_PARAM
:
throw
cudnn_error
(
"CUDNN_STATUS_BAD_PARAM"
);
default
:
throw
cudnn_error
(
"A call to cuDNN failed
."
);
throw
cudnn_error
(
"A call to cuDNN failed
: "
+
std
::
string
(
cudnnGetErrorString
(
s
))
);
}
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
cudnn_context
::
cudnn_context
()
:
handle
(
nullptr
)
...
...
@@ -162,14 +164,83 @@ namespace dlib
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
conv
::
conv
(
conv
::
conv
(
)
:
filter_handle
(
nullptr
),
conv_handle
(
nullptr
),
out_num_samples
(
0
),
out_k
(
0
),
out_nr
(
0
),
out_nc
(
0
)
{
}
void
conv
::
clear
(
)
{
if
(
filter_handle
)
cudnnDestroyFilterDescriptor
((
cudnnFilterDescriptor_t
)
filter_handle
);
if
(
conv_handle
)
cudnnDestroyConvolutionDescriptor
((
cudnnConvolutionDescriptor_t
)
conv_handle
);
filter_handle
=
nullptr
;
conv_handle
=
nullptr
;
out_num_samples
=
0
;
out_k
=
0
;
out_nr
=
0
;
out_nc
=
0
;
}
void
conv
::
setup
(
cudnn_context
&
context
,
const
tensor
&
data
,
const
tensor
&
filters
,
int
stride_y
,
int
stride_x
)
{
clear
();
try
{
check
(
cudnnCreateFilterDescriptor
((
cudnnFilterDescriptor_t
*
)
&
filter_handle
));
check
(
cudnnSetFilter4dDescriptor
((
cudnnFilterDescriptor_t
)
filter_handle
,
CUDNN_DATA_FLOAT
,
filters
.
num_samples
(),
filters
.
k
(),
filters
.
nr
(),
filters
.
nc
()));
check
(
cudnnCreateConvolutionDescriptor
((
cudnnConvolutionDescriptor_t
*
)
&
conv_handle
));
check
(
cudnnSetConvolution2dDescriptor
((
cudnnConvolutionDescriptor_t
)
conv_handle
,
filters
.
nr
()
/
2
,
// vertical padding
filters
.
nc
()
/
2
,
// horizontal padding
stride_y
,
stride_x
,
1
,
1
,
// must be 1,1
CUDNN_CONVOLUTION
));
// could also be CUDNN_CROSS_CORRELATION
check
(
cudnnGetConvolution2dForwardOutputDim
(
(
const
cudnnConvolutionDescriptor_t
)
conv_handle
,
(
const
cudnnTensorDescriptor_t
)
data
.
get_cudnn_tensor_descriptor
().
get_handle
(),
(
const
cudnnFilterDescriptor_t
)
filter_handle
,
&
out_num_samples
,
&
out_k
,
&
out_nr
,
&
out_nc
));
}
catch
(...)
{
clear
();
}
}
conv
::
~
conv
(
)
{
clear
();
}
void
conv
::
operator
()
(
...
...
dlib/dnn/cudnn_dlibapi.h
View file @
d63c4682
...
...
@@ -66,6 +66,10 @@ namespace dlib
int
nc
,
int
k
);
/*!
ensures
- if any of the arguments are 0 then they are all set to 0 in the tensor.
!*/
void
get_size
(
int
&
n
,
...
...
@@ -145,7 +149,12 @@ namespace dlib
conv
(
const
conv
&
)
=
delete
;
conv
&
operator
=
(
const
conv
&
)
=
delete
;
conv
(
conv
();
void
clear
(
);
void
setup
(
cudnn_context
&
context
,
const
tensor
&
data
,
const
tensor
&
filters
,
...
...
@@ -153,6 +162,9 @@ namespace dlib
int
stride_x
);
~
conv
(
);
void
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
...
...
@@ -210,6 +222,15 @@ namespace dlib
and adds this gradient to filters_gradient.
!*/
private
:
void
*
filter_handle
;
void
*
conv_handle
;
// dimensions of the output tensor from operator()
int
out_num_samples
;
int
out_nr
;
int
out_nc
;
int
out_k
;
};
// ------------------------------------------------------------------------------------
...
...
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