Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e76d6bc9
提交
e76d6bc9
authored
8月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/sandbox/cuda/dnn.py
上级
0a7415d7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
145 行增加
和
78 行删除
+145
-78
dnn.py
theano/sandbox/cuda/dnn.py
+145
-78
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
e76d6bc9
...
@@ -140,7 +140,9 @@ if (%(err)s != CUDNN_STATUS_SUCCESS) {
...
@@ -140,7 +140,9 @@ if (%(err)s != CUDNN_STATUS_SUCCESS) {
class
DnnBase
(
GpuOp
,
COp
):
class
DnnBase
(
GpuOp
,
COp
):
"""
"""
Creates a handle for cudnn and pulls in the cudnn libraries and headers.
Creates a handle for cudnn and pulls in the cudnn libraries and headers.
"""
"""
# dnn does not know about broadcasting, so we do not need to assert
# dnn does not know about broadcasting, so we do not need to assert
# the input broadcasting pattern.
# the input broadcasting pattern.
check_broadcast
=
False
check_broadcast
=
False
...
@@ -198,9 +200,9 @@ class DnnVersion(GpuOp):
...
@@ -198,9 +200,9 @@ class DnnVersion(GpuOp):
def
version
():
def
version
():
"""
r
eturn the current cuDNN version we compile with.
"""
R
eturn the current cuDNN version we compile with.
This return a tuple with the header version and the library
This return
s
a tuple with the header version and the library
version we link with. For older cudnn version without version
version we link with. For older cudnn version without version
information, we return -1.
information, we return -1.
...
@@ -220,12 +222,14 @@ version.v = None
...
@@ -220,12 +222,14 @@ version.v = None
class
GpuDnnConvDesc
(
GpuOp
):
class
GpuDnnConvDesc
(
GpuOp
):
"""This Op builds a convolution descriptor for use in the other
"""
This Op builds a convolution descriptor for use in the other
convolution operations.
convolution operations.
see the doc of :func:`dnn_conv` for a description of the parameters
See the doc of :func:`dnn_conv` for a description of the parameters.
"""
"""
__props__
=
(
'border_mode'
,
'subsample'
,
'conv_mode'
)
__props__
=
(
'border_mode'
,
'subsample'
,
'conv_mode'
)
def
c_headers
(
self
):
def
c_headers
(
self
):
...
@@ -412,21 +416,24 @@ class GpuDnnConv(DnnBase, COp):
...
@@ -412,21 +416,24 @@ class GpuDnnConv(DnnBase, COp):
"""
"""
The forward convolution.
The forward convolution.
:param image:
Parameters
:param kernel:
----------
:param descr: the convolution descriptor
image
kernel
descr
The convolution descriptor.
workmem
*deprecated*, use parameter algo instead.
algo : {'small', 'none', 'large', 'fft', 'guess_once', 'guess_on_shape_change', 'time_once', 'time_on_shape_change'}
Default is the value of :attr:`config.dnn.conv.algo_fwd`.
"""
"""
__props__
=
(
'algo'
,
'inplace'
)
__props__
=
(
'algo'
,
'inplace'
)
__input_name__
=
(
'image'
,
'kernel'
,
'output'
,
__input_name__
=
(
'image'
,
'kernel'
,
'output'
,
'descriptor'
,
'alpha'
,
'beta'
)
'descriptor'
,
'alpha'
,
'beta'
)
def
__init__
(
self
,
workmem
=
None
,
inplace
=
False
,
algo
=
None
):
def
__init__
(
self
,
workmem
=
None
,
inplace
=
False
,
algo
=
None
):
"""
:param workmem: *deprecated*, use param algo instead
:param algo: either 'small', 'none', 'large', 'fft', 'guess_once',
'guess_on_shape_change', 'time_once' or 'time_on_shape_change'.
Default is the value of :attr:`config.dnn.conv.algo_fwd`.
"""
COp
.
__init__
(
self
,
[
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_fwd.c"
],
COp
.
__init__
(
self
,
[
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_fwd.c"
],
"APPLY_SPECIFIC(conv_fwd)"
)
"APPLY_SPECIFIC(conv_fwd)"
)
...
@@ -561,8 +568,9 @@ class GpuDnnConv(DnnBase, COp):
...
@@ -561,8 +568,9 @@ class GpuDnnConv(DnnBase, COp):
def
get_out_shape
(
ishape
,
kshape
,
border_mode
,
subsample
):
def
get_out_shape
(
ishape
,
kshape
,
border_mode
,
subsample
):
"""
"""
This function computes the output shape for a convolution with
This function computes the output shape for a convolution with
the specified parameters.
`ishape` and `kshape` can be symbolic
the specified parameters. `ishape` and `kshape` can be symbolic
or scalar.
or scalar.
"""
"""
b
=
ishape
[
0
]
# Number of inputs
b
=
ishape
[
0
]
# Number of inputs
h
=
ishape
[
2
]
# Height of input feature maps
h
=
ishape
[
2
]
# Height of input feature maps
...
@@ -698,11 +706,15 @@ class GpuDnnConvGradW(DnnBase, COp):
...
@@ -698,11 +706,15 @@ class GpuDnnConvGradW(DnnBase, COp):
"""
"""
The convolution gradient with respect to the weights.
The convolution gradient with respect to the weights.
:param image:
Parameters
:param kernel:
----------
:param descr: the convolution descriptor
image
kernel
descr
The convolution descriptor.
"""
"""
__props__
=
(
'algo'
,
'inplace'
,)
__props__
=
(
'algo'
,
'inplace'
,)
__input_name__
=
(
'image'
,
'grad'
,
'output'
,
'descriptor'
,
'alpha'
,
'beta'
)
__input_name__
=
(
'image'
,
'grad'
,
'output'
,
'descriptor'
,
'alpha'
,
'beta'
)
...
@@ -901,22 +913,24 @@ class GpuDnnConvGradI(DnnBase, COp):
...
@@ -901,22 +913,24 @@ class GpuDnnConvGradI(DnnBase, COp):
"""
"""
The convolution gradient with respect to the inputs.
The convolution gradient with respect to the inputs.
:param image:
Parameters
:param kernel:
----------
:param descr: the convolution descriptor
image
kernel
descr
The convolution descriptor.
workmem
*deprecated*, use parameter algo instead.
algo : {'none', 'deterministic', 'fft', 'guess_once', 'guess_on_shape_change', 'time_once', 'time_on_shape_change'}
Default is the value of :attr:`config.dnn.conv.algo_bwd`.
"""
"""
__props__
=
(
'algo'
,
'inplace'
,)
__props__
=
(
'algo'
,
'inplace'
,)
__input_name__
=
(
'kernel'
,
'grad'
,
'output'
,
'descriptor'
,
'alpha'
,
__input_name__
=
(
'kernel'
,
'grad'
,
'output'
,
'descriptor'
,
'alpha'
,
'beta'
)
'beta'
)
def
__init__
(
self
,
inplace
=
False
,
workmem
=
None
,
algo
=
None
):
def
__init__
(
self
,
inplace
=
False
,
workmem
=
None
,
algo
=
None
):
"""
:param workmem: *deprecated*, use param algo instead
: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_gi.c"
],
COp
.
__init__
(
self
,
[
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_gi.c"
],
"APPLY_SPECIFIC(conv_gi)"
)
"APPLY_SPECIFIC(conv_gi)"
)
...
@@ -1107,17 +1121,25 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1107,17 +1121,25 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
"""
"""
GPU convolution using cuDNN from NVIDIA.
GPU convolution using cuDNN from NVIDIA.
The memory layout to use is 'bc01', that is 'batch', 'channel',
The memory layout to use is 'bc01', that is 'batch', 'channel', 'first dim',
'first dim', 'second dim' in that order.
'second dim' in that order.
:param img: images to do the convolution over
Parameters
:param kerns: convolution filters
----------
:param border_mode: one of 'valid', 'full'; additionally, the padding size
img
could be directly specified by an integer or a pair of integers
Images to do the convolution over.
:param subsample: perform subsampling of the output (default: (1, 1))
kerns
:param conv_mode: perform convolution (kernels flipped) or cross-correlation.
Convolution filters.
One of 'conv', 'cross'. (default: 'conv')
border_mode
:param direction_hint: Used by graph optimizers to change algorithm choice.
One of 'valid', 'full'; additionally, the padding size could be directly
specified by an integer or a pair of integers.
subsample
Perform subsampling of the output (default: (1, 1)).
conv_mode
Perform convolution (kernels flipped) or cross-correlation.
One of 'conv', 'cross' (default: 'conv').
direction_hint
Used by graph optimizers to change algorithm choice.
By default, GpuDnnConv will be used to carry out the convolution.
By default, GpuDnnConv will be used to carry out the convolution.
If border_mode is 'valid', subsample is (1,1) and direction_hint is
If border_mode is 'valid', subsample is (1,1) and direction_hint is
'bprop weights', it will use GpuDnnConvGradW.
'bprop weights', it will use GpuDnnConvGradW.
...
@@ -1125,16 +1147,13 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1125,16 +1147,13 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
'bprop inputs', it will use GpuDnnConvGradI.
'bprop inputs', it will use GpuDnnConvGradI.
This parameter is used internally by graph optimizers and may be
This parameter is used internally by graph optimizers and may be
removed at any time without a deprecation period. You have been warned.
removed at any time without a deprecation period. You have been warned.
:param workmem: *deprecated*, use param algo instead
workmem
:param algo: convolution implementation to use. One of 'none', 'small',
*deprecated*, use parameter algo instead.
'large', 'fft', 'guess_once', 'guess_on_shape_change', 'time_once' or
algo : {'none', 'small', 'large', 'fft', 'guess_once', 'guess_on_shape_change', 'time_once', 'time_on_shape_change'}
'time_on_shape_change'. Some of these
values may require certain
Convolution implementation to use. Some of its
values may require certain
versions of CuDNN to be installed. Default is the value of
versions of CuDNN to be installed. Default is the value of
:attr:`config.dnn.conv.algo_fwd.
:attr:`config.dnn.conv.algo_fwd.
:warning: The cuDNN library only works with GPU that have a compute
capability of 3.0 or higer. This means that older GPU will not
work with this Op.
"""
"""
# Check if deprecated param 'workmem' is used
# Check if deprecated param 'workmem' is used
...
@@ -1279,17 +1298,23 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1279,17 +1298,23 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
class
GpuDnnPoolDesc
(
GpuOp
):
class
GpuDnnPoolDesc
(
GpuOp
):
"""
"""
This Op builds a pooling descriptor for use in the other
This Op builds a pooling descriptor for use in the other pooling operations.
pooling operations.
Parameters
:param ws: windows size
----------
:param stride: (dx, dy)
ws
:param mode: 'max', 'average_inc_pad' or 'average_exc_pad'
Windows size.
The old deprecated name 'average' correspond to 'average_inc_pad'
stride
:param pad: (padX, padY) padding information.
(dx, dy).
mode : {'max', 'average_inc_pad', 'average_exc_pad'}
The old deprecated name 'average' correspond to 'average_inc_pad'.
pad
(padX, padY) padding information.
padX is the size of the left and right borders,
padX is the size of the left and right borders,
padY is the size of the top and bottom borders.
padY is the size of the top and bottom borders.
"""
"""
__props__
=
(
'ws'
,
'stride'
,
'mode'
,
'pad'
)
__props__
=
(
'ws'
,
'stride'
,
'mode'
,
'pad'
)
def
c_headers
(
self
):
def
c_headers
(
self
):
...
@@ -1390,9 +1415,15 @@ class GpuDnnPool(DnnBase):
...
@@ -1390,9 +1415,15 @@ class GpuDnnPool(DnnBase):
"""
"""
Pooling.
Pooling.
:param img: the image 4d or 5d tensor.
Parameters
:param desc: the pooling descriptor.
----------
img
The image 4d or 5d tensor.
desc
The pooling descriptor.
"""
"""
__props__
=
()
__props__
=
()
def
make_node
(
self
,
img
,
desc
):
def
make_node
(
self
,
img
,
desc
):
...
@@ -1547,12 +1578,19 @@ class GpuDnnPoolGrad(DnnBase):
...
@@ -1547,12 +1578,19 @@ class GpuDnnPoolGrad(DnnBase):
"""
"""
The pooling gradient.
The pooling gradient.
:param inp: the input of the pooling.
Parameters
:param out: the output of the pooling in the forward.
----------
:param inp_grad: same size as out, but is the corresponding gradient
inp
information.
The input of the pooling.
:param desc: The pooling descriptor.
out
The output of the pooling in the forward.
inp_grad
Same size as out, but is the corresponding gradient information.
desc
The pooling descriptor.
"""
"""
__props__
=
()
__props__
=
()
def
make_node
(
self
,
inp
,
out
,
inp_grad
,
desc
):
def
make_node
(
self
,
inp
,
out
,
inp_grad
,
desc
):
...
@@ -1725,22 +1763,31 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)):
...
@@ -1725,22 +1763,31 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)):
The memory layout to use is 'bc01', that is 'batch', 'channel',
The memory layout to use is 'bc01', that is 'batch', 'channel',
'first dim', 'second dim' in that order.
'first dim', 'second dim' in that order.
:param img: images to do the pooling over
Parameters
:param ws: subsampling window size
----------
:param stride: subsampling stride (default: (1, 1))
img
:param mode: one of 'max', 'average_inc_pad' or 'average_exc_pad
Images to do the pooling over.
(default: 'max')
ws
:param pad: (padX, padY) padding information.
Subsampling window size.
stride
Subsampling stride (default: (1, 1)).
mode : {'max', 'average_inc_pad', 'average_exc_pad}
pad
(padX, padY) padding information.
padX is the size of the left and right borders,
padX is the size of the left and right borders,
padY is the size of the top and bottom borders.
padY is the size of the top and bottom borders.
:param nd: dimensions of pooling, can be 2 or 3 for 2d or 3d pooling
:param nd: dimensions of pooling, can be 2 or 3 for 2d or 3d pooling
If set to 3 all other params (except mode) must have an extra
If set to 3 all other params (except mode) must have an extra
dimension to match. 3 is only available for cudnn v3
dimension to match. 3 is only available for cudnn v3
:warning
: The cuDNN library only works with GPU that have a compute
.. warning:
: The cuDNN library only works with GPU that have a compute
capability of 3.0 or higer. This means that older GPU will not
capability of 3.0 or higer. This means that older GPU will not
work with this Op.
work with this Op.
:note: This Op implements the ignore_border=True of max_pool_2d.
Notes
-----
This Op implements the ignore_border=True of max_pool_2d.
"""
"""
img
=
gpu_contiguous
(
img
)
img
=
gpu_contiguous
(
img
)
desc
=
GpuDnnPoolDesc
(
ws
=
ws
,
stride
=
stride
,
mode
=
mode
,
pad
=
pad
)()
desc
=
GpuDnnPoolDesc
(
ws
=
ws
,
stride
=
stride
,
mode
=
mode
,
pad
=
pad
)()
...
@@ -1751,13 +1798,19 @@ class GpuDnnSoftmaxBase(DnnBase):
...
@@ -1751,13 +1798,19 @@ class GpuDnnSoftmaxBase(DnnBase):
"""
"""
Op for the cuDNN Softmax.
Op for the cuDNN Softmax.
:param tensor_format: Whether the data format is 'bc01' or 'b01c'.
Parameters
:param algo: 'fast', 'accurate' or 'log' indicating whether, respectively,
----------
computations should be optimized for speed, for accuracy, or if CuDNN
tensor_format
should rather compute the log-softmax instead.
Whether the data format is 'bc01' or 'b01c'.
:param mode: 'instance' or 'channel' indicating whether the softmax should
algo
'fast', 'accurate' or 'log' indicating whether, respectively, computations
should be optimized for speed, for accuracy, or if CuDNN should rather
compute the log-softmax instead.
mode
'instance' or 'channel' indicating whether the softmax should
be computed per image across 'c01' or per spatial location '01' per
be computed per image across 'c01' or per spatial location '01' per
image across 'c'.
image across 'c'.
"""
"""
__props__
=
(
'tensor_format'
,
'mode'
,
'algo'
)
__props__
=
(
'tensor_format'
,
'mode'
,
'algo'
)
...
@@ -1902,13 +1955,20 @@ class GpuDnnSoftmax(GpuDnnSoftmaxBase):
...
@@ -1902,13 +1955,20 @@ class GpuDnnSoftmax(GpuDnnSoftmaxBase):
"""
"""
Op for the cuDNN Softmax.
Op for the cuDNN Softmax.
:param tensor_format: Whether the data format is 'bc01' or 'b01c'.
Parameters
:param algo: 'fast' or 'accurate' indicating whether computations should be
----------
tensor_format
Whether the data format is 'bc01' or 'b01c'.
algo
'fast' or 'accurate' indicating whether computations should be
optimized for speed or accuracy respectively.
optimized for speed or accuracy respectively.
:param mode: 'instance' or 'channel' indicating whether the softmax should
mode
'instance' or 'channel' indicating whether the softmax should
be computed per image across 'c01' or per spatial location '01' per
be computed per image across 'c01' or per spatial location '01' per
image across 'c'.
image across 'c'.
"""
"""
direction
=
'forward'
direction
=
'forward'
softmax_inputs
=
[
'softmax_input'
]
softmax_inputs
=
[
'softmax_input'
]
...
@@ -1963,13 +2023,20 @@ class GpuDnnSoftmaxGrad(GpuDnnSoftmaxBase):
...
@@ -1963,13 +2023,20 @@ class GpuDnnSoftmaxGrad(GpuDnnSoftmaxBase):
"""
"""
Op for the cuDNN SoftmaxGrad.
Op for the cuDNN SoftmaxGrad.
:param tensor_format: Whether the data format is 'bc01' or 'b01c'.
Parameters
:param algo: 'fast' or 'accurate' indicating whether computations should be
----------
tensor_format
Whether the data format is 'bc01' or 'b01c'.
algo
'fast' or 'accurate' indicating whether computations should be
optimized for speed or accuracy respectively.
optimized for speed or accuracy respectively.
:param mode: 'instance' or 'channel' indicating whether the softmax should
mode
'instance' or 'channel' indicating whether the softmax should
be computed per image across 'c01' or per spatial location '01' per
be computed per image across 'c01' or per spatial location '01' per
image across 'c'.
image across 'c'.
"""
"""
direction
=
'backward'
direction
=
'backward'
softmax_inputs
=
[
'softmax_gout'
,
'softmax_input'
]
softmax_inputs
=
[
'softmax_gout'
,
'softmax_input'
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论