Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4df0b99
提交
c4df0b99
authored
7月 24, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify GpuDnnConvGradW to support timing feature
上级
a5fe8e38
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
94 行增加
和
50 行删除
+94
-50
dnn.py
theano/sandbox/cuda/dnn.py
+33
-18
dnn_gw.c
theano/sandbox/cuda/dnn_gw.c
+61
-32
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
c4df0b99
...
...
@@ -695,8 +695,8 @@ class GpuDnnConvGradW(DnnBase, COp):
def
__init__
(
self
,
inplace
=
False
,
workmem
=
None
,
algo
=
None
):
"""
:param workmem: *deprecated*, use param algo instead
:param algo: either 'none', 'deterministic', 'fft', 'guess_once'
or
'guess_on_shape_change'.
:param algo: either 'none', 'deterministic', 'fft', 'guess_once'
,
'guess_on_shape_change'
, 'time_once' or 'time_on_shape_change'
.
Default is the value of :attr:`config.dnn.conv.algo_bwd`.
"""
COp
.
__init__
(
self
,
[
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_gw.c"
],
...
...
@@ -716,7 +716,8 @@ class GpuDnnConvGradW(DnnBase, COp):
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
2
]}
assert
self
.
algo
in
[
'none'
,
'deterministic'
,
'fft'
,
'guess_once'
,
'guess_on_shape_change'
]
'guess_on_shape_change'
,
'time_once'
,
'time_on_shape_change'
]
def
__setstate__
(
self
,
d
):
self
.
__dict__
.
update
(
d
)
...
...
@@ -752,29 +753,42 @@ class GpuDnnConvGradW(DnnBase, COp):
else
:
inplace_def
=
[]
alg_choose_once_def
=
(
'CHOOSE_ALGO_ONCE'
,
'0'
)
choose_alg
=
'0'
choose_alg_once
=
'0'
choose_alg_time
=
'0'
if
version
()
==
-
1
or
version
()
<
(
3000
,
3000
):
alg_def
=
(
'CONV_ALGO'
,
'0'
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
'0'
)
alg
=
"0"
else
:
if
self
.
algo
==
'none'
:
alg_def
=
(
'CONV_ALGO'
,
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0'
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
'0'
)
alg
=
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0'
elif
self
.
algo
==
'deterministic'
:
alg_def
=
(
'CONV_ALGO'
,
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_1'
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
'0'
)
alg
=
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_1'
elif
self
.
algo
==
'fft'
:
alg_def
=
(
'CONV_ALGO'
,
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_FFT'
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
'0'
)
alg
=
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_FFT'
elif
self
.
algo
in
[
'guess_once'
,
'guess_on_shape_change'
]:
# The convolution implementation should be cho
o
sen according
# The convolution implementation should be chosen according
# to a heuristic
alg
_def
=
(
'CONV_ALGO'
,
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0'
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
'1'
)
alg
=
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0'
choose_alg
=
'1'
if
self
.
algo
==
'guess_once'
:
alg_choose_once_def
=
(
'CHOOSE_ALGO_ONCE'
,
'1'
)
choose_alg_once
=
'1'
elif
self
.
algo
in
[
'time_once'
,
'guess_on_shape_change'
]:
# The convolution implementation should be chosen according
# to timing
alg
=
'CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0'
choose_alg
=
'1'
choose_alg_time
=
'1'
if
self
.
algo
==
'time_once'
:
choose_alg_once
=
'1'
return
inplace_def
+
[
alg_def
,
alg_choose_def
,
alg_choose_once_def
]
alg_def
=
(
'CONV_ALGO'
,
alg
)
alg_choose_def
=
(
'CHOOSE_ALGO'
,
choose_alg
)
alg_choose_once_def
=
(
'CHOOSE_ALGO_ONCE'
,
choose_alg_once
)
alg_choose_time_def
=
(
'CHOOSE_ALGO_TIME'
,
choose_alg_time
)
return
inplace_def
+
[
alg_def
,
alg_choose_def
,
alg_choose_once_def
,
alg_choose_time_def
]
def
make_node
(
self
,
img
,
topgrad
,
output
,
desc
,
alpha
=
None
,
beta
=
None
):
img
=
as_cuda_ndarray_variable
(
img
)
...
...
@@ -828,7 +842,8 @@ class GpuDnnConv3dGradW(GpuDnnConvGradW):
super
(
GpuDnnConv3dGradW
,
self
)
.
__init__
(
inplace
=
inplace
,
algo
=
'none'
)
assert
self
.
algo
in
[
'none'
,
'guess_once'
,
'guess_on_shape_change'
]
assert
self
.
algo
in
[
'none'
,
'guess_once'
,
'guess_on_shape_change'
,
'time_once'
,
'time_on_shape_change'
]
def
grad
(
self
,
inp
,
grads
):
img
,
top
,
output
,
desc
,
alpha
,
beta
=
inp
...
...
theano/sandbox/cuda/dnn_gw.c
浏览文件 @
c4df0b99
...
...
@@ -42,8 +42,8 @@ APPLY_SPECIFIC(conv_gw)(CudaNdarray *input, CudaNdarray *output,
if
(
CHOOSE_ALGO
)
{
// A new convolution implementation should be selected, based on
// heuristics, if in one of the two following cases :
// A new convolution implementation should be selected, based
either
on
//
timing or
heuristics, if in one of the two following cases :
// - The implementation should only be chosen during the first execution
// of an apply node and this is the first execution of the apply node.
// - The implementation should be chosen as often as necessary and the
...
...
@@ -75,35 +75,64 @@ APPLY_SPECIFIC(conv_gw)(CudaNdarray *input, CudaNdarray *output,
// new one based on the shapes of the current inputs
if
(
!
reuse_previous_algo
)
{
// Choose the convolution implementation using heuristics based on the
// shapes of the inputs and the amount of memory available.
// Get the amount of available memory
size_t
free
=
0
,
total
=
0
;
cudaError_t
err2
=
cudaMemGetInfo
(
&
free
,
&
total
);
if
(
err2
!=
cudaSuccess
){
cudaGetLastError
();
fprintf
(
stderr
,
"Error when trying to find the memory information"
" on the GPU: %s
\n
"
,
cudaGetErrorString
(
err2
));
return
1
;
// Obtain a convolution algorithm appropriate for the input and output
// shapes. Either by choosing one according to heuristics or by making
// CuDNN time every implementation and choose the best one.
if
(
CHOOSE_ALGO_TIME
)
{
// Time the different implementations to choose the best one
int
requestedCount
=
1
;
int
count
;
cudnnConvolutionBwdFilterAlgoPerf_t
choosen_algo_perf
;
err
=
cudnnFindConvolutionBackwardFilterAlgorithm
(
_handle
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
output
),
desc
,
APPLY_SPECIFIC
(
kerns
),
requestedCount
,
&
count
,
&
choosen_algo_perf
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"GpuDnnConvGradW: error selecting convolution algo: "
"%s"
,
cudnnGetErrorString
(
err
));
return
1
;
}
chosen_algo
=
choosen_algo_perf
.
algo
;
}
// Use heuristics to choose the implementation
err
=
cudnnGetConvolutionBackwardFilterAlgorithm
(
_handle
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
output
),
desc
,
APPLY_SPECIFIC
(
kerns
),
CUDNN_CONVOLUTION_BWD_FILTER_PREFER_FASTEST
,
free
,
&
chosen_algo
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"GpuDnnConvGradW: error selecting convolution algo: %s"
,
cudnnGetErrorString
(
err
));
return
1
;
else
{
// Choose the convolution implementation using heuristics based on the
// shapes of the inputs and the amount of memory available.
// Get the amount of available memory
size_t
free
=
0
,
total
=
0
;
cudaError_t
err2
=
cudaMemGetInfo
(
&
free
,
&
total
);
if
(
err2
!=
cudaSuccess
){
cudaGetLastError
();
fprintf
(
stderr
,
"Error when trying to find the memory information"
" on the GPU: %s
\n
"
,
cudaGetErrorString
(
err2
));
return
1
;
}
// Use heuristics to choose the implementation
err
=
cudnnGetConvolutionBackwardFilterAlgorithm
(
_handle
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
output
),
desc
,
APPLY_SPECIFIC
(
kerns
),
CUDNN_CONVOLUTION_BWD_SPECIFY_WORKSPACE_LIMIT
,
free
,
&
chosen_algo
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"GpuDnnConvGradW: error selecting convolution algo: %s"
,
cudnnGetErrorString
(
err
));
return
1
;
}
}
// Store the shapes of the inputs and kernels as well as the chosen
...
...
@@ -129,8 +158,8 @@ APPLY_SPECIFIC(conv_gw)(CudaNdarray *input, CudaNdarray *output,
chosen_algo
=
CONV_ALGO
;
}
// The FFT implementation
does not support strides, 1x1 filters or
// inputs with a spatial dimension larger than 1024.
// The FFT implementation
(only in v3 and onward) does not support strides,
//
1x1 filters or
inputs with a spatial dimension larger than 1024.
// If the chosen implementation is FFT, validate that it can be used
// on the current data and default on a safe implementation if it
// can't.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论