Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cf4e0264
提交
cf4e0264
authored
4月 12, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Addressed nouiz comments.
上级
4c87b1b3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
32 行增加
和
8 行删除
+32
-8
linalg.py
theano/gpuarray/linalg.py
+4
-7
opt.py
theano/gpuarray/opt.py
+7
-0
test_opt.py
theano/gpuarray/tests/test_opt.py
+21
-1
没有找到文件。
theano/gpuarray/linalg.py
浏览文件 @
cf4e0264
...
@@ -5,7 +5,6 @@ import theano
...
@@ -5,7 +5,6 @@ import theano
import
warnings
import
warnings
from
theano
import
Op
from
theano
import
Op
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
import
numpy
as
np
import
numpy
as
np
...
@@ -254,7 +253,7 @@ class GpuCholesky(Op):
...
@@ -254,7 +253,7 @@ class GpuCholesky(Op):
warnings
.
warn
(
'The GpuSolve op requires scikit-cuda > 0.5.1 to work with CUDA 8'
)
warnings
.
warn
(
'The GpuSolve op requires scikit-cuda > 0.5.1 to work with CUDA 8'
)
if
not
pygpu_available
:
if
not
pygpu_available
:
raise
RuntimeError
(
'Missing pygpu or triu/tril functions.'
raise
RuntimeError
(
'Missing pygpu or triu/tril functions.'
'
Try updating libgpuarray?
'
)
'
Install or update libgpuarray.
'
)
context_name
=
basic_ops
.
infer_context_name
(
inp
)
context_name
=
basic_ops
.
infer_context_name
(
inp
)
inp
=
basic_ops
.
as_gpuarray_variable
(
inp
,
context_name
)
inp
=
basic_ops
.
as_gpuarray_variable
(
inp
,
context_name
)
...
@@ -262,14 +261,12 @@ class GpuCholesky(Op):
...
@@ -262,14 +261,12 @@ class GpuCholesky(Op):
inp
=
basic_ops
.
gpu_contiguous
(
inp
)
inp
=
basic_ops
.
gpu_contiguous
(
inp
)
# this op can only operate on float32 matrices
# this op can only operate on float32 matrices
# because of current implementation of triu/tril.
# TODO: support float64 for triu/tril in GpuArray and for GpuCholesky/GpuCusolverSolve in Theano.
assert
inp
.
ndim
==
2
assert
inp
.
ndim
==
2
assert
inp
.
dtype
==
'float32'
assert
inp
.
dtype
==
'float32'
return
theano
.
Apply
(
return
theano
.
Apply
(
self
,
[
inp
],
[
inp
.
type
()])
self
,
[
inp
],
[
GpuArrayType
(
'float32'
,
broadcastable
=
inp
.
broadcastable
,
context_name
=
context_name
)()])
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
ctx
=
node
.
inputs
[
0
]
.
type
.
context
ctx
=
node
.
inputs
[
0
]
.
type
.
context
...
...
theano/gpuarray/opt.py
浏览文件 @
cf4e0264
...
@@ -1977,6 +1977,13 @@ def local_gpu_cholesky(op, context_name, inputs, outputs):
...
@@ -1977,6 +1977,13 @@ def local_gpu_cholesky(op, context_name, inputs, outputs):
return
return
return
GpuCholesky
(
lower
=
op
.
lower
,
inplace
=
op
.
destructive
)
return
GpuCholesky
(
lower
=
op
.
lower
,
inplace
=
op
.
destructive
)
@register_inplace
()
@local_optimizer
([
GpuCholesky
],
inplace
=
True
)
def
local_inplace_cholesky
(
node
):
if
isinstance
(
node
.
op
,
GpuCholesky
)
and
not
node
.
op
.
inplace
:
return
[
GpuCholesky
(
lower
=
node
.
op
.
lower
,
inplace
=
True
)(
*
node
.
inputs
)]
# Do not register in fast_run or fast_compile.
# Do not register in fast_run or fast_compile.
# It will be added to fast_run if the GPU is enabled.
# It will be added to fast_run if the GPU is enabled.
optdb
.
register
(
'gpua_scanOp_make_inplace'
,
optdb
.
register
(
'gpua_scanOp_make_inplace'
,
...
...
theano/gpuarray/tests/test_opt.py
浏览文件 @
cf4e0264
...
@@ -593,7 +593,8 @@ def test_local_lift_cholesky():
...
@@ -593,7 +593,8 @@ def test_local_lift_cholesky():
f_gpu
=
theano
.
function
([
A
],
o
,
mode
=
mode_with_gpu
)
f_gpu
=
theano
.
function
([
A
],
o
,
mode
=
mode_with_gpu
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Cholesky
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Cholesky
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
assert
any
(
isinstance
(
n
.
op
,
GpuCholesky
)
# GpuCholesky op in this graph should be inplace (as his input is not reused by other op).
assert
any
(
isinstance
(
n
.
op
,
GpuCholesky
)
and
n
.
op
.
inplace
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
M_val
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
M_val
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
# A = M.dot(M) will be positive definite for all non-singular M
# A = M.dot(M) will be positive definite for all non-singular M
...
@@ -601,6 +602,25 @@ def test_local_lift_cholesky():
...
@@ -601,6 +602,25 @@ def test_local_lift_cholesky():
utt
.
assert_allclose
(
f_cpu
(
A_val
),
f_gpu
(
A_val
))
utt
.
assert_allclose
(
f_cpu
(
A_val
),
f_gpu
(
A_val
))
def
test_gpu_cholesky_not_inplace
():
if
not
cusolver_available
:
raise
SkipTest
(
'No cuSolver'
)
A
=
tensor
.
fmatrix
()
A_squared
=
A
**
2
B
=
slinalg
.
cholesky
(
A_squared
)
D
=
B
+
A_squared
f_cpu
=
theano
.
function
([
A
],
D
,
mode
=
mode_without_gpu
)
f_gpu
=
theano
.
function
([
A
],
D
,
mode
=
mode_with_gpu
)
# GpuCholesky op in this graph should NOT be inplace (as his input is reused in another op)
count_cholesky_not_inplace
=
len
([
n
.
op
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
if
isinstance
(
n
.
op
,
GpuCholesky
)
and
not
n
.
op
.
inplace
])
assert
count_cholesky_not_inplace
==
1
,
count_cholesky_not_inplace
M_val
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
# A = M.dot(M) will be positive definite for all non-singular M
A_val
=
M_val
.
dot
(
M_val
.
T
)
utt
.
assert_allclose
(
f_cpu
(
A_val
),
f_gpu
(
A_val
))
def
test_local_gpua_advanced_incsubtensor
():
def
test_local_gpua_advanced_incsubtensor
():
# test a corner case reported at gh-5589
# test a corner case reported at gh-5589
target
=
tensor
.
ftensor4
()
target
=
tensor
.
ftensor4
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论