Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c9bf24bf
提交
c9bf24bf
authored
5月 05, 2015
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2791 from caglar/gpu_opt_transfer
Assert no CPU op for #2471
上级
740d8fc7
fbc08c46
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
62 行增加
和
0 行删除
+62
-0
configdefaults.py
theano/configdefaults.py
+9
-0
opt.py
theano/sandbox/cuda/opt.py
+23
-0
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+30
-0
没有找到文件。
theano/configdefaults.py
浏览文件 @
c9bf24bf
...
@@ -126,6 +126,15 @@ AddConfigVar(
...
@@ -126,6 +126,15 @@ AddConfigVar(
in_c_key
=
False
)
in_c_key
=
False
)
# This flag determines whether or not to raise error/warning message if
# there is a CPU Op in the computational graph.
AddConfigVar
(
'assert_no_cpu_op'
,
"Raise an error/warning if there is a CPU op in the computational graph."
,
EnumStr
(
'ignore'
,
'warn'
,
'raise'
,
'pdb'
,
allow_override
=
True
),
in_c_key
=
False
)
# Do not add FAST_RUN_NOGC to this list (nor any other ALL CAPS shortcut).
# Do not add FAST_RUN_NOGC to this list (nor any other ALL CAPS shortcut).
# The way to get FAST_RUN_NOGC is with the flag 'linker=c|py_nogc'.
# The way to get FAST_RUN_NOGC is with the flag 'linker=c|py_nogc'.
# The old all capital letter way of working is deprecated as it is not
# The old all capital letter way of working is deprecated as it is not
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
c9bf24bf
...
@@ -5,6 +5,7 @@ import copy
...
@@ -5,6 +5,7 @@ import copy
import
sys
import
sys
import
time
import
time
import
warnings
import
warnings
import
pdb
import
numpy
import
numpy
...
@@ -445,6 +446,27 @@ def local_gpu_dot_to_dot22(node):
...
@@ -445,6 +446,27 @@ def local_gpu_dot_to_dot22(node):
shape_out
))]
shape_out
))]
return
False
return
False
@local_optimizer
(
None
)
def
local_assert_no_cpu_op
(
node
):
if
not
isinstance
(
node
.
op
,
GpuOp
)
and
all
([
var
.
owner
and
isinstance
(
var
.
owner
.
op
,
HostFromGpu
)
for
var
in
node
.
inputs
])
and
any
([[
c
for
c
in
var
.
clients
if
isinstance
(
c
[
0
]
.
op
,
GpuFromHost
)]
for
var
in
node
.
outputs
]):
if
config
.
assert_no_cpu_op
==
"warn"
:
_logger
.
warning
((
"CPU op
%
s is detected in the computational"
" graph"
)
%
node
)
elif
config
.
assert_no_cpu_op
==
"raise"
:
raise
AssertionError
(
"The op
%
s is on CPU."
%
node
)
elif
config
.
assert_no_cpu_op
==
"pdb"
:
pdb
.
set_trace
()
return
None
# Register the local_assert_no_cpu_op:
assert_no_cpu_op
=
theano
.
tensor
.
opt
.
in2out
(
local_assert_no_cpu_op
,
name
=
'assert_no_cpu_op'
)
# 49.2 is after device specialization & fusion optimizations for last transfers
theano
.
compile
.
optdb
.
register
(
'assert_no_cpu_op'
,
assert_no_cpu_op
,
49.2
)
@register_opt
()
@register_opt
()
@local_optimizer
([
theano
.
ifelse
.
IfElse
,
gpu_from_host
])
@local_optimizer
([
theano
.
ifelse
.
IfElse
,
gpu_from_host
])
...
@@ -1915,6 +1937,7 @@ gpu_inplace_elemwise_optimizer = tensor.opt.inplace_elemwise_optimizer_op(
...
@@ -1915,6 +1937,7 @@ gpu_inplace_elemwise_optimizer = tensor.opt.inplace_elemwise_optimizer_op(
optdb
.
register
(
'gpu_inplace_elemwise_opt'
,
gpu_inplace_elemwise_optimizer
,
75
,
optdb
.
register
(
'gpu_inplace_elemwise_opt'
,
gpu_inplace_elemwise_optimizer
,
75
,
'fast_run'
,
'inplace'
,
'gpu_inplace'
)
'fast_run'
,
'inplace'
,
'gpu_inplace'
)
register_opt
()(
tensor
.
opt
.
local_remove_useless_assert
)
register_opt
()(
tensor
.
opt
.
local_remove_useless_assert
)
register_opt
()(
tensor
.
opt
.
local_shape_to_shape_i
)
register_opt
()(
tensor
.
opt
.
local_shape_to_shape_i
)
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
c9bf24bf
...
@@ -5,6 +5,7 @@ import unittest
...
@@ -5,6 +5,7 @@ import unittest
import
numpy
import
numpy
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
import
theano
import
theano
from
theano.compile.pfunc
import
pfunc
from
theano.compile.pfunc
import
pfunc
...
@@ -91,6 +92,35 @@ def test_local_gpu_contiguous_gpu_contiguous():
...
@@ -91,6 +92,35 @@ def test_local_gpu_contiguous_gpu_contiguous():
if
isinstance
(
node
.
op
,
basic_ops
.
GpuContiguous
)])
if
isinstance
(
node
.
op
,
basic_ops
.
GpuContiguous
)])
def
test_local_assert_no_cpu_op
():
numpy
.
random
.
seed
(
1
)
m
=
numpy
.
random
.
uniform
(
-
1
,
1
,
(
10
,
10
))
.
astype
(
"float32"
)
ms
=
cuda
.
shared_constructor
(
m
,
name
=
"m_shared"
)
out
=
theano
.
tensor
.
tanh
(
ms
)
.
dot
(
ms
.
T
)
mode_local_assert
=
mode_with_gpu
.
including
(
"assert_no_cpu_op"
)
mode_local_assert
=
mode_local_assert
.
excluding
(
"local_gpu_elemwise_0"
)
mode_local_assert
=
mode_local_assert
.
excluding
(
"local_gpu_elemwise_1"
)
old
=
config
.
assert_no_cpu_op
# If the flag is raise
try
:
config
.
assert_no_cpu_op
=
'raise'
assert_raises
(
AssertionError
,
theano
.
function
,
[],
out
,
mode
=
mode_local_assert
)
finally
:
config
.
assert_no_cpu_op
=
old
# If the flag is ignore
try
:
config
.
assert_no_cpu_op
=
'ignore'
theano
.
function
([],
out
,
mode
=
mode_local_assert
)
finally
:
config
.
assert_no_cpu_op
=
old
def
test_int_pow
():
def
test_int_pow
():
a
=
CudaNdarrayType
([
False
])()
a
=
CudaNdarrayType
([
False
])()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论