Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c8f8dba5
提交
c8f8dba5
authored
1月 26, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #392 from lamblin/fix_cuda_blas_tests
Update tests, gpu_gemv is used now, not gemm/dot22
上级
0186901e
13a9631f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
88 行增加
和
109 行删除
+88
-109
test_blas.py
theano/sandbox/cuda/tests/test_blas.py
+88
-0
test_vector_matrix_dot.py
theano/sandbox/cuda/tests/test_vector_matrix_dot.py
+0
-109
没有找到文件。
theano/sandbox/cuda/tests/test_blas.py
浏览文件 @
c8f8dba5
...
...
@@ -261,6 +261,94 @@ class TestGpuGemv(TestCase, BaseGemv,
gemv_inplace
=
gpu_gemv_inplace
class
TestVectorMatrixDot
(
TestCase
):
### Tolerance factor used in this tests
atol
=
1e-6
##########################
def
test_dot_vm
(
self
):
''' Test vector dot matrix '''
v
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
),
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
,
5
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
tcn
.
gpu_from_host
(
theano
.
dot
(
v
,
m
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
self
.
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
self
.
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()
])
==
1
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()
])
==
1
def
test_dot_mv
(
self
):
''' Test matrix dot vector '''
v
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
),
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
tcn
.
gpu_from_host
(
theano
.
dot
(
m
,
v
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
self
.
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
self
.
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()
])
==
1
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()
])
==
1
def
test_gemv1
(
self
):
''' test vector1+dot(matrix,vector2) '''
v1
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
)
,
dtype
=
'float32'
))
v2
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
)
,
dtype
=
'float32'
))
m
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
tcn
.
gpu_from_host
(
v2
+
theano
.
dot
(
m
,
v1
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
self
.
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
self
.
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()])
==
1
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()])
==
1
def
test_gemv2
(
self
):
''' test vector1+dot(vector2,matrix) '''
v1
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
)
,
dtype
=
'float32'
))
v2
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
)
,
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
tcn
.
gpu_from_host
(
v2
+
theano
.
dot
(
v1
,
m
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
self
.
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
self
.
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()])
==
1
assert
sum
([
node
.
op
is
gpu_gemv_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()])
==
1
class
TestGpuGer
(
TestGer
):
def
setUp
(
self
):
self
.
mode
=
mode_with_gpu
...
...
theano/sandbox/cuda/tests/test_vector_matrix_dot.py
deleted
100644 → 0
浏览文件 @
0186901e
import
numpy
import
theano
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda.blas
as
blasop
### Tolerance factor used in this tests !!!
atol
=
1e-6
##########################
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
def
test_dot_vm
():
''' Test vector dot matrix '''
v
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
),
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
,
5
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
cuda
.
gpu_from_host
(
theano
.
dot
(
v
,
m
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
isinstance
(
node
.
op
,
blasop
.
GpuDot22
)
for
node
in
gpu_f
.
maker
.
env
.
toposort
()
])
==
1
assert
sum
([
isinstance
(
node
.
op
,
blasop
.
GpuDot22
)
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()
])
==
1
def
test_dot_mv
():
''' Test matrix dot vector '''
v
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
),
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
cuda
.
gpu_from_host
(
theano
.
dot
(
m
,
v
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
isinstance
(
node
.
op
,
blasop
.
GpuDot22
)
for
node
in
gpu_f
.
maker
.
env
.
toposort
()
])
==
1
assert
sum
([
isinstance
(
node
.
op
,
blasop
.
GpuDot22
)
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()
])
==
1
def
test_gemv1
():
''' test vector1+dot(matrix,vector2) '''
v1
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
)
,
dtype
=
'float32'
))
v2
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
)
,
dtype
=
'float32'
))
m
=
theano
.
tensor
.
_shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
cuda
.
gpu_from_host
(
v2
+
theano
.
dot
(
m
,
v1
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
cuda
.
blas
.
gpu_gemm_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()])
==
1
assert
sum
([
node
.
op
is
cuda
.
blas
.
gpu_gemm_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()])
==
1
def
test_gemv2
():
''' test vector1+dot(vector2,matrix) '''
v1
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
)
,
dtype
=
'float32'
))
v2
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
2
)
,
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
numpy
.
random
.
rand
(
5
,
2
),
dtype
=
'float32'
))
no_gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_without_gpu
)
gpu_f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_with_gpu
)
#gpu_f2 is needed to test the case when the input is not on the gpu
#but the output is moved to the gpu.
gpu_f2
=
theano
.
function
([],
cuda
.
gpu_from_host
(
v2
+
theano
.
dot
(
v1
,
m
)),
mode
=
mode_with_gpu
)
# Assert they produce the same output
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f
(),
atol
=
atol
)
assert
numpy
.
allclose
(
no_gpu_f
(),
gpu_f2
(),
atol
=
atol
)
# Assert that the gpu version actually uses gpu
assert
sum
([
node
.
op
is
cuda
.
blas
.
gpu_gemm_inplace
for
node
in
gpu_f2
.
maker
.
env
.
toposort
()])
==
1
assert
sum
([
node
.
op
is
cuda
.
blas
.
gpu_gemm_inplace
for
node
in
gpu_f
.
maker
.
env
.
toposort
()])
==
1
if
__name__
==
'__main__'
:
test_dot_vm
()
test_dot_mv
()
test_gemv1
()
test_gemv2
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论