本文整理汇总了Python中theano.gof.compilelock.release_lock函数的典型用法代码示例。如果您正苦于以下问题:Python release_lock函数的具体用法?Python release_lock怎么用?Python release_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了release_lock函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: open
except OSError as e:
assert e.errno == errno.EEXIST
assert os.path.exists(location), location
if not os.path.exists(os.path.join(location, '__init__.py')):
open(os.path.join(location, '__init__.py'), 'w').close()
try:
from cutils_ext.cutils_ext import * # noqa
except ImportError:
get_lock()
# Ensure no-one else is currently modifying the content of the compilation
# directory. This is important to prevent multiple processes from trying to
# compile the cutils_ext module simultaneously.
try:
try:
# We must retry to import it as some other process could
# have been compiling it between the first failed import
# and when we receive the lock
from cutils_ext.cutils_ext import * # noqa
except ImportError:
compile_cutils()
from cutils_ext.cutils_ext import * # noqa
finally:
# Release lock on compilation directory.
release_lock()
finally:
if sys.path[0] == config.compiledir:
del sys.path[0]
开发者ID:Ambier,项目名称:Theano,代码行数:30,代码来源:cutils.py
示例2: abll_compile
def abll_compile():
# Compile .cu files in abll
_logger.debug('nvcc_compiler.rpath_defaults: %s',
str(nvcc_compiler.rpath_defaults))
import time
t1 = time.time()
if should_recompile():
_logger.debug('should recompile')
# Concatenate all .cu files into one big mod.cu
code = []
for source_file in srcs:
code.append(open(os.path.join(src_dir, source_file)).read())
code = '\n'.join(code)
get_lock()
try:
# Check if the compilation has already been done by another process
# while we were waiting for the lock
if should_recompile():
_logger.debug('recompiling')
try:
compiler = nvcc_compiler.NVCC_compiler()
args = compiler.compile_args()
# compiler.compile_args() can execute a
# compilation This currently will remove empty
# directory in the compile dir. So we must make
# destination directory after calling it.
if not os.path.exists(loc):
os.makedirs(loc)
compiler.compile_str(
'abll',
code,
location=loc,
include_dirs=[include_dir],
lib_dirs=nvcc_compiler.rpath_defaults + [loc],
libs=libs,
preargs=['-O3'] + args,
py_module=False,)
except Exception as e:
_logger.error('Failed to compile %s %s: %s',
os.path.join(loc, 'mod.cu'),
srcs, str(e))
return False
else:
_logger.debug('already compiled by another process')
finally:
release_lock()
else:
_logger.debug('not recompiling')
# If necessary, create a symlink called libabll.so
if not symlink_ok():
if sys.platform == 'win32':
# The Python `os` module does not support symlinks on win32.
shutil.copyfile(abll_so, libabll_so)
else:
try:
os.symlink(abll_so, libabll_so)
except OSError as e:
# This may happen for instance when running multiple
# concurrent jobs, if two of them try to create the
# symlink simultaneously.
# If that happens, we verify that the existing symlink is
# indeed working.
if (getattr(e, 'errno', None) != errno.EEXIST
or not symlink_ok()):
raise
# Raise an error if libabll_so is still not available
open(libabll_so).close()
# Add abll to the list of places that are hard-coded into
# compiled modules' runtime library search list.
nvcc_compiler.add_standard_rpath(loc)
t2 = time.time()
_logger.debug('successfully imported. Compiled in %fs', t2 - t1)
return True
开发者ID:andersbll,项目名称:theano_ops,代码行数:83,代码来源:abll_compile.py
示例3: release_writelock
def release_writelock(self):
"""
Release the previously obtained writelock
"""
compilelock.release_lock()
开发者ID:carlzhangxuan,项目名称:pylearn2,代码行数:5,代码来源:cache.py
示例4: convnet_compile
def convnet_compile():
# Compile .cu files in cuda_convnet
_logger.debug("nvcc_compiler.rpath_defaults: %s", str(nvcc_compiler.rpath_defaults))
import time
t1 = time.time()
if should_recompile():
_logger.debug("should recompile")
# Concatenate all .cu files into one big mod.cu
code = []
for source_file in cuda_convnet_file_sources:
code.append(open(os.path.join(this_dir, source_file)).read())
code = "\n".join(code)
get_lock()
try:
# Check if the compilation has already been done by another process
# while we were waiting for the lock
if should_recompile():
_logger.debug("recompiling")
try:
compiler = nvcc_compiler.NVCC_compiler()
args = compiler.compile_args()
# compiler.compile_args() can execute a
# compilation This currently will remove empty
# directory in the compile dir. So we must make
# destination directory after calling it.
if not os.path.exists(cuda_convnet_loc):
os.makedirs(cuda_convnet_loc)
compiler.compile_str(
"cuda_convnet",
code,
location=cuda_convnet_loc,
include_dirs=[this_dir, config.pthreads.inc_dir] if config.pthreads.inc_dir else [this_dir],
lib_dirs=nvcc_compiler.rpath_defaults
+ [cuda_convnet_loc]
+ ([config.pthreads.lib_dir] if config.pthreads.lib_dir else []),
libs=["cublas", config.pthreads.lib] if config.pthreads.lib else ["cublas"],
preargs=["-O3"] + args,
py_module=False,
)
except Exception as e:
_logger.error(
"Failed to compile %s %s: %s",
os.path.join(cuda_convnet_loc, "mod.cu"),
cuda_convnet_file_sources,
str(e),
)
return False
else:
_logger.debug("already compiled by another process")
finally:
release_lock()
else:
_logger.debug("not recompiling")
# If necessary, create a symlink called libcuda_convnet.so
if not symlink_ok():
if sys.platform == "win32":
# The Python `os` module does not support symlinks on win32.
shutil.copyfile(cuda_convnet_so, libcuda_convnet_so)
else:
try:
os.symlink(cuda_convnet_so, libcuda_convnet_so)
except OSError as e:
# This may happen for instance when running multiple
# concurrent jobs, if two of them try to create the
# symlink simultaneously.
# If that happens, we verify that the existing symlink is
# indeed working.
if getattr(e, "errno", None) != errno.EEXIST or not symlink_ok():
raise
# Raise an error if libcuda_convnet_so is still not available
open(libcuda_convnet_so).close()
# Add cuda_convnet to the list of places that are hard-coded into
# compiled modules' runtime library search list.
nvcc_compiler.add_standard_rpath(cuda_convnet_loc)
t2 = time.time()
_logger.debug("successfully imported. Compiled in %fs", t2 - t1)
return True
开发者ID:JesseLivezey,项目名称:pylearn2,代码行数:88,代码来源:convnet_compile.py
注:本文中的theano.gof.compilelock.release_lock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论