Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f293a0f6
提交
f293a0f6
authored
8月 07, 2013
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1469 from shackenberg/adding_GpuJoin.c_code
[WIP] Adding GpuJoin.c_code to cuda/basic_ops.py
上级
b93bb585
67b324a6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
132 行增加
和
3 行删除
+132
-3
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+131
-2
test_basic.py
theano/tensor/tests/test_basic.py
+1
-1
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
f293a0f6
...
...
@@ -2666,10 +2666,10 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
int x_row = d_indices_arr[i];
int y_row = i;
atomicAdd(&X[(x_row * stridesX0) + (j * stridesX1)], Y[(y_row * stridesY0) + (j * stridesY1)]);
}
}
}
return;
}
}
void CudaNdarray_vector_add_fast(CudaNdarray* py_self, CudaNdarray* py_other, PyArrayObject *indices_arr)
{
...
...
@@ -2945,6 +2945,135 @@ class GpuJoin(tensor.Join, GpuOp):
out
[
0
]
=
rval
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
nd
=
node
.
inputs
[
1
]
.
ndim
if
not
all
(
i
.
ndim
==
nd
for
i
in
node
.
inputs
[
2
:]):
# all inputs ndarray need to have the same number of dimensions
raise
NotImplementedError
()
axis
=
inputs
[
0
]
n_cndas
=
len
(
inputs
[
1
:])
input_1
=
inputs
[
1
]
axis
=
inputs
[
0
]
fail
=
sub
[
'fail'
]
out
=
out_
[
0
]
# getting the shapes of all the involved tensors (input[0]+out)
str
=
"""
int axis = PyInt_AsLong((PyObject*)
%(axis)
s);
int nd =
%(nd)
s;
int shape_
%(input_1)
s[nd];
int shape_out[nd];
int width_sum = 0;
int errorcode;
int sum;
for(int i = 0; i<nd; i+=1)
{
shape_
%(input_1)
s[i] = CudaNdarray_HOST_DIMS(
%(input_1)
s)[i];
shape_out[i] = shape_
%(input_1)
s[i];
}
"""
%
locals
()
# getting the shapes of all the involved tensors (input[1:])
# + check: all input tensors have same shape as final out
# execept for "axis" dimension
# shape_%(cdna)s[nd] is initialized before, to prevent following
# error: jump to label __label_9 crosses initialization of
# shape_%(cdna)s[nd]
for
i
,
cdna
in
enumerate
(
inputs
[
2
:]):
str
+=
"""
int shape_
%(cdna)
s[nd];
"""
%
locals
()
for
i
,
cdna
in
enumerate
(
inputs
[
2
:]):
str
+=
"""
for(int i = 0; i<nd; i+=1)
{
shape_
%(cdna)
s[i] = CudaNdarray_HOST_DIMS(
%(cdna)
s)[i];
if((i!=axis) && (shape_
%(cdna)
s[i]!=shape_out[i]))
{
PyErr_Format(
PyExc_ValueError,
"GpuJoin: Wrong inputs for input
%%
d related"
" to inputs 0.!",
i);
%(fail)
s;
}
}
"""
%
locals
()
# computing the new shape for the out tensors
for
i
,
cdna
in
enumerate
(
inputs
[
1
:]):
str
+=
"
\t\t
width_sum += CudaNdarray_HOST_DIMS(
%(cdna)
s)[axis];
\n
"
%
locals
()
str
+=
"
\t\t
shape_out[axis] = width_sum;
\n
"
# preparing the output array + init of the necessary variables
# for the data transfer
str
+=
"""
if (CudaNdarray_prep_output(&
%(out)
s, nd, shape_out))
{
%(fail)
s;
}
PyObject *slice_tuple;
PyObject *section_slice;
PyObject *full_slice;
full_slice = PySlice_New(NULL, NULL, NULL);
PyObject *out_sub;
PyObject *start, *stop, *step;
start = NULL;
stop = NULL;
step = NULL;
sum = 0;
"""
%
locals
()
# start copying the data into the new out tensors
for
i
,
cdna
in
enumerate
(
inputs
[
1
:]):
str
+=
"""
sum += shape_
%(cdna)
s[axis];
Py_XDECREF(stop);
stop = PyInt_FromLong(sum);
slice_tuple = PyTuple_New(nd);
section_slice = PySlice_New(start, stop, step);
for(int i=0; i<nd; i++)
{
if(i!=axis)
{
Py_INCREF(full_slice);
PyTuple_SetItem(slice_tuple, i, full_slice);
}
else
{
Py_INCREF(section_slice);
PyTuple_SetItem(slice_tuple, i, section_slice);
}
}
out_sub = CudaNdarray_Subscript((PyObject*)
%(out)
s, slice_tuple);
errorcode = CudaNdarray_CopyFromCudaNdarray((CudaNdarray*)out_sub,
%(cdna)
s);
if((full_slice == NULL) || (section_slice == NULL) || (out_sub == NULL) || (errorcode != 0))
{
Py_XDECREF(start);
Py_XDECREF(stop);
Py_XDECREF(step);
Py_XDECREF(slice_tuple);
Py_XDECREF(out_sub);
Py_XDECREF(
%(out)
s);
%(fail)
s;
}
Py_XDECREF(out_sub);
Py_XDECREF(slice_tuple);
Py_XDECREF(start);
start = stop;
"""
%
locals
()
str
+=
"""
Py_XDECREF(start);
Py_XDECREF(stop);
Py_XDECREF(step);"""
return
str
def
c_code_cache_version
(
self
):
return
(
1
,)
gpu_join
=
GpuJoin
()
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
f293a0f6
...
...
@@ -3200,7 +3200,7 @@ class T_Join_and_Split(unittest.TestCase):
def
test_broadcastable_flags_many_dims_and_inputs
(
self
):
"""
Test that the right broadcastable flags get set for a
join
Test that the right broadcastable flags get set for a join
with many inputs and many input dimensions.
"""
a
=
TensorType
(
dtype
=
self
.
floatX
,
broadcastable
=
[
1
,
0
,
1
,
0
,
0
,
0
])()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论