Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
29615c83
提交
29615c83
authored
9月 16, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add operation to handle context transfer and plug it in.
上级
618ed85c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
78 行增加
和
14 行删除
+78
-14
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+71
-11
type.py
theano/sandbox/gpuarray/type.py
+7
-3
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
29615c83
...
...
@@ -26,17 +26,27 @@ from .fp16_help import write_w
def
as_gpuarray_variable
(
x
,
context_name
):
# This is a pre-optimization to reduce the number of useless
# transfers in the graph and reduce optimization time.
if
getattr
(
x
,
'owner'
,
None
):
if
(
isinstance
(
x
.
owner
.
op
,
HostFromGpu
)
and
x
.
owner
.
inputs
[
0
]
.
type
.
context_name
==
context_name
):
return
x
.
owner
.
inputs
[
0
]
elif
(
isinstance
(
x
.
owner
.
op
,
GpuFromHost
)
and
x
.
owner
.
inputs
[
0
]
.
owner
and
isinstance
(
x
.
owner
.
inputs
[
0
]
.
owner
.
op
,
HostFromGpu
)
and
x
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
.
type
.
context_name
==
context_name
):
return
x
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
# If this is already some form of variable, try to avoid an extra transfer
if
isinstance
(
x
,
Variable
):
while
True
:
# If we are already a GpuArrayVariable in the right context
# then there is nothing to do.
if
(
isinstance
(
x
.
type
,
GpuArrayType
)
and
x
.
type
.
context_name
==
context_name
):
return
x
# If x is the result of a transfer, try to dig through.
if
getattr
(
x
,
'owner'
,
None
):
if
isinstance
(
x
.
owner
.
op
,
HostFromGpu
):
x
=
x
.
owner
.
inputs
[
0
]
continue
if
isinstance
(
x
.
owner
.
op
,
GpuFromHost
):
x
=
x
.
owner
.
inputs
[
0
]
continue
# If none of the conditions where met, then continue with
# the rest of the body
break
if
hasattr
(
x
,
'_as_GpuArrayVariable'
):
return
x
.
_as_GpuArrayVariable
(
context_name
)
...
...
@@ -383,6 +393,56 @@ class GpuFromHost(Op):
return
(
6
,)
class
GpuToGpu
(
Op
):
__props__
=
(
'context_name'
,)
_f16_ok
=
True
context_type
=
gpu_context_type
def
__init__
(
self
,
context_name
):
self
.
context_name
=
context_name
def
__str__
(
self
):
return
'GpuToGpu<
%
s>'
%
(
self
.
context_name
,)
def
make_node
(
self
,
x
):
if
not
isinstance
(
x
.
type
,
GpuArrayType
):
raise
TypeError
(
x
)
return
Apply
(
self
,
[
x
],
[
GpuArrayType
(
broadcastable
=
x
.
broadcastable
,
context_name
=
self
.
context_name
,
dtype
=
x
.
dtype
)()])
def
get_context
(
self
,
node
):
return
get_context
(
self
.
context_name
)
def
perform
(
self
,
node
,
inp
,
out
,
ctx
):
x
,
=
inp
z
,
=
out
z
[
0
]
=
x
.
transfer
(
ctx
)
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
return
[
GpuToGpu
(
inputs
[
0
]
.
type
.
context_name
)(
gz
)]
def
R_op
(
self
,
inputs
,
eval_points
):
return
self
.
grad
(
inputs
,
eval_points
)
def
infer_shape
(
self
,
node
,
xshp
):
return
xshp
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
Py_XDECREF(
%(out)
s);
%(out)
s = pygpu_transfer(
%(inp)
s,
%(ctx)
s, 0);
if (
%(out)
s == NULL) {
%(fail)
s
}
"""
%
{
'inp'
:
inputs
[
0
],
'ctx'
:
sub
[
'context'
],
'out'
:
outputs
[
0
],
'fail'
:
sub
[
'fail'
]}
def
c_code_cache_version
(
self
):
return
(
0
,)
class
GpuAlloc
(
HideC
,
Alloc
):
"""
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
29615c83
...
...
@@ -159,7 +159,7 @@ class GpuArrayType(Type):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
if
hasattr
(
other
,
'_as_GpuArrayVariable'
):
other
=
other
.
_as_GpuArrayVariable
()
other
=
other
.
_as_GpuArrayVariable
(
self
.
context_name
)
if
not
isinstance
(
other
,
Variable
):
other
=
self
.
Constant
(
type
=
self
,
data
=
other
)
...
...
@@ -396,8 +396,12 @@ class _operators(_tensor_py_operators):
from
.basic_ops
import
host_from_gpu
return
host_from_gpu
(
self
)
def
_as_GpuArrayVariable
(
self
):
return
self
def
_as_GpuArrayVariable
(
self
,
context_name
):
if
self
.
type
.
context_name
==
context_name
:
return
self
else
:
from
.basic_ops
import
GpuToGpu
return
GpuToGpu
(
context_name
)(
self
)
class
GpuArrayVariable
(
_operators
,
Variable
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论