Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f60bc234
提交
f60bc234
authored
2月 13, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for strides in GpuGemm
上级
b9b760e8
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
108 行增加
和
0 行删除
+108
-0
test_blas.py
theano/sandbox/cuda/tests/test_blas.py
+108
-0
没有找到文件。
theano/sandbox/cuda/tests/test_blas.py
浏览文件 @
f60bc234
...
...
@@ -167,6 +167,114 @@ def test_gemm_no_inplace():
cmp
((
0
,
0
),(
0
,
0
))
def
test_gemm_strides
():
def
cmp
(
a_shp
,
b_shp
,
c_shp
):
av
=
my_rand
(
*
a_shp
)
bv
=
my_rand
(
*
b_shp
)
cv
=
my_rand
(
*
c_shp
)
l
=
numpy
.
float32
(
0.2
)
a
=
tcn
.
shared_constructor
(
av
,
'a'
)
b
=
tcn
.
shared_constructor
(
bv
,
'b'
)
c
=
tcn
.
shared_constructor
(
cv
,
'c'
)
a_t
=
tcn
.
shared_constructor
(
av
.
T
,
'a.T'
)
b_t
=
tcn
.
shared_constructor
(
bv
.
T
,
'b.T'
)
c_t
=
tcn
.
shared_constructor
(
cv
.
T
,
'c.T'
)
a_gpu
=
a
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
b_gpu
=
b
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
c_gpu
=
c
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
bt_gpu
=
b_t
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
ct_gpu
=
c_t
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
f_nnn
=
pfunc
([],
[],
updates
=
{
a
:
(
l
*
a
+
tensor
.
dot
(
b
,
c
))},
mode
=
mode_with_gpu
)
f_nnt
=
pfunc
([],
[],
updates
=
{
a
:
(
l
*
a
+
tensor
.
dot
(
b
,
c_t
.
T
))},
mode
=
mode_with_gpu
)
f_ntn
=
pfunc
([],
[],
updates
=
{
a
:
(
l
*
a
+
tensor
.
dot
(
b_t
.
T
,
c
))},
mode
=
mode_with_gpu
)
f_ntt
=
pfunc
([],
[],
updates
=
{
a
:
(
l
*
a
+
tensor
.
dot
(
b_t
.
T
,
c_t
.
T
))},
mode
=
mode_with_gpu
)
f_tnn
=
pfunc
([],
[],
updates
=
{
a_t
:
(
l
*
a_t
+
tensor
.
dot
(
b
,
c
)
.
T
)},
mode
=
mode_with_gpu
)
f_tnt
=
pfunc
([],
[],
updates
=
{
a_t
:
(
l
*
a_t
+
tensor
.
dot
(
b
,
c_t
.
T
)
.
T
)},
mode
=
mode_with_gpu
)
f_ttn
=
pfunc
([],
[],
updates
=
{
a_t
:
(
l
*
a_t
+
tensor
.
dot
(
b_t
.
T
,
c
)
.
T
)},
mode
=
mode_with_gpu
)
f_ttt
=
pfunc
([],
[],
updates
=
{
a_t
:
(
l
*
a_t
+
tensor
.
dot
(
b_t
.
T
,
c_t
.
T
)
.
T
)},
mode
=
mode_with_gpu
)
# Try with all stride patterns, and all transposed pattern
for
steps
in
itertools
.
product
((
-
1
,
1
),
repeat
=
6
):
a_step1
,
a_step2
,
b_step1
,
b_step2
,
c_step1
,
c_step2
=
steps
b
.
set_value
(
b_gpu
.
copy
()[::
b_step1
,
::
b_step2
],
borrow
=
True
)
c
.
set_value
(
c_gpu
.
copy
()[::
c_step1
,
::
c_step2
],
borrow
=
True
)
b_t
.
set_value
(
bt_gpu
.
copy
()[::
b_step2
,
::
b_step1
],
borrow
=
True
)
c_t
.
set_value
(
ct_gpu
.
copy
()[::
c_step2
,
::
c_step1
],
borrow
=
True
)
# Numpy results
a_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
+
numpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
]))
at_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
.
T
+
numpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
])
.
T
)
# a's value is updated, so we need to reinitialize it each time
a
.
set_value
(
a_gpu
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_nnn
()
assert
numpy
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_gpu
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_nnt
()
assert
numpy
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_gpu
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_ntn
()
assert
numpy
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_gpu
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_ntt
()
assert
numpy
.
allclose
(
a
.
get_value
(),
a_n
)
a_t
.
set_value
(
transpose
(
a_gpu
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
f_tnn
()
assert
numpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_gpu
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
f_tnt
()
assert
numpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_gpu
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
f_ttn
()
assert
numpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_gpu
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
f_ttt
()
assert
numpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
cmp
((
3
,
5
),
(
3
,
4
),
(
4
,
5
))
cmp
((
1
,
5
),
(
1
,
4
),
(
4
,
5
))
cmp
((
3
,
1
),
(
3
,
4
),
(
4
,
1
))
cmp
((
3
,
1
),
(
3
,
1
),
(
1
,
1
))
cmp
((
1
,
1
),
(
1
,
4
),
(
4
,
1
))
cmp
((
3
,
5
),
(
3
,
1
),
(
1
,
5
))
cmp
((
0
,
5
),
(
0
,
4
),
(
4
,
5
))
cmp
((
0
,
1
),
(
0
,
4
),
(
4
,
1
))
cmp
((
0
,
5
),
(
0
,
1
),
(
1
,
5
))
cmp
((
3
,
0
),
(
3
,
4
),
(
4
,
0
))
cmp
((
3
,
5
),
(
3
,
0
),
(
0
,
5
))
cmp
((
0
,
0
),
(
0
,
4
),
(
4
,
0
))
cmp
((
0
,
0
),
(
0
,
0
),
(
0
,
0
))
def
test_ger_strides
():
def
cmp
(
a_shp
,
b_shp
,
c_shp
):
av
=
my_rand
(
*
a_shp
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论