Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4ed822e5
提交
4ed822e5
authored
12月 04, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement 101 reduce in the new back-end by reusing 1011 kernelinside the op
上级
c62451be
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
4 行删除
+50
-4
elemwise.py
theano/sandbox/gpuarray/elemwise.py
+36
-2
test_elemwise.py
theano/sandbox/gpuarray/tests/test_elemwise.py
+14
-2
没有找到文件。
theano/sandbox/gpuarray/elemwise.py
浏览文件 @
4ed822e5
...
...
@@ -833,7 +833,7 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype):
return
sio
.
getvalue
()
def
_makecall
(
self
,
node
,
name
,
x
,
z
,
fail
,
pattern
=
None
):
def
_makecall
(
self
,
node
,
name
,
x
,
z
,
fail
,
pattern
=
None
,
extra_dims
=
(),
extra_strides
=
()
):
"""
Return a string for making a kernel call.
...
...
@@ -876,6 +876,9 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype):
for
i
in
xrange
(
ndim
):
params
.
append
(
"(void *)&PyGpuArray_DIMS(
%(x)
s)[
%(i)
s]"
%
locals
())
for
declaration
,
value
in
extra_dims
:
print
(
declaration
%
locals
(),
file
=
sio
)
params
.
append
(
value
)
params
.
append
(
"(void *)
%(x)
s->ga.data"
%
locals
())
params
.
append
(
"(void *)&
%(x)
s->ga.offset"
%
locals
())
for
i
in
xrange
(
ndim
):
...
...
@@ -883,6 +886,9 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype):
ssize_t stride_A
%(i)
d = PyGpuArray_STRIDES(
%(x)
s)[
%(i)
s]/sizeof(
%(in_dtype)
s);
"""
%
locals
(),
file
=
sio
)
params
.
append
(
"(void *)&stride_A
%(i)
d"
%
locals
())
for
declaration
,
value
in
extra_strides
:
print
(
declaration
%
locals
(),
file
=
sio
)
params
.
append
(
value
)
params
.
append
(
"(void *)
%(z)
s->ga.data"
%
locals
())
params
.
append
(
"(void *)&
%(z)
s->ga.offset"
%
locals
())
...
...
@@ -1779,6 +1785,34 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype):
}
"""
%
locals
(),
file
=
sio
)
def
c_code_reduce_101
(
self
,
sio
,
node
,
name
,
x
,
z
,
fail
):
makecall
=
self
.
_makecall
(
node
,
name
,
x
,
z
,
fail
,
extra_dims
=
[(
"size_t one = 1;"
,
"(void *) &one"
)],
extra_strides
=
[(
"ssize_t sone = 1;"
,
"(void *) &sone"
)],
pattern
=
"1011"
)
print
(
"""
{
int verbose = 0;
// size_t n_threads[3] = {std::min(PyGpuArray_DIMS(
%(x)
s)[3],
// (size_t) 256), 1, 1};
size_t n_threads[3] = {1, 1, 1};
while (n_threads[0] * (n_threads[1]+1) <= 256) ++n_threads[1];
if (n_threads[1] > PyGpuArray_DIMS(
%(x)
s)[2])
n_threads[1] = PyGpuArray_DIMS(
%(x)
s)[2];
while (n_threads[0] * n_threads[1] * (n_threads[2]+1) <= 256)
++n_threads[2];
if (n_threads[2] > 64)
n_threads[2] = 64;
if (n_threads[2] > PyGpuArray_DIMS(
%(x)
s)[0])
n_threads[2] = PyGpuArray_DIMS(
%(x)
s)[0];
size_t n_blocks[3] = {PyGpuArray_DIMS(
%(x)
s)[1], 1, 1};
%(makecall)
s
}
"""
%
locals
(),
file
=
sio
)
def
c_code_reduce_111
(
self
,
sio
,
node
,
name
,
x
,
z
,
fail
):
makecall
=
self
.
_makecall
(
node
,
name
,
x
,
z
,
fail
)
print
(
"""
...
...
@@ -2572,7 +2606,7 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype):
"""
%
locals
(),
file
=
sio
)
kernels
.
append
(
Kernel
(
code
=
sio
.
getvalue
(),
name
=
kname
,
params
=
params
,
flags
=
flags
,
objvar
=
k_var
))
if
self
.
reduce_mask
==
(
1
,
0
,
1
,
1
):
if
self
.
reduce_mask
==
(
1
,
0
,
1
,
1
)
or
self
.
reduce_mask
==
(
1
,
0
,
1
)
:
reducebuf
=
self
.
_k_reduce_buf
(
'Z[blockIdx.x*sZ0]'
,
node
,
nodename
,
sub
=
{})
reduce_fct
=
self
.
_assign_reduce
(
node
,
nodename
,
"myresult"
,
...
...
theano/sandbox/gpuarray/tests/test_elemwise.py
浏览文件 @
4ed822e5
...
...
@@ -172,16 +172,28 @@ class test_GpuCAReduceCuda(test_GpuCAReduceCPY):
((
4100
,
4
,
3
),
[
2
]),
((
5
,
4100
,
3
),
[
2
]),
((
5
,
4
,
4100
),
[
2
]),
# 001
((
4100
,
4
,
3
),
[
0
,
1
]),
((
5
,
4100
,
3
),
[
0
,
1
]),
((
5
,
4
,
4100
),
[
0
,
1
]),
# 110
((
4100
,
4
,
3
),
[
1
,
2
]),
((
5
,
4100
,
3
),
[
1
,
2
]),
((
5
,
4
,
4100
),
[
1
,
2
]),
# 011
# ((4100,4,3),[0,2]),((5,4100,3),[0,2]),((5,4,4100),[0,2]),#101 ##not implemented
((
4100
,
4
,
3
),[
0
,
2
]),((
5
,
4100
,
3
),[
0
,
2
]),((
5
,
4
,
4100
),[
0
,
2
]),
#101
((
4100
,
4
,
3
),
[
0
,
1
,
2
]),
((
5
,
4100
,
3
),
[
0
,
1
,
2
]),
((
5
,
4
,
4100
),
[
0
,
1
,
2
]),
# 111
((
65
,
4
,
3
),
[
0
,
1
,
2
]),
((
5
,
65
,
3
),
[
0
,
1
,
2
]),
((
5
,
4
,
65
),
[
0
,
1
,
2
]),
# 111
# reduce over 2d
((
4100
,
4
,
3
,
2
),
[
2
,
3
]),
((
4
,
4100
,
3
,
2
),
[
2
,
3
]),
((
4
,
3
,
4100
,
2
),
[
2
,
3
]),
((
4
,
3
,
2
,
4100
),
[
2
,
3
]),
# 0011
((
4100
,
4
,
3
,
2
),
[
1
,
3
]),
((
4
,
4100
,
3
,
2
),
[
1
,
3
]),
((
4
,
3
,
4100
,
2
),
[
1
,
3
]),
((
4
,
3
,
2
,
4100
),
[
1
,
3
]),
# 0101
#((4100, 4, 3, 2), [1, 2]), ((4, 4100, 3, 2), [1, 2]), ((4, 3, 4100, 2), [1, 2]), ((4, 3, 2, 4100), [1, 2]), # 0110 by reshape
#((4100,4,3,2),[0,3]),((4,4100,3,2),[0,3]),((4,3,4100,2),[0,3]),((4,3,2,4100),[0,3]),#1001 by reshape
#((4100,4,3,2),[0,2]),((4,4100,3,2),[0,2]),((4,3,4100,2),[0,2]),((4,3,2,4100),[0,2]),#1010 not implemented
#((4100, 4, 3, 2), [0, 1]), ((4, 4100, 3, 2), [0, 1]), ((4, 3, 4100, 2), [0, 1]), ((4, 3, 2, 4100), [0, 1]), # 1100 by reshape
# reduce over 3d
# 3d not tested: 1101, 1110, 1111
# ((4100,4,3,2),[0,1,3]),((4,4100,3,2),[0,1,3]),((4,3,4100,2),[0,1,3]),((4,3,2,4100),[0,1,3]),#1101 by reshape
# ((4100, 4, 3, 2), [0, 1, 2]), ((4, 4100, 3, 2), [0, 1, 2]), ((4, 3, 4100, 2), [0, 1, 2]), ((4, 3, 2, 4100), [0, 1, 2]), # 1110 by reshape
((
4100
,
4
,
3
,
2
),
[
0
,
2
,
3
]),
((
4
,
4100
,
3
,
2
),
[
0
,
2
,
3
]),
((
4
,
3
,
4100
,
2
),
[
0
,
2
,
3
]),
# ((4,3,2,4100),[0,2,3]),#1011
((
4100
,
4
,
3
,
2
),
[
1
,
2
,
3
]),
((
4
,
4100
,
3
,
2
),
[
1
,
2
,
3
]),
((
4
,
3
,
4100
,
2
),
[
1
,
2
,
3
]),
((
4
,
3
,
2
,
4100
),
[
1
,
2
,
3
]),
# 0111
((
65
,
4
,
3
,
2
),
[
1
,
2
,
3
]),
((
4
,
65
,
3
,
2
),
[
1
,
2
,
3
]),
((
4
,
3
,
65
,
2
),
[
1
,
2
,
3
]),
((
4
,
3
,
2
,
65
),
[
1
,
2
,
3
]),
# 0111
((
4100
,
2
,
3
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
4100
,
3
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
3
,
4100
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
3
,
4
,
4100
),
[
0
,
1
,
2
,
3
]),
((
128
,
1
,
2
,
3
),
[
0
,
1
,
2
,
3
]),
# 1111
# reduce over 4d
((
4100
,
2
,
3
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
4100
,
3
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
3
,
4100
,
4
),
[
0
,
1
,
2
,
3
]),
((
2
,
3
,
4
,
4100
),
[
0
,
1
,
2
,
3
]),
((
128
,
1
,
3
,
3
),
[
0
,
1
,
2
,
3
]),
# 1111
# test pattern implemented by reshape
# Skip them as this test the op directly, not the optimization with reshape
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论