Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4c7b31d
提交
c4c7b31d
authored
1月 13, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix remaining problems.
上级
86be5809
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
98 行删除
+73
-98
linalg.py
theano/gpuarray/linalg.py
+73
-98
没有找到文件。
theano/gpuarray/linalg.py
浏览文件 @
c4c7b31d
...
@@ -18,8 +18,6 @@ try:
...
@@ -18,8 +18,6 @@ try:
except
(
ImportError
,
OSError
,
RuntimeError
,
pkg_resources
.
DistributionNotFound
):
except
(
ImportError
,
OSError
,
RuntimeError
,
pkg_resources
.
DistributionNotFound
):
pass
pass
cusolver_handle
=
None
class
GpuCusolverSolve
(
Op
):
class
GpuCusolverSolve
(
Op
):
"""
"""
...
@@ -32,7 +30,7 @@ class GpuCusolverSolve(Op):
...
@@ -32,7 +30,7 @@ class GpuCusolverSolve(Op):
"""
"""
__props__
=
(
'trans'
,)
__props__
=
(
'trans'
,
'inplace'
)
def
__init__
(
self
,
trans
=
'N'
,
inplace
=
False
):
def
__init__
(
self
,
trans
=
'N'
,
inplace
=
False
):
self
.
trans
=
trans
self
.
trans
=
trans
...
@@ -42,10 +40,13 @@ class GpuCusolverSolve(Op):
...
@@ -42,10 +40,13 @@ class GpuCusolverSolve(Op):
super
(
GpuCusolverSolve
,
self
)
.
__init__
()
super
(
GpuCusolverSolve
,
self
)
.
__init__
()
def
make_node
(
self
,
inp1
,
inp2
):
def
make_node
(
self
,
inp1
,
inp2
):
self
.
context
=
basic_ops
.
infer_context_name
(
inp1
,
inp2
)
if
not
cusolver_available
:
raise
RuntimeError
(
'CUSOLVER is not available and '
'GpuCusolverSolve Op can not be constructed.'
)
context_name
=
basic_ops
.
infer_context_name
(
inp1
,
inp2
)
inp1
=
basic_ops
.
as_gpuarray_variable
(
inp1
,
self
.
context
)
inp1
=
basic_ops
.
as_gpuarray_variable
(
inp1
,
context_name
)
inp2
=
basic_ops
.
as_gpuarray_variable
(
inp2
,
self
.
context
)
inp2
=
basic_ops
.
as_gpuarray_variable
(
inp2
,
context_name
)
inp1
=
basic_ops
.
gpu_contiguous
(
inp1
)
inp1
=
basic_ops
.
gpu_contiguous
(
inp1
)
inp2
=
basic_ops
.
gpu_contiguous
(
inp2
)
inp2
=
basic_ops
.
gpu_contiguous
(
inp2
)
...
@@ -62,110 +63,84 @@ class GpuCusolverSolve(Op):
...
@@ -62,110 +63,84 @@ class GpuCusolverSolve(Op):
broadcastable
=
inp1
.
broadcastable
,
broadcastable
=
inp1
.
broadcastable
,
context_name
=
self
.
context
)()])
context_name
=
self
.
context
)()])
def
make_thunk
(
self
,
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
node
,
ctx
=
node
.
inputs
[
0
]
.
type
.
context
storage_map
,
_
,
handle
=
getattr
(
ctx
,
'cusolver_handle'
,
None
)
no_recycling
=
[],
if
handle
is
None
:
impl
=
None
):
with
ctx
:
if
not
cusolver_available
:
ctx
.
cusolver_handle
=
cusolver
.
cusolverDnCreate
()
raise
RuntimeError
(
'CUSOLVER is not available and '
'GpuCusolverSolve Op can not be constructed.'
)
def
perform
(
self
,
node
,
inputs
,
outputs
):
context
=
inputs
[
0
][
0
]
.
context
inputs
=
[
storage_map
[
v
]
for
v
in
node
.
inputs
]
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
# Size of the matrices to invert.
z
=
outputs
[
0
]
global
cusolver_handle
if
cusolver_handle
is
None
:
# Matrix.
cusolver_handle
=
cusolver
.
cusolverDnCreate
()
A
=
inputs
[
0
]
def
thunk
():
# Solution vectors.
context
=
inputs
[
0
][
0
]
.
context
b
=
inputs
[
1
]
# Size of the matrices to invert.
assert
(
len
(
A
.
shape
)
==
2
)
z
=
outputs
[
0
]
assert
(
len
(
b
.
shape
)
==
2
)
# Matrix.
if
self
.
trans
in
[
'T'
,
'C'
]:
A
=
inputs
[
0
][
0
]
trans
=
1
l
,
n
=
A
.
shape
# Solution vectors.
k
,
m
=
b
.
shape
b
=
inputs
[
1
][
0
]
elif
self
.
trans
==
'N'
:
trans
=
0
assert
(
len
(
A
.
shape
)
==
2
)
n
,
l
=
A
.
shape
assert
(
len
(
b
.
shape
)
==
2
)
k
,
m
=
b
.
shape
else
:
if
self
.
trans
in
[
'T'
,
'C'
]:
raise
ValueError
(
'Invalid value for trans'
)
trans
=
1
if
l
!=
n
:
l
,
n
=
A
.
shape
raise
ValueError
(
'A must be a square matrix'
)
k
,
m
=
b
.
shape
if
n
!=
k
:
elif
self
.
trans
==
'N'
:
raise
ValueError
(
'A and b must be aligned.'
)
trans
=
0
n
,
l
=
A
.
shape
lda
=
max
(
1
,
n
)
k
,
m
=
b
.
shape
ldb
=
max
(
1
,
k
)
else
:
raise
ValueError
(
'Invalid value for trans'
)
# We copy A and b as cusolver operates inplace
if
l
!=
n
:
b
=
pygpu
.
array
(
b
,
copy
=
True
,
order
=
'F'
)
raise
ValueError
(
'A must be a square matrix'
)
if
not
self
.
inplace
:
if
n
!=
k
:
A
=
pygpu
.
array
(
A
,
copy
=
True
)
raise
ValueError
(
'A and b must be aligned.'
)
A_ptr
=
A
.
gpudata
b_ptr
=
b
.
gpudata
lda
=
max
(
1
,
n
)
ldb
=
max
(
1
,
k
)
# cusolver expects a F ordered matrix, but A is not explicitly
# converted between C and F order, instead we switch the
# We copy A and b as cusolver operates inplace
# "transpose" flag.
b
=
pygpu
.
array
(
b
,
copy
=
True
,
order
=
'F'
)
if
A
.
flags
[
'C_CONTIGUOUS'
]:
if
not
self
.
inplace
:
trans
=
1
-
trans
A
=
pygpu
.
array
(
A
,
copy
=
True
)
A_ptr
=
A
.
gpudata
with
context
:
b_ptr
=
b
.
gpudata
# cusolver expects a F ordered matrix, but A is not explicitly
# converted between C and F order, instead we switch the
# "transpose" flag.
if
A
.
flags
[
'C_CONTIGUOUS'
]:
trans
=
1
-
trans
workspace_size
=
cusolver
.
cusolverDnSgetrf_bufferSize
(
workspace_size
=
cusolver
.
cusolverDnSgetrf_bufferSize
(
cusolver_handle
,
n
,
n
,
A_ptr
,
lda
)
c
ontext
.
c
usolver_handle
,
n
,
n
,
A_ptr
,
lda
)
if
(
thunk
.
workspace
is
None
or
workspace
=
pygpu
.
zeros
(
workspace_size
,
dtype
=
'float32'
,
thunk
.
workspace
.
size
!=
workspace_size
):
context
=
context
)
thunk
.
workspace
=
pygpu
.
zeros
(
workspace_size
,
dtype
=
'float32'
,
context
=
context
)
if
thunk
.
pivots
is
None
or
thunk
.
pivots
.
size
!=
min
(
n
,
n
):
pivots
=
pygpu
.
zeros
(
n
,
dtype
=
'int32'
,
context
=
context
)
thunk
.
pivots
=
pygpu
.
zeros
(
n
,
dtype
=
'int32'
,
context
=
context
)
if
thunk
.
dev_info
is
None
:
dev_info
=
pygpu
.
zeros
((
1
,),
dtype
=
'int32'
,
context
=
context
)
thunk
.
dev_info
=
pygpu
.
zeros
((
1
,),
dtype
=
'int32'
,
context
=
context
)
workspace_ptr
=
thunk
.
workspace
.
gpudata
workspace_ptr
=
workspace
.
gpudata
pivots_ptr
=
thunk
.
pivots
.
gpudata
pivots_ptr
=
pivots
.
gpudata
dev_info_ptr
=
thunk
.
dev_info
.
gpudata
dev_info_ptr
=
dev_info
.
gpudata
with
context
:
cusolver
.
cusolverDnSgetrf
(
cusolver
.
cusolverDnSgetrf
(
cusolver_handle
,
n
,
n
,
A_ptr
,
lda
,
workspace_ptr
,
c
ontext
.
c
usolver_handle
,
n
,
n
,
A_ptr
,
lda
,
workspace_ptr
,
pivots_ptr
,
dev_info_ptr
)
pivots_ptr
,
dev_info_ptr
)
cusolver
.
cusolverDnSgetrs
(
cusolver
.
cusolverDnSgetrs
(
cusolver_handle
,
trans
,
n
,
m
,
A_ptr
,
lda
,
c
ontext
.
c
usolver_handle
,
trans
,
n
,
m
,
A_ptr
,
lda
,
pivots_ptr
,
b_ptr
,
ldb
,
dev_info_ptr
)
pivots_ptr
,
b_ptr
,
ldb
,
dev_info_ptr
)
z
[
0
]
=
b
z
[
0
]
=
b
thunk
.
inputs
=
inputs
thunk
.
outputs
=
outputs
thunk
.
lazy
=
False
thunk
.
workspace
=
None
thunk
.
pivots
=
None
thunk
.
dev_info
=
None
return
thunk
def
gpu_solve
(
A
,
b
,
trans
=
'N'
):
def
gpu_solve
(
A
,
b
,
trans
=
'N'
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论