Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
224af930
提交
224af930
authored
5月 27, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Donc rebuild inplace add kernels all the time for GpuIncSubtensor.
上级
0044349f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
16 行删除
+21
-16
subtensor.py
theano/gpuarray/subtensor.py
+21
-16
没有找到文件。
theano/gpuarray/subtensor.py
浏览文件 @
224af930
...
@@ -20,6 +20,22 @@ from .basic_ops import (as_gpuarray_variable, HideC, GpuKernelBase, Kernel,
...
@@ -20,6 +20,22 @@ from .basic_ops import (as_gpuarray_variable, HideC, GpuKernelBase, Kernel,
infer_context_name
)
infer_context_name
)
iadd_reg
=
{}
def
get_iadd
(
a
,
b
):
key
=
(
a
.
type
.
dtype
,
b
.
type
.
dtype
,
a
.
type
.
context
)
if
key
not
in
iadd_reg
:
if
a
.
dtype
==
'float16'
or
b
.
dtype
==
'float16'
:
raise
NotImplementedError
(
'float16 is not supported by pygpu '
'elemwise'
)
a_arg
=
pygpu
.
elemwise
.
arg
(
'a'
,
a
.
type
.
dtype
,
read
=
True
,
write
=
True
)
b_arg
=
pygpu
.
elemwise
.
arg
(
'b'
,
b
.
type
.
dtype
,
read
=
True
)
res
=
pygpu
.
elemwise
.
GpuElemwise
(
a
.
type
.
context
,
"a = a + b"
,
[
a_arg
,
b_arg
])
iadd_reg
[
key
]
=
res
return
iadd_reg
[
key
]
class
GpuSubtensor
(
HideC
,
Subtensor
):
class
GpuSubtensor
(
HideC
,
Subtensor
):
"""
"""
Subtensor on the GPU.
Subtensor on the GPU.
...
@@ -217,9 +233,10 @@ class GpuIncSubtensor(IncSubtensor):
...
@@ -217,9 +233,10 @@ class GpuIncSubtensor(IncSubtensor):
# we've sliced out an N-D tensor with N > 0
# we've sliced out an N-D tensor with N > 0
if
not
self
.
set_instead_of_inc
:
if
not
self
.
set_instead_of_inc
:
# sub_x += y
# sub_x += y
pygpu
.
elemwise
.
ielemwise2
(
sub_x
,
'+'
,
y
,
broadcast
=
False
)
iadd
=
get_iadd
(
node
.
inputs
[
0
],
node
.
inputs
[
1
])
iadd
(
sub_x
,
y
,
broadcast
=
False
)
else
:
else
:
# sub_x
+= -sub_x +
y
# sub_x
[...] =
y
x
.
__setitem__
(
cdata
,
y
)
x
.
__setitem__
(
cdata
,
y
)
else
:
else
:
# scalar case
# scalar case
...
@@ -452,7 +469,6 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
...
@@ -452,7 +469,6 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
Implement AdvancedIncSubtensor1 on the gpu.
Implement AdvancedIncSubtensor1 on the gpu.
"""
"""
def
make_node
(
self
,
x
,
y
,
ilist
):
def
make_node
(
self
,
x
,
y
,
ilist
):
ctx_name
=
infer_context_name
(
x
,
y
)
ctx_name
=
infer_context_name
(
x
,
y
)
x_
=
as_gpuarray_variable
(
x
,
ctx_name
)
x_
=
as_gpuarray_variable
(
x
,
ctx_name
)
...
@@ -480,17 +496,6 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
...
@@ -480,17 +496,6 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
return
gof
.
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
return
gof
.
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
def
getInplElemwiseAdditionKernel
(
self
,
a
,
b
):
if
a
.
dtype
==
'float16'
or
b
.
dtype
==
'float16'
:
raise
NotImplementedError
(
'float16 is not supported by pygpu '
'elemwise'
)
a_arg
=
pygpu
.
tools
.
as_argument
(
a
,
'a'
)
b_arg
=
pygpu
.
tools
.
as_argument
(
b
,
'b'
)
args
=
[
a_arg
,
b_arg
]
oper
=
"a[i] = a[i] +
%(b)
s"
%
{
'b'
:
b_arg
.
expr
()}
k
=
pygpu
.
elemwise
.
ElemwiseKernel
(
a
.
context
,
args
,
oper
)
return
k
# We can't use the parent version that loops on each index
# We can't use the parent version that loops on each index
# as we also need to loop when set_instead_of_inc is True and the
# as we also need to loop when set_instead_of_inc is True and the
# parent doesn't loop in that case.
# parent doesn't loop in that case.
...
@@ -521,7 +526,7 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
...
@@ -521,7 +526,7 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
for
(
j
,
i
)
in
enumerate
(
idx
):
for
(
j
,
i
)
in
enumerate
(
idx
):
x
[
i
]
=
y
[
j
]
x
[
i
]
=
y
[
j
]
else
:
else
:
k
=
self
.
getInplElemwiseAdditionKernel
(
x
[
0
],
y
[
0
])
k
=
get_iadd
(
node
.
inputs
[
0
],
node
.
inputs
[
1
])
for
(
j
,
i
)
in
enumerate
(
idx
):
for
(
j
,
i
)
in
enumerate
(
idx
):
k
(
x
[
i
],
y
[
j
],
broadcast
=
True
)
k
(
x
[
i
],
y
[
j
],
broadcast
=
True
)
else
:
else
:
...
@@ -536,7 +541,7 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
...
@@ -536,7 +541,7 @@ class GpuAdvancedIncSubtensor1(HideC, tensor.AdvancedIncSubtensor1):
for
i
in
idx
:
for
i
in
idx
:
x
[
i
]
=
reshaped_y
x
[
i
]
=
reshaped_y
else
:
else
:
k
=
self
.
getInplElemwiseAdditionKernel
(
x
[
0
],
reshaped_y
)
k
=
get_iadd
(
node
.
inputs
[
0
],
node
.
inputs
[
1
]
)
for
i
in
idx
:
for
i
in
idx
:
k
(
x
[
i
],
reshaped_y
,
broadcast
=
True
)
k
(
x
[
i
],
reshaped_y
,
broadcast
=
True
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论