Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a51c01ea
提交
a51c01ea
authored
9月 28, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't put scalar in shared var on the GPU by default.
上级
29575d6e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
6 行删除
+25
-6
opt.py
theano/gpuarray/opt.py
+3
-6
type.py
theano/gpuarray/type.py
+22
-0
没有找到文件。
theano/gpuarray/opt.py
浏览文件 @
a51c01ea
...
@@ -29,7 +29,7 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
...
@@ -29,7 +29,7 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
from
theano.tests.breakpoint
import
PdbBreakpoint
from
theano.tests.breakpoint
import
PdbBreakpoint
from
.type
import
(
GpuArrayType
,
GpuArrayConstant
,
get_context
,
from
.type
import
(
GpuArrayType
,
GpuArrayConstant
,
get_context
,
ContextNotDefined
)
ContextNotDefined
,
move_to_gpu
)
from
.basic_ops
import
(
as_gpuarray_variable
,
infer_context_name
,
from
.basic_ops
import
(
as_gpuarray_variable
,
infer_context_name
,
host_from_gpu
,
GpuToGpu
,
host_from_gpu
,
GpuToGpu
,
HostFromGpu
,
GpuFromHost
,
HostFromGpu
,
GpuFromHost
,
...
@@ -242,9 +242,8 @@ class InputToGpuOptimizer(Optimizer):
...
@@ -242,9 +242,8 @@ class InputToGpuOptimizer(Optimizer):
target
=
getattr
(
input
.
tag
,
'target'
,
None
)
target
=
getattr
(
input
.
tag
,
'target'
,
None
)
if
target
==
'cpu'
:
if
target
==
'cpu'
:
continue
continue
# Do not move *int* scalar to the GPU.
if
(
isinstance
(
input
.
type
,
tensor
.
TensorType
)
and
if
(
isinstance
(
input
.
type
,
tensor
.
TensorType
)
and
input
.
ndim
==
0
and
'int'
in
input
.
dtype
):
not
move_to_gpu
(
input
)
):
continue
continue
try
:
try
:
...
@@ -301,9 +300,7 @@ class GraphToGPU(Optimizer):
...
@@ -301,9 +300,7 @@ class GraphToGPU(Optimizer):
target
=
infer_context_name
(
*
fgraph
.
inputs
)
target
=
infer_context_name
(
*
fgraph
.
inputs
)
for
i
in
fgraph
.
inputs
:
for
i
in
fgraph
.
inputs
:
# Do not move *int* scalar to the GPU.
# Do not move *int* scalar to the GPU.
if
(
isinstance
(
i
.
type
,
tensor
.
TensorType
)
and
if
isinstance
(
i
.
type
,
tensor
.
TensorType
)
and
move_to_gpu
(
i
):
(
i
.
ndim
>
0
or
'int'
not
in
i
.
dtype
)
and
"complex"
not
in
i
.
dtype
):
mapping
[
i
]
=
i
.
transfer
(
getattr
(
i
.
tag
,
'target'
,
target
))
mapping
[
i
]
=
i
.
transfer
(
getattr
(
i
.
tag
,
'target'
,
target
))
else
:
else
:
mapping
[
i
]
=
i
mapping
[
i
]
=
i
...
...
theano/gpuarray/type.py
浏览文件 @
a51c01ea
...
@@ -22,6 +22,26 @@ except ImportError:
...
@@ -22,6 +22,26 @@ except ImportError:
_context_reg
=
{}
_context_reg
=
{}
def
move_to_gpu
(
data
):
"""
Do we want to move this computation to the GPU?
Currently, we don't move complex and scalar int.
Parameters
----------
data : numpy.ndarray or TensorVariable
(it must have dtype and ndim parameter)
"""
# We don't support complex on the GPU
if
str
(
data
.
dtype
)
in
tensor
.
basic
.
complex_dtypes
:
return
False
# We don't want scalar int on the GPU.
if
data
.
ndim
==
0
and
str
(
data
.
dtype
)
in
tensor
.
basic
.
discrete_dtypes
:
return
False
return
True
class
ContextNotDefined
(
ValueError
):
class
ContextNotDefined
(
ValueError
):
pass
pass
...
@@ -572,6 +592,8 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
...
@@ -572,6 +592,8 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
See :func:`theano.shared`.
See :func:`theano.shared`.
"""
"""
if
target
is
None
and
not
move_to_gpu
(
value
):
raise
TypeError
(
'We do not move that data by deault to the GPU'
)
if
target
==
'gpu'
or
target
==
'cpu'
:
if
target
==
'gpu'
or
target
==
'cpu'
:
raise
TypeError
(
'not for me'
)
raise
TypeError
(
'not for me'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论