Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dce45cf8
提交
dce45cf8
authored
12月 02, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2310 from abergeron/compile_time
Improve compile time on slow filesystems
上级
ea54556b
b2a1e901
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
107 行增加
和
59 行删除
+107
-59
config.txt
doc/library/config.txt
+41
-15
configdefaults.py
theano/configdefaults.py
+13
-4
compilelock.py
theano/gof/compilelock.py
+53
-40
没有找到文件。
doc/library/config.txt
浏览文件 @
dce45cf8
...
@@ -166,7 +166,7 @@ import theano and print the config variable, as in:
...
@@ -166,7 +166,7 @@ import theano and print the config variable, as in:
Theano initialize the GPU device. Newer version of PyCUDA
Theano initialize the GPU device. Newer version of PyCUDA
(currently only in the trunk) don't have this restriction.
(currently only in the trunk) don't have this restriction.
.. attribute::
config.
print_active_device
.. attribute:: print_active_device
Bool value: either ``True`` or ``False``
Bool value: either ``True`` or ``False``
...
@@ -310,26 +310,26 @@ import theano and print the config variable, as in:
...
@@ -310,26 +310,26 @@ import theano and print the config variable, as in:
Do the vm/cvm linkers profile the optimization phase when compiling a Theano function?
Do the vm/cvm linkers profile the optimization phase when compiling a Theano function?
It only works when profile=True.
It only works when profile=True.
.. attribute:: profiling.n_apply
.. attribute::
config.
profiling.n_apply
Positive int value, default: 20.
Positive int value, default: 20.
The number of Apply nodes to print in the profiler output
The number of Apply nodes to print in the profiler output
.. attribute:: profiling.n_ops
.. attribute::
config.
profiling.n_ops
Positive int value, default: 20.
Positive int value, default: 20.
The number of Ops to print in the profiler output
The number of Ops to print in the profiler output
.. attribute:: profiling.min_memory_size
.. attribute::
config.
profiling.min_memory_size
Positive int value, default: 1024.
Positive int value, default: 1024.
For the memory profile, do not print Apply nodes if the size
For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this.
of their outputs (in bytes) is lower than this.
.. attribute:: profiling.min_peak_memory
.. attribute::
config.
profiling.min_peak_memory
Bool value: either True or False
Bool value: either True or False
...
@@ -338,7 +338,7 @@ import theano and print the config variable, as in:
...
@@ -338,7 +338,7 @@ import theano and print the config variable, as in:
Does the memory profile print the min peak memory usage?
Does the memory profile print the min peak memory usage?
It only works when profile=True, profile_memory=True
It only works when profile=True, profile_memory=True
.. attribute:: profiling.destination
.. attribute::
config.
profiling.destination
String value: 'stderr', 'stdout', or a name of a
String value: 'stderr', 'stdout', or a name of a
file to be created
file to be created
...
@@ -491,7 +491,7 @@ import theano and print the config variable, as in:
...
@@ -491,7 +491,7 @@ import theano and print the config variable, as in:
Extra parameters to pass to gcc when compiling. Extra include paths,
Extra parameters to pass to gcc when compiling. Extra include paths,
library paths, configuration options, etc.
library paths, configuration options, etc.
.. attribute:: c
onfig.c
xx
.. attribute:: cxx
Default: 'g++' if g++ is present. Empty string otherwise.
Default: 'g++' if g++ is present. Empty string otherwise.
...
@@ -555,7 +555,33 @@ import theano and print the config variable, as in:
...
@@ -555,7 +555,33 @@ import theano and print the config variable, as in:
This means files whose compilation failed are deleted.
This means files whose compilation failed are deleted.
Set to True to keep those files in order to debug compilation errors.
Set to True to keep those files in order to debug compilation errors.
.. attribute:: config.DebugMode
.. attribute:: compile
This section contains attributes which influence the compilation of
C code for ops. Due to historical reasons many attributes outside
of this section also have an influence over compilation, most
notably 'cxx'. This is not expected to change any time soon.
.. attribute:: config.compile.timeout
Positive int value, default: :attr:`compile.wait` * 24
Time to wait before an unrefreshed lock is broken and stolen. This
is in place to avoid manual cleanup of locks in case a process
crashed and left a lock in place.
The refresh time is automatically set to half the timeout value.
.. attribute:: config.compile.wait
Positive int value, default: 5
Time to wait between attempts at grabbing the lock if the first
attempt is not successful. The actual time will be between
:attr:`compile.wait` and :attr:`compile.wait` * 2 to avoid a
crowding effect on lock.
.. attribute:: DebugMode
This section contains various attributes configuring the behaviour
This section contains various attributes configuring the behaviour
of mode :class:`~debugmode.DebugMode`. See directly this section
of mode :class:`~debugmode.DebugMode`. See directly this section
...
@@ -595,7 +621,7 @@ import theano and print the config variable, as in:
...
@@ -595,7 +621,7 @@ import theano and print the config variable, as in:
Generate a warning when the destroy_map or view_map tell that an op work
Generate a warning when the destroy_map or view_map tell that an op work
inplace, but the op did not reuse the input for its output.
inplace, but the op did not reuse the input for its output.
.. attribute::
config.
numpy
.. attribute:: numpy
This section contains different attributes for configuring numpy's
This section contains different attributes for configuring numpy's
behaviour, described by `numpy.seterr
behaviour, described by `numpy.seterr
...
@@ -669,7 +695,7 @@ import theano and print the config variable, as in:
...
@@ -669,7 +695,7 @@ import theano and print the config variable, as in:
This flag's value cannot be modified during the program execution.
This flag's value cannot be modified during the program execution.
.. attribute:: co
nfig.co
mpute_test_value
.. attribute:: compute_test_value
String Value: ``'off'``, ``'ignore'``, ``'warn'``, ``'raise'``.
String Value: ``'off'``, ``'ignore'``, ``'warn'``, ``'raise'``.
...
@@ -693,13 +719,13 @@ import theano and print the config variable, as in:
...
@@ -693,13 +719,13 @@ import theano and print the config variable, as in:
this Op
this Op
- ``'raise'`` will raise an Exception
- ``'raise'`` will raise an Exception
.. attribute:: co
nfig.co
mpute_test_value_opt
.. attribute:: compute_test_value_opt
As ``compute_test_value``, but it is the value used during Theano
As ``compute_test_value``, but it is the value used during Theano
optimization phase. Theano user's do not need to use this. This is
optimization phase. Theano user's do not need to use this. This is
to help debug shape error in Theano optimization.
to help debug shape error in Theano optimization.
.. attribute::
config.
reoptimize_unpickled_function
.. attribute:: reoptimize_unpickled_function
Bool value, default: True
Bool value, default: True
...
@@ -709,7 +735,7 @@ import theano and print the config variable, as in:
...
@@ -709,7 +735,7 @@ import theano and print the config variable, as in:
reoptimized when being unpickled. Otherwise, skip the graph optimization and
reoptimized when being unpickled. Otherwise, skip the graph optimization and
use directly the optimized graph.
use directly the optimized graph.
.. attribute::
config.
exception_verbosity
.. attribute:: exception_verbosity
String Value: ``'low'``, ``'high'``.
String Value: ``'low'``, ``'high'``.
...
@@ -749,13 +775,13 @@ import theano and print the config variable, as in:
...
@@ -749,13 +775,13 @@ import theano and print the config variable, as in:
This is useful to debug in gdb modules compiled by Theano.
This is useful to debug in gdb modules compiled by Theano.
The parameter -g is passed by default to g++.
The parameter -g is passed by default to g++.
.. attribute:: cmodule.compilation_warning
.. attribute:: c
onfig.c
module.compilation_warning
Bool value, default: False
Bool value, default: False
If True, will print compilation warnings.
If True, will print compilation warnings.
.. attribute:: c
module.preload_cache'
.. attribute:: c
onfig.cmodule.preload_cache
Bool value, default: False
Bool value, default: False
...
...
theano/configdefaults.py
浏览文件 @
dce45cf8
...
@@ -132,29 +132,38 @@ AddConfigVar('mode',
...
@@ -132,29 +132,38 @@ AddConfigVar('mode',
'FAST_COMPILE'
,
'PROFILE_MODE'
,
'DEBUG_MODE'
),
'FAST_COMPILE'
,
'PROFILE_MODE'
,
'DEBUG_MODE'
),
in_c_key
=
False
)
in_c_key
=
False
)
param
=
StrParam
(
"g++"
)
param
=
"g++"
# Test whether or not g++ is present: disable C code if it is not.
# Test whether or not g++ is present: disable C code if it is not.
try
:
try
:
rc
=
call_subprocess_Popen
([
'g++'
,
'-v'
])
rc
=
call_subprocess_Popen
([
'g++'
,
'-v'
])
except
OSError
:
except
OSError
:
param
=
StrParam
(
""
)
param
=
""
rc
=
1
rc
=
1
# On Mac we test for 'clang++' and use it by default
# On Mac we test for 'clang++' and use it by default
if
sys
.
platform
==
'darwin'
:
if
sys
.
platform
==
'darwin'
:
try
:
try
:
rc
=
call_subprocess_Popen
([
'clang++'
,
'-v'
])
rc
=
call_subprocess_Popen
([
'clang++'
,
'-v'
])
param
=
StrParam
(
"clang++"
)
param
=
"clang++"
except
OSError
:
except
OSError
:
pass
pass
# Try to find the full compiler path from the name
if
param
!=
""
:
import
distutils.spawn
newp
=
distutils
.
spawn
.
find_executable
(
param
)
if
newp
is
not
None
:
param
=
newp
del
newp
del
distutils
AddConfigVar
(
'cxx'
,
AddConfigVar
(
'cxx'
,
"The C++ compiler to use. Currently only g++ is"
"The C++ compiler to use. Currently only g++ is"
" supported, but supporting additional compilers should not be "
" supported, but supporting additional compilers should not be "
"too difficult. "
"too difficult. "
"If it is empty, no C++ code is compiled."
,
"If it is empty, no C++ code is compiled."
,
param
,
StrParam
(
param
)
,
in_c_key
=
False
)
in_c_key
=
False
)
del
param
del
param
...
...
theano/gof/compilelock.py
浏览文件 @
dce45cf8
...
@@ -9,38 +9,39 @@ import time
...
@@ -9,38 +9,39 @@ import time
import
logging
import
logging
from
theano
import
config
from
theano
import
config
from
theano.configparser
import
AddConfigVar
,
IntParam
_logger
=
logging
.
getLogger
(
"theano.gof.compilelock"
)
_logger
=
logging
.
getLogger
(
"theano.gof.compilelock"
)
# If the user provided a logging level, we don't want to override it.
# If the user provided a logging level, we don't want to override it.
if
_logger
.
level
==
logging
.
NOTSET
:
if
_logger
.
level
==
logging
.
NOTSET
:
# INFO will show the
the messages "Refreshing lock" message
# INFO will show the
"Refreshing lock" messages
_logger
.
setLevel
(
logging
.
INFO
)
_logger
.
setLevel
(
logging
.
INFO
)
# In seconds, time that a process will wait before deciding to override an
AddConfigVar
(
'compile.wait'
,
# existing lock. An override only happens when the existing lock is held by
"""Time to wait before retrying to aquire the compile lock."""
,
# the same owner *and* has not been 'refreshed' by this owner for more than
IntParam
(
5
,
lambda
i
:
i
>
0
,
allow_override
=
False
),
# 'timeout_before_override' seconds.
in_c_key
=
False
)
timeout_before_override
=
120
# In seconds, duration before a lock is refreshed. More precisely, the lock is
def
_timeout_default
():
# refreshed each time 'get_lock()' is called (typically for each file being
return
config
.
compile
.
wait
*
24
# compiled) and the existing lock has not been refreshed in the past
# 'refresh_every' seconds.
AddConfigVar
(
'compile.timeout'
,
refresh_every
=
60
"""In seconds, time that a process will wait before deciding to
override an existing lock. An override only happens when the existing
lock is held by the same owner *and* has not been 'refreshed' by this
owner for more than this period. Refreshes are done every half timeout
period for running processes."""
,
IntParam
(
_timeout_default
,
lambda
i
:
i
>=
0
,
allow_override
=
False
),
in_c_key
=
False
)
def
force_unlock
():
def
force_unlock
():
"""
"""
Delete the compilation lock if someone else has it.
Delete the compilation lock if someone else has it.
"""
"""
global
timeout_before_override
get_lock
(
min_wait
=
0
,
max_wait
=
0.001
,
timeout
=
0
)
timeout_backup
=
timeout_before_override
release_lock
()
timeout_before_override
=
0
try
:
get_lock
(
min_wait
=
0
,
max_wait
=
0.001
)
release_lock
()
finally
:
timeout_before_override
=
timeout_backup
def
get_lock
(
lock_dir
=
None
,
**
kw
):
def
get_lock
(
lock_dir
=
None
,
**
kw
):
...
@@ -74,16 +75,17 @@ def get_lock(lock_dir=None, **kw):
...
@@ -74,16 +75,17 @@ def get_lock(lock_dir=None, **kw):
if
get_lock
.
lock_is_enabled
:
if
get_lock
.
lock_is_enabled
:
# Only really try to acquire the lock if we do not have it already.
# Only really try to acquire the lock if we do not have it already.
if
get_lock
.
n_lock
==
0
:
if
get_lock
.
n_lock
==
0
:
lock
(
get_lock
.
lock_dir
,
timeout
=
timeout_before_override
,
**
kw
)
lock
(
get_lock
.
lock_dir
,
**
kw
)
atexit
.
register
(
Unlocker
.
unlock
,
get_lock
.
unlocker
)
atexit
.
register
(
Unlocker
.
unlock
,
get_lock
.
unlocker
)
# Store time at which the lock was set.
# Store time at which the lock was set.
get_lock
.
start_time
=
time
.
time
()
get_lock
.
start_time
=
time
.
time
()
else
:
else
:
# Check whether we need to 'refresh' the lock. We do this every
# Check whether we need to 'refresh' the lock. We do this
# 'refresh_every' seconds to ensure noone else tries to override
# every 'config.compile.timeout / 2' seconds to ensure
# our lock after their 'timeout_before_override' timeout period.
# no one else tries to override our lock after their
# 'config.compile.timeout' timeout period.
now
=
time
.
time
()
now
=
time
.
time
()
if
now
-
get_lock
.
start_time
>
refresh_every
:
if
now
-
get_lock
.
start_time
>
config
.
compile
.
timeout
/
2
:
lockpath
=
os
.
path
.
join
(
get_lock
.
lock_dir
,
'lock'
)
lockpath
=
os
.
path
.
join
(
get_lock
.
lock_dir
,
'lock'
)
_logger
.
info
(
'Refreshing lock
%
s'
,
str
(
lockpath
))
_logger
.
info
(
'Refreshing lock
%
s'
,
str
(
lockpath
))
refresh_lock
(
lockpath
)
refresh_lock
(
lockpath
)
...
@@ -109,46 +111,57 @@ def set_lock_status(use_lock):
...
@@ -109,46 +111,57 @@ def set_lock_status(use_lock):
by default). Disabling may make compilation slightly faster (but is not
by default). Disabling may make compilation slightly faster (but is not
recommended for parallel execution).
recommended for parallel execution).
@
param use_lock: whether to use the compilation lock or not
:
param use_lock: whether to use the compilation lock or not
@
type use_lock: bool
:
type use_lock: bool
"""
"""
get_lock
.
lock_is_enabled
=
use_lock
get_lock
.
lock_is_enabled
=
use_lock
# This is because None is a valid input for timeout
notset
=
object
()
def
lock
(
tmp_dir
,
timeout
=
120
,
min_wait
=
5
,
max_wait
=
10
,
verbosity
=
1
):
def
lock
(
tmp_dir
,
timeout
=
notset
,
min_wait
=
None
,
max_wait
=
None
,
verbosity
=
1
):
"""
"""
Obtain lock access by creating a given temporary directory (whose base will
Obtain lock access by creating a given temporary directory (whose base will
be created if needed, but will not be deleted after the lock is removed).
be created if needed, but will not be deleted after the lock is removed).
If access is refused by the same lock owner during more than 'timeout'
If access is refused by the same lock owner during more than 'timeout'
seconds, then the current lock is overridden. If timeout is None, then no
seconds, then the current lock is overridden. If timeout is None, then no
timeout is performed.
timeout is performed.
The lock is performed by creating a 'lock' file in 'tmp_dir' that contains
The lock is performed by creating a 'lock' file in 'tmp_dir' that contains
a unique id identifying the owner of the lock (the process id, followed by
a unique id identifying the owner of the lock (the process id, followed by
a random string).
a random string).
When there is already a lock, the process sleeps for a random amount of
When there is already a lock, the process sleeps for a random amount of
time between min_wait and max_wait seconds before trying again.
time between min_wait and max_wait seconds before trying again.
If 'verbosity' is >= 1, then a message will be displayed when we need to
If 'verbosity' is >= 1, then a message will be displayed when we need to
wait for the lock. If it is set to a value >1, then this message will be
wait for the lock. If it is set to a value >1, then this message will be
displayed each time we re-check for the presence of the lock. Otherwise it
displayed each time we re-check for the presence of the lock. Otherwise it
is displayed only when we notice the lock's owner has changed.
is displayed only when we notice the lock's owner has changed.
@param tmp_dir: lock directory that will be created when acquiring the lock
:param str tmp_dir: lock directory that will be created when
@type tmp_dir: string
acquiring the lock
@param timeout: time (in seconds) to wait before replacing an existing lock
:param timeout: time (in seconds) to wait before replacing an
@type timeout: int or None
existing lock (default config 'compile.timeout')
:type timeout: int or None
@param min_wait: minimum time (in seconds) to wait before trying again to
:param int min_wait: minimum time (in seconds) to wait before
get the lock
trying again to
get the lock
@type min_wait: int
(default config 'compile.wait')
@param max_wait: maximum time (in seconds) to wait before trying again to
:param int max_wait: maximum time (in seconds) to wait before
get the lock
trying again to
get the lock
@type max_wait: int
(default 2 * min_wait)
@param verbosity: amount of feedback displayed to screen
:param int verbosity: amount of feedback displayed to screen (default 1)
@type verbosity: int
"""
"""
if
min_wait
is
None
:
min_wait
=
config
.
compile
.
wait
if
max_wait
is
None
:
max_wait
=
min_wait
*
2
if
timeout
is
notset
:
timeout
=
config
.
compile
.
timeout
# Create base of lock directory if required.
# Create base of lock directory if required.
base_lock
=
os
.
path
.
dirname
(
tmp_dir
)
base_lock
=
os
.
path
.
dirname
(
tmp_dir
)
if
not
os
.
path
.
isdir
(
base_lock
):
if
not
os
.
path
.
isdir
(
base_lock
):
...
@@ -207,7 +220,7 @@ def lock(tmp_dir, timeout=120, min_wait=5, max_wait=10, verbosity=1):
...
@@ -207,7 +220,7 @@ def lock(tmp_dir, timeout=120, min_wait=5, max_wait=10, verbosity=1):
continue
continue
if
last_owner
==
read_owner
:
if
last_owner
==
read_owner
:
if
(
timeout
is
not
None
and
if
(
timeout
is
not
None
and
time
.
time
()
-
time_start
>=
timeout
):
time
.
time
()
-
time_start
>=
timeout
):
# Timeout exceeded or locking process dead.
# Timeout exceeded or locking process dead.
if
not
no_display
:
if
not
no_display
:
if
read_owner
==
'failure'
:
if
read_owner
==
'failure'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论