Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5dbfdec6
提交
5dbfdec6
authored
10月 27, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GPU conv opt refactoring to simplify the code.
Now only the legacy opt move to the GPU. Then we can apply opt in order to get the behavior we want.
上级
cabf5754
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
60 行删除
+17
-60
opt.py
theano/sandbox/cuda/opt.py
+17
-60
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
5dbfdec6
...
...
@@ -1143,7 +1143,7 @@ def _gpu_conv_to_fftconv(node):
return
rval
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
,
GpuConv
])
@local_optimizer
([
GpuConv
])
def
local_conv_fft_valid
(
node
):
if
isinstance
(
node
.
op
,
GpuConv
):
if
(
node
.
op
.
border_mode
==
'valid'
and
...
...
@@ -1152,25 +1152,8 @@ def local_conv_fft_valid(node):
return
[
_gpu_conv_to_fftconv
(
node
)]
return
False
repl
=
local_gpu_conv_legacy
.
transform
(
node
)
if
repl
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
gpu_conv
=
repl
[
0
]
.
owner
else
:
gpu_conv
=
repl
[
0
]
.
owner
.
inputs
[
0
]
.
owner
assert
isinstance
(
gpu_conv
.
op
,
GpuConv
)
if
(
gpu_conv
.
op
.
border_mode
==
'valid'
and
gpu_conv
.
op
.
subsample
==
(
1
,
1
)
and
gpu_conv
.
op
.
fft_opt
):
ret
=
_gpu_conv_to_fftconv
(
gpu_conv
)
if
ret
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
return
[
ret
]
else
:
return
[
host_from_gpu
(
ret
)]
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
,
GpuConv
])
@local_optimizer
([
GpuConv
])
def
local_conv_fft_full
(
node
):
if
isinstance
(
node
.
op
,
GpuConv
):
if
(
node
.
op
.
border_mode
==
'full'
and
...
...
@@ -1179,47 +1162,21 @@ def local_conv_fft_full(node):
return
[
_gpu_conv_to_fftconv
(
node
)]
return
repl
=
local_gpu_conv_legacy
.
transform
(
node
)
if
repl
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
gpu_conv
=
repl
[
0
]
.
owner
else
:
gpu_conv
=
repl
[
0
]
.
owner
.
inputs
[
0
]
.
owner
assert
isinstance
(
gpu_conv
.
op
,
GpuConv
)
if
(
gpu_conv
.
op
.
border_mode
==
'full'
and
gpu_conv
.
op
.
subsample
==
(
1
,
1
)
and
gpu_conv
.
op
.
fft_opt
):
ret
=
_gpu_conv_to_fftconv
(
gpu_conv
)
if
ret
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
return
[
ret
]
else
:
return
[
host_from_gpu
(
ret
)]
# Needs to be registered before local_gpu_conv_legacy. Otherwise, it
# will have priority over this optimization. We want, if cudnn is
# available and the GPU supports it, to use it. Otherwise, the gemm
# version should be used. If the users want the legacy convolution,
# they should use the Theano flag to disable the dnn and/or gemm version.
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
])
@local_optimizer
([
GpuConv
])
def
local_gpu_conv
(
node
):
"""
If cudnn is available, use it. Otherwise, use the gemm version.
"""
if
theano
.
sandbox
.
cuda
.
dnn
.
dnn_available
():
repl
=
local_gpu_conv_legacy
.
transform
(
node
)
if
repl
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
gpu_conv
=
repl
[
0
]
.
owner
else
:
gpu_conv
=
repl
[
0
]
.
owner
.
inputs
[
0
]
.
owner
assert
isinstance
(
gpu_conv
.
op
,
GpuConv
)
ret
=
theano
.
sandbox
.
cuda
.
dnn
.
local_conv_dnn
.
transform
(
gpu_conv
)
if
ret
:
if
isinstance
(
node
.
op
,
GpuFromHost
):
return
ret
else
:
return
[
host_from_gpu
(
ret
[
0
])]
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
theano
.
sandbox
.
cuda
.
dnn
.
dnn_available
()):
return
theano
.
sandbox
.
cuda
.
dnn
.
local_conv_dnn
.
transform
(
node
)
# If dnn isn't avail, the local_gpu_conv_legacy wil introduce the
# legacy opt. Then the local_conv_gemm will convert it to gemm
# opt.
...
...
@@ -1382,20 +1339,20 @@ def local_conv_gemm(node):
gpu_contiguous
(
kern
),
gpu_contiguous
(
img
))]
# fft optimization not enabled by default. Need to be registered
# before the default convolution optimization. If the user ask fft, as
# this isn't the default, it should have higher prio then the default.
# Legacy opt first, as this is the only that move to the GPU.
# Then fft, as disabled dy default. So if use enable it, it have prio
# Then default, use dnn if avail
# Then default, use gemm if dnn or fft didn't worked.
# Normally, gemm should catch all case, so the legacy should never run.
conv_groupopt
.
register
(
'local_gpu_conv_legacy'
,
local_gpu_conv_legacy
,
0
,
'fast_compile'
,
'fast_run'
)
conv_groupopt
.
register
(
"conv_fft_valid"
,
local_conv_fft_valid
,
1
)
conv_groupopt
.
register
(
"conv_fft_full"
,
local_conv_fft_full
,
1
)
#
default gpu conv optimization
#
Use dnn if avail, so have the dnn tag to be able to disable it.
conv_groupopt
.
register
(
'local_gpu_conv'
,
local_gpu_conv
,
10
,
'fast_compile'
,
'fast_run'
,
"dnn"
)
# Legacy convolution, after default
conv_groupopt
.
register
(
'local_gpu_conv_legacy'
,
local_gpu_conv_legacy
,
11
,
'fast_compile'
,
'fast_run'
,
"dnn"
)
# conv gemm after legacy, as it convert legacy to gemm version
'fast_compile'
,
'fast_run'
,
'dnn'
)
conv_groupopt
.
register
(
'local_conv_gemm'
,
local_conv_gemm
,
12
,
'fast_compile'
,
'fast_run'
,
"dnn"
)
'fast_compile'
,
'fast_run'
)
@local_optimizer
([
Conv3D
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论