Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dfd1c614
提交
dfd1c614
authored
12月 22, 2011
作者:
James Bergstra
提交者:
Frederic
1月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added late dot22->gemv optimization
上级
32fa6f2e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
8 行删除
+24
-8
blas.py
theano/tensor/blas.py
+24
-8
没有找到文件。
theano/tensor/blas.py
浏览文件 @
dfd1c614
...
@@ -43,7 +43,7 @@ GEMV: Gemv
...
@@ -43,7 +43,7 @@ GEMV: Gemv
----------
----------
The BLAS GEMV operation implements Z <- a X Y + b Z,
The BLAS GEMV operation implements Z <- a X Y + b Z,
where
Z
is a matrix, Y, and Z are vectors, and a and b are scalars.
where
X
is a matrix, Y, and Z are vectors, and a and b are scalars.
Gemv implements the GEMV call in all its generality.
Gemv implements the GEMV call in all its generality.
...
@@ -1148,7 +1148,7 @@ def _gemm_from_factored_list(lst):
...
@@ -1148,7 +1148,7 @@ def _gemm_from_factored_list(lst):
# Try every pair in the sM_list, trying to turn it into a gemm operation
# Try every pair in the sM_list, trying to turn it into a gemm operation
for
i
in
xrange
(
len
(
lst
)
-
1
):
for
i
in
xrange
(
len
(
lst
)
-
1
):
s_i
,
M_i
=
lst
[
i
]
s_i
,
M_i
=
lst
[
i
]
for
j
in
xrange
(
i
+
1
,
len
(
lst
)):
for
j
in
xrange
(
i
+
1
,
len
(
lst
)):
s_j
,
M_j
=
lst
[
j
]
s_j
,
M_j
=
lst
[
j
]
...
@@ -1414,20 +1414,36 @@ def local_gemm_to_ger(node):
...
@@ -1414,20 +1414,36 @@ def local_gemm_to_ger(node):
#TODO: delete this optimization when we have the proper dot->gemm->ger pipeline
#TODO: delete this optimization when we have the proper dot->gemm->ger pipeline
# working
# working
@local_optimizer
([
_dot22
])
@local_optimizer
([
_dot22
])
def
local_dot22_to_ger
(
node
):
def
local_dot22_to_ger
_or_gemv
(
node
):
"""
GEMM
computing an outer-product -> GER
"""
dot22
computing an outer-product -> GER
"""
"""
if
node
.
op
==
_dot22
:
if
node
.
op
==
_dot22
:
x
,
y
=
node
.
inputs
x
,
y
=
node
.
inputs
if
x
.
broadcastable
[
1
]
and
y
.
broadcastable
[
0
]:
xb
=
x
.
broadcastable
yb
=
y
.
broadcastable
one
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
1
,
dtype
=
x
.
dtype
))
zero
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
x
.
dtype
))
if
xb
[
1
]
and
yb
[
0
]:
# x and y are both vectors so this might qualifies for a GER
# x and y are both vectors so this might qualifies for a GER
xv
=
x
.
dimshuffle
(
0
)
xv
=
x
.
dimshuffle
(
0
)
yv
=
y
.
dimshuffle
(
1
)
yv
=
y
.
dimshuffle
(
1
)
one
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
1
,
dtype
=
x
.
dtype
))
zeros
=
T
.
alloc
(
numpy
.
asarray
(
0
,
dtype
=
x
.
dtype
),
x
.
shape
[
0
],
y
.
shape
[
1
])
zeros
=
T
.
alloc
(
numpy
.
asarray
(
0
,
dtype
=
x
.
dtype
),
x
.
shape
[
0
],
y
.
shape
[
1
])
rval
=
ger
(
zeros
,
one
,
xv
,
yv
)
rval
=
ger
(
zeros
,
one
,
xv
,
yv
)
return
[
rval
]
return
[
rval
]
if
xb
[
0
]
and
not
yb
[
0
]
and
not
yb
[
1
]:
# x is vector, y is matrix so try gemv
xv
=
x
.
dimshuffle
(
1
)
zeros
=
T
.
alloc
(
numpy
.
asarray
(
0
,
dtype
=
x
.
dtype
),
y
.
shape
[
1
])
rval
=
gemv_inplace
(
zeros
,
one
,
y
.
T
,
xv
,
one
)
return
[
rval
.
dimshuffle
(
'x'
,
0
)]
if
not
xb
[
0
]
and
not
xb
[
1
]
and
yb
[
1
]:
# x is matrix, y is vector, try gemv
yv
=
y
.
dimshuffle
(
0
)
zeros
=
T
.
alloc
(
numpy
.
asarray
(
0
,
dtype
=
x
.
dtype
),
x
.
shape
[
0
])
rval
=
gemv_inplace
(
zeros
,
one
,
x
,
yv
,
one
)
return
[
rval
.
dimshuffle
(
0
,
'x'
)]
#################################
#################################
#
#
...
@@ -1445,14 +1461,14 @@ optdb.register('BlasOpt', blas_optdb, 1.7, 'fast_run')
...
@@ -1445,14 +1461,14 @@ optdb.register('BlasOpt', blas_optdb, 1.7, 'fast_run')
blas_optdb
.
register
(
'local_dot_to_dot22'
,
blas_optdb
.
register
(
'local_dot_to_dot22'
,
EquilibriumOptimizer
([
local_dot_to_dot22
],
max_use_ratio
=
5
),
EquilibriumOptimizer
([
local_dot_to_dot22
],
max_use_ratio
=
5
),
0
,
'fast_run'
)
0
,
'fast_run'
)
blas_optdb
.
register
(
'
local_dot_to_gemm
'
,
blas_optdb
.
register
(
'
gemm_optimizer
'
,
GemmOptimizer
(),
GemmOptimizer
(),
10
,
'fast_run'
)
10
,
'fast_run'
)
blas_optdb
.
register
(
'local_gemm_to_gemv'
,
blas_optdb
.
register
(
'local_gemm_to_gemv'
,
EquilibriumOptimizer
([
EquilibriumOptimizer
([
local_gemm_to_gemv
,
local_gemm_to_gemv
,
local_gemm_to_ger
,
local_gemm_to_ger
,
local_dot22_to_ger
,
local_dot22_to_ger
_or_gemv
,
local_dimshuffle_lift
],
local_dimshuffle_lift
],
max_use_ratio
=
5
),
max_use_ratio
=
5
),
15
,
'fast_run'
)
15
,
'fast_run'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论