Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
74a105e8
提交
74a105e8
authored
1月 21, 2014
作者:
AlOa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding scripts to test the speedup(slowdonw) using openmp in elemwise ops
上级
32fe7e5c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
96 行增加
和
0 行删除
+96
-0
elemwise_openmp_speedup.py
theano/misc/elemwise_openmp_speedup.py
+37
-0
elemwise_time_test.py
theano/misc/elemwise_time_test.py
+59
-0
没有找到文件。
theano/misc/elemwise_openmp_speedup.py
0 → 100644
浏览文件 @
74a105e8
import
os
import
subprocess
import
sys
def
runScript
():
script
=
'elemwise_time_test.py'
dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
proc
=
subprocess
.
Popen
([
'python'
,
script
,
'--script'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
cwd
=
dir
)
(
out
,
err
)
=
proc
.
communicate
()
if
err
:
print
err
sys
.
exit
()
return
map
(
float
,
out
.
split
(
" "
))
if
__name__
==
'__main__'
:
(
cheapTime
,
costlyTime
)
=
runScript
()
os
.
environ
[
'THEANO_FLAGS'
]
=
'openmp=true'
(
cheapTimeOpenmp
,
costlyTimeOpenmp
)
=
runScript
()
if
cheapTime
>
cheapTimeOpenmp
:
cheapSpeed
=
(
cheapTime
-
cheapTimeOpenmp
)
/
cheapTime
cheapSpeedstring
=
"speedup"
else
:
cheapSpeed
=
(
cheapTimeOpenmp
-
cheapTime
)
/
cheapTimeOpenmp
cheapSpeedstring
=
"slowdown"
if
cheapTime
>
cheapTimeOpenmp
:
costlySpeed
=
(
costlyTime
-
costlyTimeOpenmp
)
/
costlyTime
costlySpeedstring
=
"speedup"
else
:
costlySpeed
=
(
costlyTimeOpenmp
-
costlyTime
)
/
costlyTimeOpenmp
costlySpeedstring
=
"slowdown"
print
"Cheap op time without openmp
%
fs with openmp
%
fs
%
s
%2.2
f
%%
"
%
(
cheapTime
,
cheapTimeOpenmp
,
cheapSpeedstring
,
cheapSpeed
*
100
)
print
"Costly op time without openmp
%
fs with openmp
%
fs
%
s
%2.2
f
%%
"
%
(
costlyTime
,
costlyTimeOpenmp
,
costlySpeedstring
,
costlySpeed
*
100
)
theano/misc/elemwise_time_test.py
0 → 100644
浏览文件 @
74a105e8
import
theano
import
theano.tensor
as
T
import
numpy
as
np
import
time
from
optparse
import
OptionParser
import
sys
parser
=
OptionParser
(
usage
=
'
%
prog <options>
\n
Compute time for'
'cheap and costly elemwise operations'
)
parser
.
add_option
(
'-N'
,
'--N'
,
action
=
'store'
,
dest
=
'N'
,
default
=
theano
.
config
.
openmp_elemwise_minsize
,
type
=
"int"
,
help
=
"Number of vector element"
)
parser
.
add_option
(
'--script'
,
action
=
'store_true'
,
dest
=
'script'
,
default
=
False
,
help
=
"Run program as script and print results on stdoutput"
)
def
evalTime
(
f
,
v
,
script
=
False
,
loops
=
1000
):
min
=
1e10
for
i
in
xrange
(
0
,
loops
):
t0
=
time
.
time
()
f
(
v
)
dt
=
time
.
time
()
-
t0
min
=
dt
if
dt
<
min
else
min
if
not
script
:
print
' run time in
%
d loops was
%2.9
f sec'
%
(
loops
,
min
)
return
min
def
ElemwiseOpTime
(
N
,
script
=
False
,
loops
=
1000
):
x
=
T
.
vector
(
'x'
)
np
.
random
.
seed
(
1235
)
v
=
np
.
random
.
random
(
N
)
.
astype
(
theano
.
config
.
floatX
)
f
=
theano
.
function
([
x
],
2
*
x
+
x
*
x
)
f1
=
theano
.
function
([
x
],
T
.
tanh
(
x
))
if
not
script
:
if
theano
.
config
.
openmp
:
print
"With openmp:"
print
"Cheap op "
,
ceapTime
=
evalTime
(
f
,
v
,
script
=
script
,
loops
=
loops
)
if
not
script
:
print
"Costly op "
,
costlyTime
=
evalTime
(
f1
,
v
,
script
=
script
,
loops
=
loops
)
return
(
ceapTime
,
costlyTime
)
if
__name__
==
'__main__'
:
options
,
arguments
=
parser
.
parse_args
(
sys
.
argv
)
if
hasattr
(
options
,
"help"
):
print
options
.
help
sys
.
exit
(
0
)
(
cheapTime
,
costlyTime
)
=
ElemwiseOpTime
(
N
=
options
.
N
,
script
=
options
.
script
)
if
options
.
script
:
sys
.
stdout
.
write
(
"
%2.9
f
%2.9
f
\n
"
%
(
cheapTime
,
costlyTime
))
sys
.
stdout
.
flush
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论