Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9fe28989
提交
9fe28989
authored
8月 18, 2014
作者:
Nicolas Ballas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add an option to desactivate conv2d_fft at the op level
上级
93be9cb8
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
66 行增加
和
5 行删除
+66
-5
blas.py
theano/sandbox/cuda/blas.py
+5
-1
opt.py
theano/sandbox/cuda/opt.py
+5
-2
test_fftconv.py
theano/sandbox/cuda/tests/test_fftconv.py
+46
-0
conv.py
theano/tensor/nnet/conv.py
+10
-2
没有找到文件。
theano/sandbox/cuda/blas.py
浏览文件 @
9fe28989
...
@@ -687,7 +687,8 @@ class GpuConv(GpuOp):
...
@@ -687,7 +687,8 @@ class GpuConv(GpuOp):
verbose
=
0
,
verbose
=
0
,
kshp
=
None
,
kshp
=
None
,
imshp
=
None
,
imshp
=
None
,
max_threads_dim0
=
None
):
max_threads_dim0
=
None
,
fft_opt
=
True
):
"""
"""
:param version: each version of c_code implements many kernel for the
:param version: each version of c_code implements many kernel for the
convolution. By default we try to guess the best one.
convolution. By default we try to guess the best one.
...
@@ -706,6 +707,8 @@ class GpuConv(GpuOp):
...
@@ -706,6 +707,8 @@ class GpuConv(GpuOp):
:param max_threads_dim0: The maximum number of threads for the
:param max_threads_dim0: The maximum number of threads for the
block size dimensions 0 (blockDim.x) used by the
block size dimensions 0 (blockDim.x) used by the
GPU function.
GPU function.
:param fft_opt: desactivate fft_opt optimization at the op level when
set to False.
"""
"""
self
.
border_mode
=
border_mode
self
.
border_mode
=
border_mode
...
@@ -730,6 +733,7 @@ class GpuConv(GpuOp):
...
@@ -730,6 +733,7 @@ class GpuConv(GpuOp):
self
.
kshp
=
kshp
self
.
kshp
=
kshp
self
.
imshp
=
imshp
self
.
imshp
=
imshp
self
.
max_threads_dim0
=
max_threads_dim0
self
.
max_threads_dim0
=
max_threads_dim0
self
.
fft_opt
=
fft_opt
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
\
return
type
(
self
)
==
type
(
other
)
\
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
9fe28989
...
@@ -1143,6 +1143,7 @@ def local_gpu_conv(node):
...
@@ -1143,6 +1143,7 @@ def local_gpu_conv(node):
version
=
op
.
version
,
version
=
op
.
version
,
verbose
=
op
.
verbose
,
verbose
=
op
.
verbose
,
imshp
=
op
.
imshp
,
imshp
=
op
.
imshp
,
fft_opt
=
op
.
fft_opt
)
)
if
op
.
imshp_logical
is
not
None
:
if
op
.
imshp_logical
is
not
None
:
logical_img_hw
=
op
.
imshp_logical
[
1
:
3
]
logical_img_hw
=
op
.
imshp_logical
[
1
:
3
]
...
@@ -1242,7 +1243,8 @@ def _gpu_conv_to_fftconv(node):
...
@@ -1242,7 +1243,8 @@ def _gpu_conv_to_fftconv(node):
def
local_conv_fft_valid
(
node
):
def
local_conv_fft_valid
(
node
):
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
node
.
op
.
border_mode
==
'valid'
and
node
.
op
.
border_mode
==
'valid'
and
node
.
op
.
subsample
==
(
1
,
1
)):
node
.
op
.
subsample
==
(
1
,
1
)
and
node
.
op
.
fft_opt
):
return
[
_gpu_conv_to_fftconv
(
node
)]
return
[
_gpu_conv_to_fftconv
(
node
)]
...
@@ -1250,7 +1252,8 @@ def local_conv_fft_valid(node):
...
@@ -1250,7 +1252,8 @@ def local_conv_fft_valid(node):
def
local_conv_fft_full
(
node
):
def
local_conv_fft_full
(
node
):
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
node
.
op
.
border_mode
==
'full'
and
node
.
op
.
border_mode
==
'full'
and
node
.
op
.
subsample
==
(
1
,
1
)):
node
.
op
.
subsample
==
(
1
,
1
)
and
node
.
op
.
fft_opt
):
return
[
_gpu_conv_to_fftconv
(
node
)]
return
[
_gpu_conv_to_fftconv
(
node
)]
gpu_optimizer
.
register
(
"conv_fft_valid"
,
local_conv_fft_valid
)
gpu_optimizer
.
register
(
"conv_fft_valid"
,
local_conv_fft_valid
)
...
...
theano/sandbox/cuda/tests/test_fftconv.py
浏览文件 @
9fe28989
...
@@ -119,6 +119,52 @@ class TestConv2dFFT(unittest.TestCase):
...
@@ -119,6 +119,52 @@ class TestConv2dFFT(unittest.TestCase):
utt
.
assert_allclose
(
res_ref
,
res_fft
)
utt
.
assert_allclose
(
res_ref
,
res_fft
)
def
test_opt_nofft_valid
(
self
):
inputs_shape
=
(
5
,
3
,
7
,
6
)
filters_shape
=
(
2
,
3
,
3
,
3
)
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
conv
=
theano
.
tensor
.
nnet
.
conv
.
conv2d
(
inputs
,
filters
,
version
=
'no_fft'
)
mode
=
mode_with_gpu
.
including
(
'conv_fft_valid'
)
f_ref
=
theano
.
function
([],
conv
)
f_fft
=
theano
.
function
([],
conv
,
mode
=
mode
)
# make sure we inserted the fft trickery
topo
=
f_fft
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
n
.
op
,
theano
.
sandbox
.
cuda
.
fftconv
.
CuFFTOp
)
for
n
in
topo
)
==
0
def
test_opt_nofft_full
(
self
):
inputs_shape
=
(
5
,
3
,
7
,
6
)
filters_shape
=
(
2
,
3
,
3
,
3
)
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
conv
=
theano
.
tensor
.
nnet
.
conv
.
conv2d
(
inputs
,
filters
,
border_mode
=
'full'
,
version
=
'no_fft'
)
mode
=
mode_with_gpu
.
including
(
'conv_fft_full'
)
f_ref
=
theano
.
function
([],
conv
)
f_fft
=
theano
.
function
([],
conv
,
mode
=
mode
)
# make sure we that no CuFFTOp has been inserted
topo
=
f_fft
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
n
.
op
,
theano
.
sandbox
.
cuda
.
fftconv
.
CuFFTOp
)
for
n
in
topo
)
==
0
class
TestConv3dFFT
(
unittest
.
TestCase
):
class
TestConv3dFFT
(
unittest
.
TestCase
):
...
...
theano/tensor/nnet/conv.py
浏览文件 @
9fe28989
...
@@ -348,8 +348,9 @@ class ConvOp(OpenMPOp):
...
@@ -348,8 +348,9 @@ class ConvOp(OpenMPOp):
:type verbose: int
:type verbose: int
:param verbose: passed to GpuConv
:param verbose: passed to GpuConv
:type version: int
:type version: int or str
:param version: passed to GpuConv
:param version: passed to GpuConv, if version='no_fft', fft
optimization will be desactivated the at the op level.
The 3 following parameters are used internally when we generate
The 3 following parameters are used internally when we generate
the gradient when dx!=1 or dy!=1.
the gradient when dx!=1 or dy!=1.
...
@@ -367,6 +368,13 @@ class ConvOp(OpenMPOp):
...
@@ -367,6 +368,13 @@ class ConvOp(OpenMPOp):
Set to False in the grad again the weight when the
Set to False in the grad again the weight when the
output_mode is full.
output_mode is full.
"""
"""
# Desactivate fft_optimization at the op level if specified
if
version
==
"no_fft"
:
self
.
fft_opt
=
False
version
=
-
1
else
:
self
.
fft_opt
=
True
# We must continue to consider None as 1 for backward compatibility.
# We must continue to consider None as 1 for backward compatibility.
if
dx
is
None
:
if
dx
is
None
:
dx
=
1
dx
=
1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论