Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
192b0e47
提交
192b0e47
authored
9月 06, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Try to give better shape information about params.
上级
d1e64669
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
34 行删除
+30
-34
dnn.py
theano/gpuarray/dnn.py
+30
-34
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
192b0e47
...
@@ -2019,6 +2019,7 @@ class _RNNSplitParams(DnnBase):
...
@@ -2019,6 +2019,7 @@ class _RNNSplitParams(DnnBase):
void *w;
void *w;
void *o;
void *o;
ptrdiff_t off;
ptrdiff_t off;
size_t bshp;
cudnnStatus_t err;
cudnnStatus_t err;
cudnnDataType_t dt;
cudnnDataType_t dt;
cudnnTensorFormat_t tf;
cudnnTensorFormat_t tf;
...
@@ -2084,78 +2085,73 @@ class _RNNSplitParams(DnnBase):
...
@@ -2084,78 +2085,73 @@ class _RNNSplitParams(DnnBase):
nshp[0] = PyGpuArray_DIM(
%(w)
s, 0);
nshp[0] = PyGpuArray_DIM(
%(w)
s, 0);
nshp[1] = 1;
nshp[1] = 1;
"""
%
kw
"""
%
kw
def
get_
matrix
(
id
,
out
):
def
get_
params
(
id
,
m
,
b
):
kw2
=
kw
.
copy
()
kw2
=
kw
.
copy
()
kw2
[
'id'
]
=
id
kw2
[
'id'
]
=
id
kw2
[
'out'
]
=
out
kw2
[
'm'
]
=
m
kw2
[
'b'
]
=
b
return
"""
return
"""
err = cudnnGetRNNLinLayer
Matrix
Params(
%(handle)
s,
%(desc)
s,
%(layer)
s, xdesc, wdesc, w,
%(id)
s, odesc, &o);
err = cudnnGetRNNLinLayer
Bias
Params(
%(handle)
s,
%(desc)
s,
%(layer)
s, xdesc, wdesc, w,
%(id)
s, odesc, &o);
if (err != CUDNN_STATUS_SUCCESS) {
if (err != CUDNN_STATUS_SUCCESS) {
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(odesc);
cudnnDestroyFilterDescriptor(odesc);
PyErr_SetString(PyExc_RuntimeError, "can't fetch
matrix
for id
%(id)
s");
PyErr_SetString(PyExc_RuntimeError, "can't fetch
bias
for id
%(id)
s");
%(fail)
s
%(fail)
s
}
}
off = (intptr_t)o - (intptr_t)w;
off = (intptr_t)o - (intptr_t)w;
assert(off >= 0 && "
matrix
");
assert(off >= 0 && "
bias
");
// This is 3d because of cudnn limitations.
err = cudnnGetFilterNdDescriptor(odesc, 3, &dt, &tf, &nd, dims);
err = cudnnGetFilterNdDescriptor(odesc, 3, &dt, &tf, &nd, dims);
if (err != CUDNN_STATUS_SUCCESS) {
if (err != CUDNN_STATUS_SUCCESS) {
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(odesc);
cudnnDestroyFilterDescriptor(odesc);
PyErr_SetString(PyExc_RuntimeError, "could not get
matrix
shape for id
%(id)
s");
PyErr_SetString(PyExc_RuntimeError, "could not get
bias
shape for id
%(id)
s");
%(fail)
s;
%(fail)
s;
}
}
assert(dims[2] == 1);
// We assume that the typecode matches
// We assume that the typecode matches
%(out)
s = pygpu_reshape(
%(w)
s, 2, nshp, GA_C_ORDER, 1, -1);
assert(dims[2] == 1);
%(out)
s->ga.offset = off;
assert(dims[1] == 1);
%(out)
s->ga.dimensions[0] = dims[0];
%(b)
s = pygpu_view(
%(w)
s, Py_None);
%(out)
s->ga.dimensions[1] = dims[1];
%(b)
s->ga.offset = off;
%(out)
s->ga.strides[0] = dims[1] * gpuarray_get_elsize(
%(out)
s->ga.typecode);
%(b)
s->ga.dimensions[0] = dims[0];
// strides[1] is already ok
bshp = dims[0];
"""
%
kw2
def
get_bias
(
id
,
out
):
err = cudnnGetRNNLinLayerMatrixParams(
%(handle)
s,
%(desc)
s,
%(layer)
s, xdesc, wdesc, w,
%(id)
s, odesc, &o);
kw2
=
kw
.
copy
()
kw2
[
'id'
]
=
id
kw2
[
'out'
]
=
out
return
"""
err = cudnnGetRNNLinLayerBiasParams(
%(handle)
s,
%(desc)
s,
%(layer)
s, xdesc, wdesc, w,
%(id)
s, odesc, &o);
if (err != CUDNN_STATUS_SUCCESS) {
if (err != CUDNN_STATUS_SUCCESS) {
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(odesc);
cudnnDestroyFilterDescriptor(odesc);
PyErr_SetString(PyExc_RuntimeError, "can't fetch
bias
for id
%(id)
s");
PyErr_SetString(PyExc_RuntimeError, "can't fetch
matrix
for id
%(id)
s");
%(fail)
s
%(fail)
s
}
}
off = (intptr_t)o - (intptr_t)w;
off = (intptr_t)o - (intptr_t)w;
assert(off >= 0 && "
bias
");
assert(off >= 0 && "
matrix
");
// This is 3d because of cudnn limitations.
err = cudnnGetFilterNdDescriptor(odesc, 3, &dt, &tf, &nd, dims);
err = cudnnGetFilterNdDescriptor(odesc, 3, &dt, &tf, &nd, dims);
if (err != CUDNN_STATUS_SUCCESS) {
if (err != CUDNN_STATUS_SUCCESS) {
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(wdesc);
cudnnDestroyFilterDescriptor(odesc);
cudnnDestroyFilterDescriptor(odesc);
PyErr_SetString(PyExc_RuntimeError, "could not get
bias
shape for id
%(id)
s");
PyErr_SetString(PyExc_RuntimeError, "could not get
matrix
shape for id
%(id)
s");
%(fail)
s;
%(fail)
s;
}
}
// We assume that the typecode matches
assert(dims[2] == 1);
assert(dims[1] == 1);
assert(dims[1] == 1);
%(out)
s = pygpu_view(
%(w)
s, Py_None);
assert(dims[2] == 1);
%(out)
s->ga.offset = off;
// We assume that the typecode matches
%(out)
s->ga.dimensions[0] = dims[0];
%(m)
s = pygpu_reshape(
%(w)
s, 2, nshp, GA_C_ORDER, 1, -1);
%(m)
s->ga.offset = off;
%(m)
s->ga.dimensions[0] = dims[0] / bshp;
%(m)
s->ga.dimensions[1] = bshp;
%(m)
s->ga.strides[0] = bshp * gpuarray_get_elsize(
%(m)
s->ga.typecode);
// strides[1] is already ok
"""
%
kw2
"""
%
kw2
for
i
,
o
in
enumerate
(
outputs
):
for
i
in
range
(
len
(
outputs
)
//
2
):
if
i
%
2
==
0
:
code
+=
get_params
(
i
,
outputs
[
2
*
i
],
outputs
[(
2
*
i
)
+
1
])
code
+=
get_matrix
(
i
//
2
,
o
)
else
:
code
+=
get_bias
(
i
//
2
,
o
)
code
+=
"""
code
+=
"""
cudnnDestroyTensorDescriptor(xdesc);
cudnnDestroyTensorDescriptor(xdesc);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论