Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a2fe5c5d
提交
a2fe5c5d
authored
3月 03, 2015
作者:
Caglar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
used ls again.
上级
c4bcd45e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
25 行删除
+32
-25
cula.py
theano/sandbox/cuda/cula.py
+30
-24
test_cula.py
theano/sandbox/cuda/tests/test_cula.py
+2
-1
没有找到文件。
theano/sandbox/cuda/cula.py
浏览文件 @
a2fe5c5d
...
@@ -19,6 +19,7 @@ if cula is not None:
...
@@ -19,6 +19,7 @@ if cula is not None:
import
numpy
import
numpy
class
GpuSolve
(
GpuOp
):
class
GpuSolve
(
GpuOp
):
"""
"""
CULA GPU solver OP.
CULA GPU solver OP.
...
@@ -55,53 +56,58 @@ class GpuSolve(GpuOp):
...
@@ -55,53 +56,58 @@ class GpuSolve(GpuOp):
def
thunk
():
def
thunk
():
input_shape
=
inputs
[
1
][
0
]
.
shape
input_shape
=
inputs
[
1
][
0
]
.
shape
#size of the matrices to invert
#size of the matrices to invert
z
=
outputs
[
0
]
z
=
outputs
[
0
]
#Matrix
#Matrix
A
=
inputs
[
0
][
0
]
A
=
inputs
[
0
][
0
]
#Solution vectors
#Solution vectors
b
=
inputs
[
1
][
0
]
b
=
inputs
[
1
][
0
]
A_cpy
=
A
.
copy
()
b_cpy
=
b
.
copy
()
A_pycuda
=
to_gpuarray
(
A_cpy
)
#A_cpy = A.copy()
b_pycuda
=
to_gpuarray
(
b_cpy
)
#b_cpy = b.copy()
A_pycuda
=
to_gpuarray
(
A
)
b_pycuda
=
to_gpuarray
(
b
)
def
cula_gpu_solve
(
A
,
b
):
def
cula_gpu_solve
(
A
,
b
,
trans
=
'N'
):
A_shape
=
A
.
shape
A_shape
=
A
.
shape
b_shape
=
b
.
shape
b_shape
=
b
.
shape
assert
(
len
(
A_shape
)
==
2
)
assert
(
len
(
A_shape
)
==
2
)
assert
(
len
(
b_shape
)
==
2
)
assert
(
len
(
b_shape
)
==
2
)
import
string
if
A_shape
[
0
]
!=
A_shape
[
1
]:
if
trans
in
[
'T'
,
'C'
]:
raise
ValueError
(
'Coefficient matrix should be a square matrix.'
)
l
,
n
=
A_shape
k
,
m
=
b_shape
elif
trans
in
[
'N'
]:
n
,
l
=
A_shape
k
,
m
=
b_shape
else
:
raise
ValueError
(
'Invalid value for trans'
)
n
=
A_shape
[
0
]
if
n
!=
k
:
nrhs
=
b_shape
[
1
]
raise
ValueError
(
'A and b must be aligned.'
)
#Create the integer pivot vector to store the indices for
#permutation matrix.
ipiv
=
CudaNdarray
.
zeros
((
n
,))
ipiv
=
to_gpuarray
(
ipiv
)
import
string
if
trans
==
'N'
:
lda
=
max
(
1
,
n
)
lda
=
max
(
1
,
n
)
ldb
=
max
(
1
,
n
)
else
:
lda
=
max
(
1
,
l
)
ldb
=
max
(
1
,
k
)
# construct pointer arrays needed for culaDeviceSgels
# construct pointer arrays needed for culaDeviceSgels
# Cula requires you to pass a pointer for A and b.
# Cula requires you to pass a pointer for A and b.
A_ptr
=
A_cpy
.
gpudata
A_ptr
=
A
.
gpudata
b_ptr
=
b_cpy
.
gpudata
b_ptr
=
b
.
gpudata
ipiv_ptr
=
ipiv
.
gpudata
cula
.
culaDeviceSge
sv
(
n
,
nrhs
,
A_ptr
,
lda
,
ipiv_ptr
,
b_ptr
,
ldb
)
cula
.
culaDeviceSge
ls
(
trans
,
n
,
l
,
m
,
A_ptr
,
lda
,
b_ptr
,
ldb
)
return
A
,
b
return
A
,
b
A_pycuda
,
b_pycuda
=
cula_gpu_solve
(
A_pycuda
,
b_pycuda
)
A_pycuda
,
b_pycuda
=
cula_gpu_solve
(
A_pycuda
,
b_pycuda
,
self
.
trans
)
z
[
0
]
=
b
z
[
0
]
=
b
thunk
.
inputs
=
inputs
thunk
.
inputs
=
inputs
...
@@ -110,4 +116,4 @@ class GpuSolve(GpuOp):
...
@@ -110,4 +116,4 @@ class GpuSolve(GpuOp):
return
thunk
return
thunk
gpu_solve
=
GpuSolve
()
gpu_solve
=
GpuSolve
(
trans
=
"T"
)
theano/sandbox/cuda/tests/test_cula.py
浏览文件 @
a2fe5c5d
...
@@ -52,7 +52,8 @@ class TestCula(unittest.TestCase):
...
@@ -52,7 +52,8 @@ class TestCula(unittest.TestCase):
def
test_orth_solve
(
self
):
def
test_orth_solve
(
self
):
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_orth
=
numpy
.
linalg
.
svd
(
A_val
)[
0
]
A_orth
=
numpy
.
linalg
.
svd
(
A_val
)[
0
]
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_orth
.
shape
[
1
],
A_orth
.
shape
[
0
]))
.
astype
(
"float32"
)
#import ipdb; ipdb.set_trace()
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_orth
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_orth
,
x_val
)
self
.
run_gpu_solve
(
A_orth
,
x_val
)
def
test_uni_rand_solve
(
self
):
def
test_uni_rand_solve
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论