Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1ccf7243
提交
1ccf7243
authored
11月 23, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
7b362c83
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
45 行删除
+47
-45
dnn.py
theano/sandbox/cuda/dnn.py
+2
-5
extra_ops.py
theano/sandbox/cuda/extra_ops.py
+1
-1
opt.py
theano/sandbox/cuda/opt.py
+44
-39
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
1ccf7243
...
@@ -13,7 +13,6 @@ from theano.compile.ops import shape_i
...
@@ -13,7 +13,6 @@ from theano.compile.ops import shape_i
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.signal.downsample
import
(
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePoolGrad
)
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePoolGrad
)
from
theano.tensor.opt
import
register_specialize_device
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda
import
GpuOp
from
theano.sandbox.cuda
import
GpuOp
...
@@ -33,8 +32,6 @@ from theano.sandbox.cuda.nvcc_compiler import NVCC_compiler
...
@@ -33,8 +32,6 @@ from theano.sandbox.cuda.nvcc_compiler import NVCC_compiler
from
theano.tensor.nnet.abstract_conv2d
import
(
AbstractConv2d
,
from
theano.tensor.nnet.abstract_conv2d
import
(
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
from
theano.tensor.opt
import
register_specialize_device
def
dnn_available
():
def
dnn_available
():
...
@@ -2453,8 +2450,8 @@ def local_abstractconv_cudnn(node):
...
@@ -2453,8 +2450,8 @@ def local_abstractconv_cudnn(node):
AbstractConv2d_gradInputs
))):
AbstractConv2d_gradInputs
))):
return
None
return
None
if
not
isinstance
(
inp1
.
type
,
CudaNdarrayType
)
or
\
if
(
not
isinstance
(
inp1
.
type
,
CudaNdarrayType
)
or
not
isinstance
(
inp2
.
type
,
CudaNdarrayType
):
not
isinstance
(
inp2
.
type
,
CudaNdarrayType
)
)
:
return
None
return
None
if
not
dnn_available
():
if
not
dnn_available
():
return
None
return
None
...
...
theano/sandbox/cuda/extra_ops.py
浏览文件 @
1ccf7243
...
@@ -9,7 +9,7 @@ from theano.tensor.extra_ops import CumsumOp
...
@@ -9,7 +9,7 @@ from theano.tensor.extra_ops import CumsumOp
if
cuda_available
:
if
cuda_available
:
from
theano.sandbox.cuda
import
CudaNdarrayType
from
theano.sandbox.cuda
import
CudaNdarrayType
from
theano.sandbox.cuda.basic_ops
import
host_from_gpu
,
gpu_from_host
,
HostFromGpu
from
theano.sandbox.cuda.basic_ops
import
host_from_gpu
,
gpu_from_host
,
HostFromGpu
from
theano.sandbox.cuda
.opt
import
register_opt
as
register_gpu_opt
from
theano.sandbox.cuda
import
register_opt
as
register_gpu_opt
class
GpuCumsum
(
CumsumOp
,
GpuOp
):
class
GpuCumsum
(
CumsumOp
,
GpuOp
):
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
1ccf7243
from
__future__
import
print_function
from
__future__
import
print_function
import
logging
_logger
=
logging
.
getLogger
(
'theano.sandbox.cuda.opt'
)
import
copy
import
copy
import
logging
import
pdb
import
sys
import
sys
import
time
import
time
import
warnings
import
warnings
import
pdb
import
numpy
import
numpy
from
six.moves
import
reduce
,
xrange
import
theano
import
theano
from
theano
import
scalar
as
scal
from
theano
import
scalar
as
scal
from
theano
import
config
,
tensor
,
gof
from
theano
import
config
,
tensor
,
gof
import
theano.ifelse
import
theano.ifelse
from
six.moves
import
reduce
,
xrange
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano.gof
import
(
local_optimizer
,
EquilibriumDB
,
ProxyDB
,
from
theano.gof
import
(
local_optimizer
,
EquilibriumDB
,
ProxyDB
,
Optimizer
,
TopoOptimizer
,
toolbox
)
Optimizer
,
TopoOptimizer
,
toolbox
)
...
@@ -66,6 +65,7 @@ from theano.sandbox.cuda.elemwise import erfinv_gpu
...
@@ -66,6 +65,7 @@ from theano.sandbox.cuda.elemwise import erfinv_gpu
from
theano.sandbox.cuda.elemwise
import
erfcx_gpu
from
theano.sandbox.cuda.elemwise
import
erfcx_gpu
from
theano.sandbox.cuda.var
import
CudaNdarrayConstant
from
theano.sandbox.cuda.var
import
CudaNdarrayConstant
from
theano.sandbox.cuda
import
gpu_optimizer
,
register_opt
,
gpu_seqopt
,
GpuOp
from
theano.sandbox.cuda
import
gpu_optimizer
,
register_opt
,
gpu_seqopt
,
GpuOp
import
theano.sandbox.cuda.extra_ops
from
theano.scan_module
import
scan_utils
,
scan_op
,
scan_opt
from
theano.scan_module
import
scan_utils
,
scan_op
,
scan_opt
from
theano.tensor.blas
import
_is_real_vector
,
_is_real_matrix
from
theano.tensor.blas
import
_is_real_vector
,
_is_real_matrix
...
@@ -75,7 +75,8 @@ from theano.tensor import slinalg
...
@@ -75,7 +75,8 @@ from theano.tensor import slinalg
from
theano.tensor.nnet.Conv3D
import
Conv3D
from
theano.tensor.nnet.Conv3D
import
Conv3D
from
theano.tests.breakpoint
import
PdbBreakpoint
from
theano.tests.breakpoint
import
PdbBreakpoint
from
theano.tensor.nnet.abstract_conv2d
import
(
BaseAbstractConv2d
,
AbstractConv2d
,
from
theano.tensor.nnet.abstract_conv2d
import
(
BaseAbstractConv2d
,
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
from
theano.tensor.opt
import
register_specialize_device
from
theano.tensor.opt
import
register_specialize_device
...
@@ -88,6 +89,8 @@ except ImportError:
...
@@ -88,6 +89,8 @@ except ImportError:
pass
pass
_logger
=
logging
.
getLogger
(
'theano.sandbox.cuda.opt'
)
# optdb.print_summary() # shows what is currently registered
# optdb.print_summary() # shows what is currently registered
gpu_cut_copies
=
EquilibriumDB
()
gpu_cut_copies
=
EquilibriumDB
()
...
@@ -261,7 +264,7 @@ def local_gpu_elemwise_0(node):
...
@@ -261,7 +264,7 @@ def local_gpu_elemwise_0(node):
"""
"""
if
(
isinstance
(
node
.
op
,
tensor
.
Elemwise
)
and
if
(
isinstance
(
node
.
op
,
tensor
.
Elemwise
)
and
dtype_in_elemwise_supported
(
node
.
op
)):
dtype_in_elemwise_supported
(
node
.
op
)):
if
any
([
i
.
owner
and
if
any
([
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
HostFromGpu
)
isinstance
(
i
.
owner
.
op
,
HostFromGpu
)
for
i
in
node
.
inputs
]):
for
i
in
node
.
inputs
]):
...
@@ -327,9 +330,9 @@ def local_gpu_elemwise_1(node):
...
@@ -327,9 +330,9 @@ def local_gpu_elemwise_1(node):
if
isinstance
(
node
.
op
,
GpuFromHost
):
if
isinstance
(
node
.
op
,
GpuFromHost
):
host_i
,
=
node
.
inputs
host_i
,
=
node
.
inputs
if
(
host_i
.
owner
and
if
(
host_i
.
owner
and
isinstance
(
host_i
.
owner
.
op
,
tensor
.
Elemwise
)
and
isinstance
(
host_i
.
owner
.
op
,
tensor
.
Elemwise
)
and
len
(
host_i
.
clients
)
==
1
and
len
(
host_i
.
clients
)
==
1
and
dtype_in_elemwise_supported
(
node
.
op
)):
dtype_in_elemwise_supported
(
node
.
op
)):
elemwise_node
=
host_i
.
owner
elemwise_node
=
host_i
.
owner
# Don't set any inplace pattern.
# Don't set any inplace pattern.
...
@@ -555,13 +558,13 @@ def local_gpu_lazy_ifelse(node):
...
@@ -555,13 +558,13 @@ def local_gpu_lazy_ifelse(node):
if
isinstance
(
node
.
op
,
GpuFromHost
):
if
isinstance
(
node
.
op
,
GpuFromHost
):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
(
host_input
.
owner
and
if
(
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
theano
.
ifelse
.
IfElse
)
and
isinstance
(
host_input
.
owner
.
op
,
theano
.
ifelse
.
IfElse
)
and
not
host_input
.
owner
.
op
.
gpu
and
not
host_input
.
owner
.
op
.
gpu
and
# If there is more then 1 outputs, we can't replace it
# If there is more then 1 outputs, we can't replace it
# here with a local optimizer as we replace the
# here with a local optimizer as we replace the
# GpuFromHost node and the other output of the if won't be
# GpuFromHost node and the other output of the if won't be
# replaced.
# replaced.
host_input
.
owner
.
op
.
n_outs
==
1
):
host_input
.
owner
.
op
.
n_outs
==
1
):
gpu_ifelse
=
theano
.
ifelse
.
IfElse
(
host_input
.
owner
.
op
.
n_outs
,
gpu_ifelse
=
theano
.
ifelse
.
IfElse
(
host_input
.
owner
.
op
.
n_outs
,
gpu
=
True
)
gpu
=
True
)
...
@@ -1037,7 +1040,7 @@ def local_gpu_advanced_subtensor1(node):
...
@@ -1037,7 +1040,7 @@ def local_gpu_advanced_subtensor1(node):
x
=
node
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
coords
=
node
.
inputs
[
1
:]
coords
=
node
.
inputs
[
1
:]
if
(
x
.
owner
and
isinstance
(
x
.
owner
.
op
,
HostFromGpu
)
and
if
(
x
.
owner
and
isinstance
(
x
.
owner
.
op
,
HostFromGpu
)
and
x
.
dtype
==
"float32"
):
x
.
dtype
==
"float32"
):
gpu_x
,
=
x
.
owner
.
inputs
gpu_x
,
=
x
.
owner
.
inputs
return
[
host_from_gpu
(
GpuAdvancedSubtensor1
()(
gpu_x
,
*
coords
))]
return
[
host_from_gpu
(
GpuAdvancedSubtensor1
()(
gpu_x
,
*
coords
))]
return
False
return
False
...
@@ -2605,10 +2608,10 @@ def local_inplace_gpu_sparse_block_gemv(node):
...
@@ -2605,10 +2608,10 @@ def local_inplace_gpu_sparse_block_gemv(node):
return
[
new_node
]
return
[
new_node
]
return
False
return
False
optdb
.
register
(
'local_inplace_gpu_sparse_block_gemv'
,
optdb
.
register
(
'local_inplace_gpu_sparse_block_gemv'
,
TopoOptimizer
(
TopoOptimizer
(
local_inplace_gpu_sparse_block_gemv
,
local_inplace_gpu_sparse_block_gemv
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
,
'gpu'
)
# DEBUG
60
,
'fast_run'
,
'inplace'
,
'gpu'
)
# DEBUG
@local_optimizer
([
GpuSparseBlockOuter
],
inplace
=
True
)
@local_optimizer
([
GpuSparseBlockOuter
],
inplace
=
True
)
...
@@ -2621,17 +2624,17 @@ def local_inplace_gpu_sparse_block_outer(node):
...
@@ -2621,17 +2624,17 @@ def local_inplace_gpu_sparse_block_outer(node):
return
[
new_node
]
return
[
new_node
]
return
False
return
False
optdb
.
register
(
'local_inplace_gpu_sparse_block_outer'
,
optdb
.
register
(
'local_inplace_gpu_sparse_block_outer'
,
TopoOptimizer
(
TopoOptimizer
(
local_inplace_gpu_sparse_block_outer
,
local_inplace_gpu_sparse_block_outer
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
,
'gpu'
)
# DEBUG
60
,
'fast_run'
,
'inplace'
,
'gpu'
)
# DEBUG
import
theano.sandbox.cuda.extra_ops
# Move to Gpu optimization
### Move to Gpu optimization
@local_optimizer
([
gpu_from_host
,
@local_optimizer
([
gpu_from_host
,
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
])
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
])
def
local_conv2d_gpu_conv
(
node
):
def
local_conv2d_gpu_conv
(
node
):
"""
"""
gpu_from_host(AbstractConv) -> AbstractConv(gpu_from_host)
gpu_from_host(AbstractConv) -> AbstractConv(gpu_from_host)
...
@@ -2640,7 +2643,8 @@ def local_conv2d_gpu_conv(node):
...
@@ -2640,7 +2643,8 @@ def local_conv2d_gpu_conv(node):
"""
"""
if
isinstance
(
node
.
op
,
GpuFromHost
):
if
isinstance
(
node
.
op
,
GpuFromHost
):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
BaseAbstractConv2d
):
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
BaseAbstractConv2d
):
conv
=
host_input
.
owner
.
op
conv
=
host_input
.
owner
.
op
inps
=
list
(
host_input
.
owner
.
inputs
)
inps
=
list
(
host_input
.
owner
.
inputs
)
...
@@ -2686,8 +2690,7 @@ def local_conv2d_gpu_conv(node):
...
@@ -2686,8 +2690,7 @@ def local_conv2d_gpu_conv(node):
register_opt
()(
local_conv2d_gpu_conv
)
register_opt
()(
local_conv2d_gpu_conv
)
# Corrmm opt
### Corrmm opt
@local_optimizer
([
AbstractConv2d
])
@local_optimizer
([
AbstractConv2d
])
def
local_abstractconv_gemm
(
node
):
def
local_abstractconv_gemm
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d
):
...
@@ -2720,11 +2723,11 @@ def local_abstractconv_gemm(node):
...
@@ -2720,11 +2723,11 @@ def local_abstractconv_gemm(node):
# is larger than inputChannels * outputHeight * outputWidth.
# is larger than inputChannels * outputHeight * outputWidth.
# GpuConv does not always store information on the batchsize and
# GpuConv does not always store information on the batchsize and
# channels, though, so we only use what information we have.)
# channels, though, so we only use what information we have.)
if
((
subsample
==
(
1
,
1
))
and
if
((
subsample
==
(
1
,
1
))
and
(
node
.
op
.
imshp
is
not
None
)
and
(
node
.
op
.
imshp
is
not
None
)
and
(
None
not
in
node
.
op
.
imshp
[
-
2
:])
and
(
None
not
in
node
.
op
.
imshp
[
-
2
:])
and
(
node
.
op
.
kshp
is
not
None
)
and
(
node
.
op
.
kshp
is
not
None
)
and
(
None
not
in
node
.
op
.
kshp
)):
(
None
not
in
node
.
op
.
kshp
)):
# we know the kernel and output size
# we know the kernel and output size
prod1
=
node
.
op
.
kshp
[
0
]
*
node
.
op
.
kshp
[
1
]
prod1
=
node
.
op
.
kshp
[
0
]
*
node
.
op
.
kshp
[
1
]
prod2
=
((
node
.
op
.
imshp
[
-
2
]
-
node
.
op
.
kshp
[
0
]
+
1
)
*
prod2
=
((
node
.
op
.
imshp
[
-
2
]
-
node
.
op
.
kshp
[
0
]
+
1
)
*
...
@@ -2745,6 +2748,7 @@ def local_abstractconv_gemm(node):
...
@@ -2745,6 +2748,7 @@ def local_abstractconv_gemm(node):
)
.
dimshuffle
(
1
,
0
,
2
,
3
))
)
.
dimshuffle
(
1
,
0
,
2
,
3
))
return
[
rval
]
return
[
rval
]
@local_optimizer
([
AbstractConv2d_gradWeights
])
@local_optimizer
([
AbstractConv2d_gradWeights
])
def
local_abstractconv_gradweight_gemm
(
node
):
def
local_abstractconv_gradweight_gemm
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
...
@@ -2763,6 +2767,7 @@ def local_abstractconv_gradweight_gemm(node):
...
@@ -2763,6 +2767,7 @@ def local_abstractconv_gradweight_gemm(node):
rval
=
as_cuda_ndarray_variable
(
rval
)
rval
=
as_cuda_ndarray_variable
(
rval
)
return
[
rval
]
return
[
rval
]
@local_optimizer
([
AbstractConv2d_gradInputs
])
@local_optimizer
([
AbstractConv2d_gradInputs
])
def
local_abstractconv_gradinputs_gemm
(
node
):
def
local_abstractconv_gradinputs_gemm
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
...
@@ -2775,8 +2780,8 @@ def local_abstractconv_gradinputs_gemm(node):
...
@@ -2775,8 +2780,8 @@ def local_abstractconv_gradinputs_gemm(node):
if
node
.
op
.
filter_flip
:
if
node
.
op
.
filter_flip
:
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
]
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
]
rval
=
GpuCorrMM_gradInputs
(
border_mode
=
node
.
op
.
border_mode
,
rval
=
GpuCorrMM_gradInputs
(
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
)(
subsample
=
node
.
op
.
subsample
)(
gpu_contiguous
(
kern
),
gpu_contiguous
(
topgrad
),
shape
)
gpu_contiguous
(
kern
),
gpu_contiguous
(
topgrad
),
shape
)
return
[
rval
]
return
[
rval
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论