Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8aeb40a8
提交
8aeb40a8
authored
6月 09, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make CudaNdarray setitem fct able to unbroadcast a value.
上级
e6432acb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
33 行增加
和
15 行删除
+33
-15
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+8
-4
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+1
-1
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+24
-10
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
8aeb40a8
...
...
@@ -1428,7 +1428,7 @@ CudaNdarray_setitem(PyObject *o, PyObject *key, PyObject *v)
return -1;
}
if(CudaNdarray_CopyFromCudaNdarray(rval, (CudaNdarray*)v))
if(CudaNdarray_CopyFromCudaNdarray(rval, (CudaNdarray*)v
, true
))
{
Py_DECREF(viewCopyForComparison);
Py_DECREF((PyObject*)rval);
...
...
@@ -2045,7 +2045,7 @@ static __global__ void k_copy_1d(const int N, const float * x, const int sx, flo
}
//copy from other into self
int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other)
int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other
, bool unbroadcast
)
{
int verbose = 0;
//standard elemwise size checks
...
...
@@ -2063,7 +2063,8 @@ int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other)
unsigned int size = 1;
for (int i = 0; i< self->nd; ++i)
{
if (CudaNdarray_HOST_DIMS(self)[i] != CudaNdarray_HOST_DIMS(other)[i])
if ((CudaNdarray_HOST_DIMS(self)[i] != CudaNdarray_HOST_DIMS(other)[i])
&& (1!=CudaNdarray_HOST_DIMS(other)[i] || !unbroadcast) )
{
PyErr_Format(PyExc_TypeError, "need same dimensions for dim %d, destination=%d, source=%d",
i, CudaNdarray_HOST_DIMS(self)[i], CudaNdarray_HOST_DIMS(other)[i]);
...
...
@@ -2123,11 +2124,14 @@ int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other)
// call worker routine
unsigned int n_blocks = std::min(size, (unsigned int)NUM_VECTOR_OP_BLOCKS);
unsigned int threads_per_block = std::min(ceil_intdiv(size, n_blocks), (unsigned int)NUM_VECTOR_OP_THREADS_PER_BLOCK);
CudaNdarray * cuda_dims = other;
if(unbroadcast)
cuda_dims = self;
//copy from other into self
k_elemwise_unary_rowmajor_copy<<<n_blocks, threads_per_block>>>(
size,
(unsigned int)other->nd,
(const int *)CudaNdarray_DEV_DIMS(
other
),
(const int *)CudaNdarray_DEV_DIMS(
cuda_dims
),
(const float*)CudaNdarray_DEV_DATA(other), (const int *)CudaNdarray_DEV_STRIDES(other),
CudaNdarray_DEV_DATA(self), (const int *)CudaNdarray_DEV_STRIDES(self));
CNDA_THREAD_SYNC;
...
...
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
8aeb40a8
...
...
@@ -459,7 +459,7 @@ int CudaNdarray_CopyFromArray(CudaNdarray * self, PyArrayObject*obj);
*
* self is reallocated to have the correct dimensions if necessary.
*/
int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other);
int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other
, bool unbroadcast = false
);
/**
* Transfer the contents of CudaNdarray `self` to a new numpy ndarray.
...
...
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
8aeb40a8
...
...
@@ -407,6 +407,23 @@ def test_setitem_matrix_tensor3():
assert
numpy
.
all
(
numpy
.
asarray
(
_a
[:,
1
,
1
])
==
b
)
def
test_setitem_matrix_bad_shape
():
a
=
numpy
.
arange
(
27
)
a
.
resize
((
3
,
3
,
3
))
a
=
theano
.
_asarray
(
a
,
dtype
=
'float32'
)
_a
=
cuda_ndarray
.
CudaNdarray
(
a
)
b
=
theano
.
_asarray
([
7
,
8
],
dtype
=
'float32'
)
_b
=
cuda_ndarray
.
CudaNdarray
(
b
)
try
:
# attempt to assign the ndarray b with setitem
_a
[:,:,
1
]
=
_b
assert
False
except
TypeError
,
e
:
#print e
assert
True
def
test_setitem_assign_to_slice
():
a
=
numpy
.
arange
(
27
)
a
.
resize
((
3
,
3
,
3
))
...
...
@@ -425,9 +442,7 @@ def test_setitem_assign_to_slice():
assert
numpy
.
all
(
numpy
.
asarray
(
_a
[:,
1
,
1
])
==
b
)
# this fails for the moment
def
test_setitem_broadcast_must_fail
():
def
test_setitem_broadcast
():
a
=
numpy
.
arange
(
27
)
a
.
resize
((
3
,
3
,
3
))
a
=
theano
.
_asarray
(
a
,
dtype
=
'float32'
)
...
...
@@ -435,16 +450,15 @@ def test_setitem_broadcast_must_fail():
b
=
theano
.
_asarray
([
7
,
8
,
9
],
dtype
=
'float32'
)
_b
=
cuda_ndarray
.
CudaNdarray
(
b
)
try
:
# attempt to assign vector to all rows of this submatrix
_a
[:,:,
1
]
=
_b
assert
False
except
TypeError
:
assert
True
_a
[:,:,
1
]
=
_b
.
reshape
((
1
,
3
))
a
[:,:,
1
]
=
b
.
reshape
((
1
,
3
))
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
a
)
# this also fails for the moment
def
test_setitem_rightvalue_ndarray_fails
():
"""
Now we don't automatically add dimensions to broadcast
"""
a
=
numpy
.
arange
(
27
)
a
.
resize
((
3
,
3
,
3
))
a
=
theano
.
_asarray
(
a
,
dtype
=
'float32'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论