Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
91835cc8
提交
91835cc8
authored
4月 27, 2017
作者:
notoraptor
提交者:
GitHub
4月 27, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5895 from tfjgeorge/gpu_solve_inplace
Added an optimization for inplace gpu_cusolver_solve and tests
上级
ca213aa4
ab5904a4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
38 行增加
和
4 行删除
+38
-4
linalg.py
theano/gpuarray/linalg.py
+7
-1
opt.py
theano/gpuarray/opt.py
+13
-2
test_opt.py
theano/gpuarray/tests/test_opt.py
+18
-1
没有找到文件。
theano/gpuarray/linalg.py
浏览文件 @
91835cc8
...
...
@@ -60,6 +60,11 @@ def attach_cusolver_handle_to_context(ctx):
with
ctx
:
ctx
.
cusolver_handle
=
cusolver
.
cusolverDnCreate
()
# it is a subset of all cases available in slinalg's MATRIX_STRUCTURE
MATRIX_STRUCTURES_SOLVE
=
(
'general'
,
'symmetric'
)
class
GpuCusolverSolve
(
Op
):
"""
...
...
@@ -79,7 +84,8 @@ class GpuCusolverSolve(Op):
self
.
inplace
=
inplace
self
.
A_structure
=
A_structure
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
,
1
]}
self
.
destroy_map
=
{
0
:
[
0
]}
assert
A_structure
in
MATRIX_STRUCTURES_SOLVE
super
(
GpuCusolverSolve
,
self
)
.
__init__
()
def
make_node
(
self
,
inp1
,
inp2
):
...
...
theano/gpuarray/opt.py
浏览文件 @
91835cc8
...
...
@@ -70,7 +70,8 @@ from .subtensor import (GpuIncSubtensor, GpuSubtensor,
GpuAdvancedIncSubtensor1_dev20
)
from
.opt_util
import
alpha_merge
,
output_merge
,
pad_dims
,
unpad_dims
from
.reduction
import
GpuMaxAndArgmax
from
.linalg
import
(
GpuCusolverSolve
,
GpuCholesky
,
cusolver_available
)
from
.linalg
import
(
GpuCusolverSolve
,
MATRIX_STRUCTURES_SOLVE
,
GpuCholesky
,
cusolver_available
)
_logger
=
logging
.
getLogger
(
"theano.gpuarray.opt"
)
...
...
@@ -1974,7 +1975,17 @@ def local_gpu_maxandargmax(op, context_name, inputs, outputs):
def
local_gpu_solve
(
op
,
context_name
,
inputs
,
outputs
):
if
not
cusolver_available
:
return
return
GpuCusolverSolve
()
if
op
.
A_structure
not
in
MATRIX_STRUCTURES_SOLVE
:
return
return
GpuCusolverSolve
(
A_structure
=
op
.
A_structure
)
@register_inplace
()
@local_optimizer
([
GpuCusolverSolve
],
inplace
=
True
)
def
local_inplace_gpu_solve
(
node
):
if
isinstance
(
node
.
op
,
GpuCusolverSolve
)
and
not
node
.
op
.
inplace
:
return
[
GpuCusolverSolve
(
A_structure
=
node
.
op
.
A_structure
,
trans
=
node
.
op
.
trans
,
inplace
=
True
)(
*
node
.
inputs
)]
# Cholesky decomposition
...
...
theano/gpuarray/tests/test_opt.py
浏览文件 @
91835cc8
...
...
@@ -587,13 +587,30 @@ def test_local_lift_solve():
f_gpu
=
theano
.
function
([
A
,
b
],
o
,
mode
=
mode_with_gpu
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Solve
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
assert
any
(
isinstance
(
n
.
op
,
GpuCusolverSolve
)
assert
any
(
isinstance
(
n
.
op
,
GpuCusolverSolve
)
and
n
.
op
.
inplace
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
A_val
=
np
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
b_val
=
np
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
3
))
.
astype
(
"float32"
)
utt
.
assert_allclose
(
f_cpu
(
A_val
,
b_val
),
f_gpu
(
A_val
,
b_val
))
def
test_gpu_solve_not_inplace
():
if
not
cusolver_available
:
raise
SkipTest
(
'No cuSolver'
)
A
=
tensor
.
fmatrix
()
b
=
tensor
.
fmatrix
()
s
=
slinalg
.
solve
(
A
,
b
)
o
=
tensor
.
dot
(
A
,
s
)
f_cpu
=
theano
.
function
([
A
,
b
],
o
,
mode_without_gpu
)
f_gpu
=
theano
.
function
([
A
,
b
],
o
,
mode
=
mode_with_gpu
)
count_not_inplace
=
len
([
n
.
op
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
if
isinstance
(
n
.
op
,
GpuCusolverSolve
)
and
not
n
.
op
.
inplace
])
assert
count_not_inplace
==
1
,
count_not_inplace
A_val
=
np
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
b_val
=
np
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
3
))
.
astype
(
"float32"
)
utt
.
assert_allclose
(
f_cpu
(
A_val
,
b_val
),
f_gpu
(
A_val
,
b_val
))
def
test_local_lift_cholesky
():
if
not
cusolver_available
:
raise
SkipTest
(
'No cuSolver'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论