Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
354169fc
提交
354169fc
authored
7月 13, 2014
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Altered code to zero out the memory that we create.
上级
ddabc5b5
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
59 行增加
和
16 行删除
+59
-16
blas_c.py
theano/tensor/blas_c.py
+59
-16
没有找到文件。
theano/tensor/blas_c.py
浏览文件 @
354169fc
...
@@ -369,7 +369,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
...
@@ -369,7 +369,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
PyErr_SetString(PyExc_AssertionError, "
%(zz)
s !=
%(aa)
s");
PyErr_SetString(PyExc_AssertionError, "
%(zz)
s !=
%(aa)
s");
%(fail)
s
%(fail)
s
}
}
if (dbeta != 0
||
%(force_init_beta)
d
)
if (dbeta != 0)
{
{
if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_FLOAT)
if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_FLOAT)
{
{
...
@@ -382,7 +382,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
...
@@ -382,7 +382,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
zoutdata[Zi*i] = fbeta * zdata[Ai*i];
zoutdata[Zi*i] = fbeta * zdata[Ai*i];
}
}
}
}
else if (PyArray_DESCR(
%(
xx
)
s)->type_num == NPY_DOUBLE)
else if (PyArray_DESCR(
%(
zz
)
s)->type_num == NPY_DOUBLE)
{
{
double * zoutdata = (double*) PyArray_DATA(
%(zz)
s);
double * zoutdata = (double*) PyArray_DATA(
%(zz)
s);
const double * zdata = (double*)PyArray_DATA(
%(aa)
s);
const double * zdata = (double*)PyArray_DATA(
%(aa)
s);
...
@@ -401,6 +401,53 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
...
@@ -401,6 +401,53 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail, force_init_beta=
}
}
fbeta = dbeta = 1.0;
fbeta = dbeta = 1.0;
}
}
else if (
%(force_init_beta)
d)
{
if (PyArray_IS_C_CONTIGUOUS(
%(zz)
s))
{
if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_FLOAT)
{
memset((void *)PyArray_DATA(
%(zz)
s), 0, PyArray_SIZE(
%(zz)
s)*sizeof(float));
}
else if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_DOUBLE)
{
memset((void *)PyArray_DATA(
%(zz)
s), 0, PyArray_SIZE(
%(zz)
s)*sizeof(double));
}
else
{
PyErr_SetString(PyExc_AssertionError,
"neither float nor double dtype");
%(fail)
s
}
}
else
{
if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_FLOAT)
{
float *zoutdata = (float *)PyArray_DATA(
%(zz)
s);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(float);
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
{
zoutdata[Zi*i] = 0.0f;
}
}
else if (PyArray_DESCR(
%(zz)
s)->type_num == NPY_DOUBLE)
{
double *zoutdata = (double *)PyArray_DATA(
%(zz)
s);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(double);
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
{
zoutdata[Zi*i] = 0.0;
}
}
else
{
PyErr_SetString(PyExc_AssertionError,
"neither float nor double dtype");
%(fail)
s
}
}
}
}
}
else
else
{
{
...
@@ -604,26 +651,22 @@ def check_force_gemv_init():
...
@@ -604,26 +651,22 @@ def check_force_gemv_init():
beta*aa + alpha*dot(xx, yy)
beta*aa + alpha*dot(xx, yy)
where we set
z = b = zeros of the correct dimensions we do not actually
where we set
aa = betas = zeros of the correct dimensions we do not
set z = zeros and instead let the BLAS perform b*z with uninitialized
actually set aa = zeros and instead let the BLAS perform beta*aa with
memory for speed. Occasionally the memory contains values that are
uninitialized memory for speed. Occasionally the memory contains values
equivalent to NaN in which case the product b*z contains NaN's for
that are equivalent to NaN in which case the product beta*aa contains
correctly implemented BLAS libraries. In this situation, since we ar
e
NaN's for correctly implemented BLAS libraries. In this situation, sinc
e
introducing the NaN's, we need to test whether the BLAS performs
we are
introducing the NaN's, we need to test whether the BLAS performs
correctly. If it *does*, i.e. it actually performs the multiplication
correctly. If it *does*, i.e. it actually performs the multiplication
b
*z
which will result in NaN's in the result, then we need intialize
b
eta*aa
which will result in NaN's in the result, then we need intialize
the memory to zeros.
the memory to zeros.
Note: We perform this check here, as opposed to in the global scope,
because the environment is not completely setup at the point in which
we would perform this check in global scope.
"""
"""
aa
=
T
.
vector
(
'aa'
)
aa
=
T
.
vector
(
'aa'
)
yy
=
T
.
vector
(
'yy'
)
yy
=
T
.
vector
(
'yy'
)
xx
=
T
.
matrix
(
'xx'
)
xx
=
T
.
matrix
(
'xx'
)
f
=
theano
.
function
(
f
=
theano
.
function
(
[
aa
,
yy
,
xx
],
[
aa
,
yy
,
xx
],
gemv_no_inplace
(
aa
,
0
.
,
xx
,
yy
,
0.
),
gemv_no_inplace
(
aa
,
1
.
,
xx
,
yy
,
0.
),
theano
.
compile
.
Mode
(
optimizer
=
'fast_compile'
)
theano
.
compile
.
Mode
(
optimizer
=
'fast_compile'
)
)
)
...
@@ -635,11 +678,11 @@ def check_force_gemv_init():
...
@@ -635,11 +678,11 @@ def check_force_gemv_init():
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
yy_data
=
numpy
.
array
(
yy_data
=
numpy
.
array
(
numpy
.
zeros
((
2
,))
,
numpy
.
ones
((
2
,))
*
2
,
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
xx_data
=
numpy
.
array
(
xx_data
=
numpy
.
array
(
float
(
'NaN'
)
*
numpy
.
ones
((
2
,
2
)),
numpy
.
ones
((
2
,
2
)),
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
zz
=
f
(
aa_data
,
yy_data
,
xx_data
)
zz
=
f
(
aa_data
,
yy_data
,
xx_data
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论