Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c58fd8c8
提交
c58fd8c8
authored
3月 04, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1255 from nouiz/march
add equivalent of -march=native to g++ command line.
上级
0781c496
e49d70e9
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
92 行增加
和
4 行删除
+92
-4
faq.txt
doc/tutorial/faq.txt
+9
-2
cmodule.py
theano/gof/cmodule.py
+71
-0
unittest_tools.py
theano/tests/unittest_tools.py
+12
-2
没有找到文件。
doc/tutorial/faq.txt
浏览文件 @
c58fd8c8
...
...
@@ -26,10 +26,17 @@ Faster gcc optimization
You can enable faster gcc optimization with the ``cxxflags``. This list of flags was suggested on the mailing list::
cxxflags=-march=native
-O3 -ffast-math -ftree-loop-distribution -funroll-loops -ftracer
-O3 -ffast-math -ftree-loop-distribution -funroll-loops -ftracer
Use it at your own risk. Some people warned that the ``-ftree-loop-distribution`` optimization resulted in wrong results in the past.
Also the ``-march=native`` flag must be used with care if you have NFS. In that case, you MUST set the compiledir to a local path of the computer.
In the past we told that if the ``compiledir`` wasn't shared by multiple
computers, you could add the ``-march=native`` flags. Now we recommande
to remove this flags as Theano does that automatically and safelly
even if the ``compiledir`` is shared by multiple computers with different
CPU. In fact, we ask g++ what are the equivalent flags it use and use
them directly.
Faster Theano function
----------------------
...
...
theano/gof/cmodule.py
浏览文件 @
c58fd8c8
...
...
@@ -1475,6 +1475,9 @@ def gcc_version():
class
GCC_compiler
(
object
):
# The equivalent flags of --march=native used by g++.
march_flags
=
None
@staticmethod
def
version_str
():
return
"g++ "
+
gcc_version_str
...
...
@@ -1482,6 +1485,74 @@ class GCC_compiler(object):
@staticmethod
def
compile_args
():
cxxflags
=
[
flag
for
flag
in
config
.
gcc
.
cxxflags
.
split
(
' '
)
if
flag
]
# Add the equivalent of -march=native flag. We can't use
# -march=native as when the compiledir is shared by multiple
# computers (for example, if the home directory is on NFS), this
# won't be optimum or cause crash depending if the file is compiled
# on an older or more recent computer.
# Those URL discuss how to find witch flags are used by -march=native.
# http://en.gentoo-wiki.com/wiki/Safe_Cflags#-march.3Dnative
# http://en.gentoo-wiki.com/wiki/Hardware_CFLAGS
detect_march
=
GCC_compiler
.
march_flags
is
None
if
detect_march
:
for
f
in
cxxflags
:
#If the user give an -march=X parameter, don't add one ourself
if
((
f
.
startswith
(
"--march="
)
or
f
.
startswith
(
"-march="
))):
_logger
.
warn
(
"WARNING: your Theano flags `gcc.cxxflags` specify"
" an `-march=X` flags.
\n
"
" It is better to let Theano/g++ find it"
" automatically, but we don't do it now"
)
detect_march
=
False
break
if
detect_march
:
GCC_compiler
.
march_flags
=
[]
def
get_lines
(
cmd
):
p
=
call_subprocess_Popen
(
cmd
,
stderr
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
stdout
=
p
.
stdout
.
readlines
()
stderr
=
p
.
stderr
.
readlines
()
lines
=
[]
for
line
in
stdout
+
stderr
:
if
"-march="
in
line
and
"-march=native"
not
in
line
:
lines
.
append
(
line
.
strip
())
lines
=
list
(
set
(
lines
))
# to remove duplicate
return
lines
native_lines
=
get_lines
(
"g++ -march=native -E -v - </dev/null"
)
_logger
.
info
(
"g++ -march=native selected lines:
%
s"
,
native_lines
)
if
len
(
native_lines
)
!=
1
:
_logger
.
warn
(
"OPTIMIZATION WARNING: Theano was not able to find the"
" g++ parameter that tune the compilation to your specific"
" CPU. This can slow down the execution of Theano"
" function. Can you submit the following lines to"
" Theano's mailing list such that we fix this"
" problem:
\n
%
s"
,
native_lines
)
else
:
default_lines
=
get_lines
(
"g++ -E -v - </dev/null"
)
_logger
.
info
(
"g++ default lines:
%
s"
,
default_lines
)
assert
len
(
default_lines
)
>
1
part
=
native_lines
[
0
]
.
split
()
for
line
in
default_lines
:
if
line
.
startswith
(
part
[
0
]):
part2
=
[
p
for
p
in
line
.
split
()
if
not
'march'
in
p
and
not
'mtune'
in
p
]
new_flags
=
[
p
for
p
in
part
if
p
not
in
part2
]
GCC_compiler
.
march_flags
=
new_flags
break
_logger
.
info
(
"g++ -march=native equivalent flags:
%
s"
,
GCC_compiler
.
march_flags
)
#Add the detected -march=native equivalent flags
cxxflags
.
extend
(
GCC_compiler
.
march_flags
)
#NumPy 1.7 Deprecate the old API. I updated most of the places
#to use the new API, but not everywhere. When finished, enable
#the following macro to assert that we don't bring new code
...
...
theano/tests/unittest_tools.py
浏览文件 @
c58fd8c8
...
...
@@ -19,9 +19,19 @@ except ImportError:
_logger
=
logging
.
getLogger
(
"theano.tests.unittest_tools"
)
def
good_seed_param
(
seed
):
if
seed
==
"random"
:
return
True
try
:
int
(
seed
)
except
Exception
:
return
False
return
True
AddConfigVar
(
'unittests.rseed'
,
"Seed to use for randomized unit tests. Special value 'random' means using a seed of None."
,
StrParam
(
666
),
"Seed to use for randomized unit tests. "
"Special value 'random' means using a seed of None."
,
StrParam
(
666
,
is_valid
=
good_seed_param
),
in_c_key
=
False
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论