Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9895e2e2
提交
9895e2e2
authored
3月 20, 2015
作者:
Caglar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added the flake8 changes.
上级
9f36d45a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
30 行删除
+44
-30
cula.py
theano/sandbox/cuda/cula.py
+23
-22
test_cula.py
theano/sandbox/cuda/tests/test_cula.py
+15
-6
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+6
-2
没有找到文件。
theano/sandbox/cuda/cula.py
浏览文件 @
9895e2e2
import
warnings
import
theano
import
theano
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda
import
GpuOp
,
CudaNdarray
from
theano.sandbox.cuda
import
GpuOp
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
gpu_contiguous
)
from
theano.tensor
import
as_tensor_variable
from
theano.sandbox.cuda.basic_ops
import
as_cuda_ndarray_variable
from
scikits.cuda
import
cula
from
theano.sandbox.cuda
import
cuda_ndarray
cula_available
=
False
try
:
try
:
from
scikits.cuda
import
cula
from
scikits.cuda
import
cula
scikits_cuda_available
=
Tru
e
cula_available
=
Fals
e
except
ImportError
:
except
ImportError
:
scikits_cuda_available
=
False
warnings
.
warn
(
"CULA import failed in theano.sandbox.cuda.cula"
)
if
cula
is
not
None
:
cula_initialized
=
False
if
cula_available
and
cula
and
not
cula_initialized
:
try
:
cula
.
culaInitialize
()
cula
.
culaInitialize
()
cula_initialized
=
True
except
:
warnings
.
warn
(
"Initialization of cula failed."
)
import
numpy
class
GpuSolve
(
GpuOp
):
class
GpuSolve
(
GpuOp
):
"""
"""
CULA GPU solver OP.
CULA GPU solver OP.
trans: Whether to take the transpose of the input matrix or not. By default,
trans: Whether to take the transpose of the input matrix
we will take the transpose of the input matrix, before feeding it into the Op.
or not. By default, we will take the transpose of the
That is mainly, because that CULA requires inputs to be in Fortran order.
input matrix, before feeding it into the Op. That is
mainly, because that CULA requires inputs to be in Fortran
order.
"""
"""
def
__init__
(
self
,
trans
=
'T'
):
def
__init__
(
self
,
trans
=
'T'
):
self
.
trans
=
trans
self
.
trans
=
trans
...
@@ -61,21 +65,19 @@ class GpuSolve(GpuOp):
...
@@ -61,21 +65,19 @@ class GpuSolve(GpuOp):
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
def
thunk
():
def
thunk
():
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
()
A_cpy
=
A
.
copy
()
b_cpy
=
b
.
copy
()
b_cpy
=
b
.
copy
()
#Convert b to F-order from c-order.
#
Convert b to F-order from c-order.
b_cpy
=
b_cpy
.
dimshuffle
(
1
,
0
)
.
reshape
((
b
.
shape
[
0
],
b
.
shape
[
1
]))
b_cpy
=
b_cpy
.
dimshuffle
(
1
,
0
)
.
reshape
((
b
.
shape
[
0
],
b
.
shape
[
1
]))
A_pycuda
=
to_gpuarray
(
A_cpy
)
A_pycuda
=
to_gpuarray
(
A_cpy
)
...
@@ -102,7 +104,6 @@ class GpuSolve(GpuOp):
...
@@ -102,7 +104,6 @@ class GpuSolve(GpuOp):
else
:
else
:
raise
ValueError
(
'Invalid value for trans'
)
raise
ValueError
(
'Invalid value for trans'
)
lda
=
max
(
1
,
n
)
lda
=
max
(
1
,
n
)
ldb
=
max
(
1
,
n
,
l
)
ldb
=
max
(
1
,
n
,
l
)
...
@@ -116,7 +117,7 @@ class GpuSolve(GpuOp):
...
@@ -116,7 +117,7 @@ class GpuSolve(GpuOp):
A_pycuda
,
b_pycuda
=
cula_gpu_solve
(
A_pycuda
,
b_pycuda
,
self
.
trans
)
A_pycuda
,
b_pycuda
=
cula_gpu_solve
(
A_pycuda
,
b_pycuda
,
self
.
trans
)
#Convert b to F-order from c-order and assign it to output:
#
Convert b to F-order from c-order and assign it to output:
z
[
0
]
=
b_cpy
.
reshape
((
b
.
shape
[
0
],
b
.
shape
[
1
]))
.
dimshuffle
(
1
,
0
)
z
[
0
]
=
b_cpy
.
reshape
((
b
.
shape
[
0
],
b
.
shape
[
1
]))
.
dimshuffle
(
1
,
0
)
thunk
.
inputs
=
inputs
thunk
.
inputs
=
inputs
...
...
theano/sandbox/cuda/tests/test_cula.py
浏览文件 @
9895e2e2
...
@@ -24,8 +24,8 @@ if theano.config.mode == 'FAST_COMPILE':
...
@@ -24,8 +24,8 @@ if theano.config.mode == 'FAST_COMPILE':
else
:
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
class
TestCula
(
unittest
.
TestCase
):
class
TestCula
(
unittest
.
TestCase
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
):
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
...
@@ -38,23 +38,32 @@ class TestCula(unittest.TestCase):
...
@@ -38,23 +38,32 @@ class TestCula(unittest.TestCase):
utt
.
assert_allclose
(
x_res
,
x_val
)
utt
.
assert_allclose
(
x_res
,
x_val
)
def
test_diag_solve
(
self
):
def
test_diag_solve
(
self
):
A_val
=
numpy
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
dtype
=
"float32"
)
numpy
.
random
.
seed
(
1
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
A_val
=
numpy
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
dtype
=
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_sym_solve
(
self
):
def
test_sym_solve
(
self
):
numpy
.
random
.
seed
(
1
)
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_sym
=
(
A_val
+
A_val
.
T
)
/
2.0
A_sym
=
(
A_val
+
A_val
.
T
)
/
2.0
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_sym
,
x_val
)
self
.
run_gpu_solve
(
A_sym
,
x_val
)
def
test_orth_solve
(
self
):
def
test_orth_solve
(
self
):
numpy
.
random
.
seed
(
1
)
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
],
1
))
.
astype
(
"float32"
)
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
):
numpy
.
random
.
seed
(
1
)
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"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
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
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
9895e2e2
...
@@ -537,11 +537,15 @@ def test_erfinvgpu():
...
@@ -537,11 +537,15 @@ def test_erfinvgpu():
def
test_local_gpu_solve
():
def
test_local_gpu_solve
():
numpy
.
random
.
seed
(
1
)
def
cmp
(
a_shp
,
b_shp
):
def
cmp
(
a_shp
,
b_shp
):
a0
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
a_shp
)
.
astype
(
'float32'
)
a0
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
a_shp
)
.
astype
(
'float32'
)
a
=
cuda
.
shared_constructor
(
a0
,
'a'
)
a
=
cuda
.
shared_constructor
(
a0
,
'a'
)
b0
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
b_shp
)
.
astype
(
'float32'
)
b0
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
b_shp
)
.
astype
(
'float32'
)
b
=
cuda
.
shared_constructor
(
b0
,
'b'
)
b
=
cuda
.
shared_constructor
(
b0
,
'b'
)
f
=
pfunc
([],
tensor
.
slinalg
.
solve
(
a
,
b
),
mode
=
mode_with_gpu
)
f
=
pfunc
([],
tensor
.
slinalg
.
solve
(
a
,
b
),
mode
=
mode_with_gpu
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论