Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f9b85e1e
提交
f9b85e1e
authored
6月 11, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement cudnn implementation selection for FWD pass
上级
2b83b6ac
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
102 行增加
和
4 行删除
+102
-4
dnn.py
theano/sandbox/cuda/dnn.py
+8
-1
dnn_conv_base.c
theano/sandbox/cuda/dnn_conv_base.c
+19
-1
dnn_fwd.c
theano/sandbox/cuda/dnn_fwd.c
+75
-2
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
f9b85e1e
...
@@ -416,12 +416,19 @@ class GpuDnnConv(DnnBase, COp):
...
@@ -416,12 +416,19 @@ class GpuDnnConv(DnnBase, COp):
else
:
else
:
if
self
.
workmem
==
'none'
:
if
self
.
workmem
==
'none'
:
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM'
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM'
choose_alg
=
'0'
elif
self
.
workmem
==
'small'
:
elif
self
.
workmem
==
'small'
:
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM'
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM'
choose_alg
=
'0'
elif
self
.
workmem
==
'large'
:
elif
self
.
workmem
==
'large'
:
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_GEMM'
alg
=
'CUDNN_CONVOLUTION_FWD_ALGO_GEMM'
choose_alg
=
'0'
elif
self
.
workmem
==
'time'
:
alg
=
"0"
choose_alg
=
'1'
alg_def
=
(
'CONV_ALGO'
,
alg
)
alg_def
=
(
'CONV_ALGO'
,
alg
)
return
[
alg_def
]
+
inpl_def
alg_choose_def
=
(
'CHOOSE_ALGO'
,
choose_alg
)
return
[
alg_def
,
alg_choose_def
]
+
inpl_def
def
make_node
(
self
,
img
,
kern
,
output
,
desc
,
alpha
=
None
,
beta
=
None
):
def
make_node
(
self
,
img
,
kern
,
output
,
desc
,
alpha
=
None
,
beta
=
None
):
img
=
as_cuda_ndarray_variable
(
img
)
img
=
as_cuda_ndarray_variable
(
img
)
...
...
theano/sandbox/cuda/dnn_conv_base.c
浏览文件 @
f9b85e1e
...
@@ -3,6 +3,15 @@ cudnnTensorDescriptor_t APPLY_SPECIFIC(input);
...
@@ -3,6 +3,15 @@ cudnnTensorDescriptor_t APPLY_SPECIFIC(input);
cudnnTensorDescriptor_t
APPLY_SPECIFIC
(
output
);
cudnnTensorDescriptor_t
APPLY_SPECIFIC
(
output
);
cudnnFilterDescriptor_t
APPLY_SPECIFIC
(
kerns
);
cudnnFilterDescriptor_t
APPLY_SPECIFIC
(
kerns
);
/* Keep track, from one execution to another, of the dimension of the inputs
and the algorithm, if any, that was selected according to these dimensions
and the amount of memory available at that time.
*/
int
APPLY_SPECIFIC
(
previous_input_shape
)[
4
];
int
APPLY_SPECIFIC
(
previous_kerns_shape
)[
4
];
cudnnConvolutionFwdAlgo_t
APPLY_SPECIFIC
(
previous_algo
);
#section init_code_struct
#section init_code_struct
cudnnStatus_t
APPLY_SPECIFIC
(
err
);
cudnnStatus_t
APPLY_SPECIFIC
(
err
);
...
@@ -20,11 +29,20 @@ if ((APPLY_SPECIFIC(err) = cudnnCreateTensorDescriptor(&APPLY_SPECIFIC(output)))
...
@@ -20,11 +29,20 @@ if ((APPLY_SPECIFIC(err) = cudnnCreateTensorDescriptor(&APPLY_SPECIFIC(output)))
FAIL
;
FAIL
;
}
}
if
((
APPLY_SPECIFIC
(
err
)
=
cudnnCreateFilterDescriptor
(
&
APPLY_SPECIFIC
(
kerns
)))
!=
CUDNN_STATUS_SUCCESS
)
{
if
((
APPLY_SPECIFIC
(
err
)
=
cudnnCreateFilterDescriptor
(
&
APPLY_SPECIFIC
(
kerns
)))
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_MemoryError
,
"could not allocate filter descriptor: %s"
,
PyErr_Format
(
PyExc_MemoryError
,
"could not allocate filter descriptor: %s"
,
cudnnGetErrorString
(
APPLY_SPECIFIC
(
err
)));
cudnnGetErrorString
(
APPLY_SPECIFIC
(
err
)));
FAIL
;
FAIL
;
}
}
APPLY_SPECIFIC
(
previous_input_shape
)[
0
]
=
0
;
APPLY_SPECIFIC
(
previous_input_shape
)[
1
]
=
0
;
APPLY_SPECIFIC
(
previous_input_shape
)[
2
]
=
0
;
APPLY_SPECIFIC
(
previous_input_shape
)[
3
]
=
0
;
APPLY_SPECIFIC
(
previous_kerns_shape
)[
0
]
=
0
;
APPLY_SPECIFIC
(
previous_kerns_shape
)[
1
]
=
0
;
APPLY_SPECIFIC
(
previous_kerns_shape
)[
2
]
=
0
;
APPLY_SPECIFIC
(
previous_kerns_shape
)[
3
]
=
0
;
#section cleanup_code_struct
#section cleanup_code_struct
if
(
APPLY_SPECIFIC
(
input
)
!=
NULL
)
if
(
APPLY_SPECIFIC
(
input
)
!=
NULL
)
...
...
theano/sandbox/cuda/dnn_fwd.c
浏览文件 @
f9b85e1e
...
@@ -33,13 +33,86 @@ APPLY_SPECIFIC(conv_fwd)(CudaNdarray *input, CudaNdarray *kerns,
...
@@ -33,13 +33,86 @@ APPLY_SPECIFIC(conv_fwd)(CudaNdarray *input, CudaNdarray *kerns,
{
{
size_t
worksize
;
size_t
worksize
;
void
*
workspace
;
void
*
workspace
;
cudnnConvolutionFwdAlgo_t
chosen_algo
;
if
(
CHOOSE_ALGO
){
// Check if the input and the kernels have the same shape as they have
// last time the apply node was executed
bool
same_shapes
=
true
;
for
(
int
i
=
0
;
(
i
<
4
)
&&
same_shapes
;
i
++
)
{
same_shapes
&=
(
CudaNdarray_HOST_DIMS
(
input
)[
i
]
!=
APPLY_SPECIFIC
(
previous_input_shape
)[
i
]);
same_shapes
&=
(
CudaNdarray_HOST_DIMS
(
kerns
)[
i
]
!=
APPLY_SPECIFIC
(
previous_kerns_shape
)[
i
]);
}
if
(
same_shapes
)
{
// The shape of the inputs and/or the kernels is different from the
// last execution. Use the current shapes to infer the implementation
// to use from now on.
// 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
));
}
// Obtain a convolution algorithm appropriate for the input and kernel
// shapes
err
=
cudnnGetConvolutionForwardAlgorithm
(
_handle
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
kerns
),
desc
,
APPLY_SPECIFIC
(
output
),
CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT
,
free
,
&
chosen_algo
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"GpuDnnConv: error selecting convolution algo: %s"
,
cudnnGetErrorString
(
err
));
return
1
;
}
// Store the shapes of the inputs and kernels as well as the chosen
// algorithm for future use.
APPLY_SPECIFIC
(
previous_algo
)
=
chosen_algo
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
APPLY_SPECIFIC
(
previous_input_shape
)[
i
]
=
CudaNdarray_HOST_DIMS
(
input
)[
i
];
APPLY_SPECIFIC
(
previous_kerns_shape
)[
i
]
=
CudaNdarray_HOST_DIMS
(
kerns
)[
i
];
}
}
else
{
// The shapes of the inputs and the kernels are the same as for the
// last execution. The convolution algorithm used last time can also
// be used here
chosen_algo
=
APPLY_SPECIFIC
(
previous_algo
);
}
}
else
{
chosen_algo
=
CONV_ALGO
;
}
err
=
cudnnGetConvolutionForwardWorkspaceSize
(
_handle
,
err
=
cudnnGetConvolutionForwardWorkspaceSize
(
_handle
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
kerns
),
APPLY_SPECIFIC
(
kerns
),
desc
,
desc
,
APPLY_SPECIFIC
(
output
),
APPLY_SPECIFIC
(
output
),
CONV_ALGO
,
chosen_algo
,
&
worksize
);
&
worksize
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
PyErr_Format
(
PyExc_RuntimeError
,
...
@@ -58,7 +131,7 @@ APPLY_SPECIFIC(conv_fwd)(CudaNdarray *input, CudaNdarray *kerns,
...
@@ -58,7 +131,7 @@ APPLY_SPECIFIC(conv_fwd)(CudaNdarray *input, CudaNdarray *kerns,
APPLY_SPECIFIC
(
input
),
CudaNdarray_DEV_DATA
(
input
),
APPLY_SPECIFIC
(
input
),
CudaNdarray_DEV_DATA
(
input
),
APPLY_SPECIFIC
(
kerns
),
CudaNdarray_DEV_DATA
(
kerns
),
APPLY_SPECIFIC
(
kerns
),
CudaNdarray_DEV_DATA
(
kerns
),
desc
,
desc
,
CONV_ALGO
,
chosen_algo
,
workspace
,
worksize
,
workspace
,
worksize
,
(
void
*
)
&
beta
,
(
void
*
)
&
beta
,
APPLY_SPECIFIC
(
output
),
CudaNdarray_DEV_DATA
(
*
output
));
APPLY_SPECIFIC
(
output
),
CudaNdarray_DEV_DATA
(
*
output
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论