Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90cd2169
提交
90cd2169
authored
11月 30, 2016
作者:
Thomas George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implementation cusolver solve general case + tests
上级
b8f3b638
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
36 行增加
和
32 行删除
+36
-32
linalg.py
theano/gpuarray/linalg.py
+20
-14
__init__.py
theano/gpuarray/linalg/__init__.py
+0
-0
test_linalg.py
theano/gpuarray/tests/test_linalg.py
+16
-18
没有找到文件。
theano/gpuarray/linalg
/solve
.py
→
theano/gpuarray/linalg.py
浏览文件 @
90cd2169
...
...
@@ -10,7 +10,7 @@ from pygpu import gpuarray
cusolver_available
=
False
try
:
from
s
cikits.
cuda
import
cusolver
from
s
k
cuda
import
cusolver
cusolver_available
=
True
except
(
ImportError
,
OSError
,
RuntimeError
,
pkg_resources
.
DistributionNotFound
):
pass
...
...
@@ -30,8 +30,11 @@ class GpuCusolverSolve(Op):
__props__
=
(
'trans'
,)
def
__init__
(
self
,
trans
=
'N'
):
def
__init__
(
self
,
trans
=
'N'
,
inplace
=
False
):
self
.
trans
=
trans
self
.
inplace
=
inplace
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
,
1
]}
super
(
GpuCusolverSolve
,
self
)
.
__init__
()
def
make_node
(
self
,
inp1
,
inp2
):
...
...
@@ -52,7 +55,7 @@ class GpuCusolverSolve(Op):
return
theano
.
Apply
(
self
,
[
inp1
,
inp2
],
[
GpuArrayType
(
'float32'
,
broadcastable
=
[
False
]
*
inp1
.
ndim
,
broadcastable
=
inp1
.
broadcastable
,
context_name
=
self
.
context
)()])
def
make_thunk
(
self
,
...
...
@@ -86,14 +89,12 @@ class GpuCusolverSolve(Op):
assert
(
len
(
A
.
shape
)
==
2
)
assert
(
len
(
b
.
shape
)
==
2
)
# A is not explicitly converted between C and F order, instead we
# switch the "transpose" flag.
if
self
.
trans
in
[
'T'
,
'C'
]:
trans
=
0
trans
=
1
l
,
n
=
A
.
shape
k
,
m
=
b
.
shape
elif
self
.
trans
==
'N'
:
trans
=
1
trans
=
0
n
,
l
=
A
.
shape
k
,
m
=
b
.
shape
else
:
...
...
@@ -106,13 +107,18 @@ class GpuCusolverSolve(Op):
lda
=
max
(
1
,
n
)
ldb
=
max
(
1
,
k
,
m
)
if
trans
==
0
:
A
=
gpuarray
.
asfortranarray
(
A
)
trans
=
1
# We copy A and b as cusolver operates inplace
if
not
self
.
inplace
:
A
=
gpuarray
.
array
(
A
,
copy
=
True
)
b
=
gpuarray
.
array
(
b
,
copy
=
True
,
order
=
'F'
)
A_ptr
=
A
.
gpudata
# We copy b as cusolver operates inplace
b_cpy
=
gpuarray
.
array
(
b
,
copy
=
True
,
order
=
'F'
)
b_ptr
=
b_cpy
.
gpudata
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
(
cusolver_handle
,
n
,
n
,
A_ptr
,
lda
)
...
...
@@ -145,7 +151,7 @@ class GpuCusolverSolve(Op):
cusolver_handle
,
trans
,
n
,
m
,
A_ptr
,
lda
,
pivots_ptr
,
b_ptr
,
ldb
,
dev_info_ptr
)
z
[
0
]
=
b
_cpy
z
[
0
]
=
b
thunk
.
inputs
=
inputs
thunk
.
outputs
=
outputs
...
...
theano/gpuarray/linalg/__init__.py
deleted
100644 → 0
浏览文件 @
b8f3b638
theano/
sandbox/cuda/tests/test_cusolver
.py
→
theano/
gpuarray/tests/test_linalg
.py
浏览文件 @
90cd2169
...
...
@@ -5,36 +5,27 @@ import numpy
import
theano
from
theano.tests
import
unittest_tools
as
utt
from
.config
import
mode_with_gpu
# Skip tests if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
import
theano.sandbox.cuda
as
cuda_ndarray
from
theano.misc.pycuda_init
import
pycuda_available
from
theano.sandbox.cuda.cusolver
import
cusolver_available
from
theano.gpuarray.linalg
import
(
cusolver_available
,
gpu_solve
)
from
theano.sandbox.cuda
import
cusolver
if
not
cuda_ndarray
.
cuda_available
:
raise
SkipTest
(
'Optional package cuda not available'
)
if
not
pycuda_available
:
raise
SkipTest
(
'Optional package pycuda not available'
)
if
not
cusolver_available
:
raise
SkipTest
(
'Optional package scikits.cuda.cusolver not available'
)
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
class
TestCusolver
(
unittest
.
TestCase
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
):
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
def
run_gpu_solve
(
self
,
A_val
,
x_val
,
trans
=
'N'
):
if
trans
==
'N'
:
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
else
:
b_val
=
numpy
.
dot
(
A_val
.
T
,
x_val
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
solver
=
cusolver
.
gpu_solve
(
A
,
b
)
fn
=
theano
.
function
([
A
,
b
],
[
solver
])
solver
=
gpu_solve
(
A
,
b
,
trans
)
fn
=
theano
.
function
([
A
,
b
],
[
solver
]
,
mode
=
mode_with_gpu
)
res
=
fn
(
A_val
,
b_val
)
x_res
=
numpy
.
array
(
res
[
0
])
utt
.
assert_allclose
(
x_res
,
x_val
)
...
...
@@ -69,3 +60,10 @@ class TestCusolver(unittest.TestCase):
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_uni_rand_solve_transpose
(
self
):
numpy
.
random
.
seed
(
1
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
,
trans
=
'T'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论