提交 ddf1c0e6 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Cache mechanism improvements:

- Avoid actually compiling a module when it has same hash as an existing one - Simplified the get/release lock stuff in some functions - Added ability to log messages directly when calling _rmtree
上级 4bcbc2f5
...@@ -958,11 +958,30 @@ class CLinker(link.Linker): ...@@ -958,11 +958,30 @@ class CLinker(link.Linker):
def compile_cmodule(self, location=None): def compile_cmodule(self, location=None):
""" """
This method is a callback for `ModuleCache.module_from_key` Compile the module and return it.
"""
# Go through all steps of the compilation process.
for step_result in self.compile_cmodule_by_step(location=location):
pass
# And return the output of the last step, which should be the module
# itself.
return step_result
def compile_cmodule_by_step(self, location=None):
"""
This method is a callback for `ModuleCache.module_from_key`.
It is a generator (thus the 'by step'), so that:
- it first yields the module's C code
- it last yields the module itself
- it may yield other intermediate outputs in-between if needed
in the future (but this is not currently the case)
""" """
if location is None: if location is None:
location = cmodule.dlimport_workdir(config.compiledir) location = cmodule.dlimport_workdir(config.compiledir)
mod = self.build_dynamic_module() mod = self.build_dynamic_module()
src_code = mod.code()
yield src_code
get_lock() get_lock()
try: try:
debug("LOCATION", location) debug("LOCATION", location)
...@@ -970,7 +989,7 @@ class CLinker(link.Linker): ...@@ -970,7 +989,7 @@ class CLinker(link.Linker):
libs = self.libraries() libs = self.libraries()
preargs = self.compile_args() preargs = self.compile_args()
if c_compiler.__name__=='nvcc_module_compile_str' and config.lib.amdlibm: if c_compiler.__name__=='nvcc_module_compile_str' and config.lib.amdlibm:
#this lib don't work correctly with nvcc in device code. # This lib does not work correctly with nvcc in device code.
if '<amdlibm.h>' in mod.includes: if '<amdlibm.h>' in mod.includes:
mod.includes.remove('<amdlibm.h>') mod.includes.remove('<amdlibm.h>')
if '-DREPLACE_WITH_AMDLIBM' in preargs: if '-DREPLACE_WITH_AMDLIBM' in preargs:
...@@ -980,7 +999,7 @@ class CLinker(link.Linker): ...@@ -980,7 +999,7 @@ class CLinker(link.Linker):
try: try:
module = c_compiler( module = c_compiler(
module_name=mod.name, module_name=mod.name,
src_code = mod.code(), src_code=src_code,
location=location, location=location,
include_dirs=self.header_dirs(), include_dirs=self.header_dirs(),
lib_dirs=self.lib_dirs(), lib_dirs=self.lib_dirs(),
...@@ -992,8 +1011,7 @@ class CLinker(link.Linker): ...@@ -992,8 +1011,7 @@ class CLinker(link.Linker):
finally: finally:
release_lock() release_lock()
return module yield module
def build_dynamic_module(self): def build_dynamic_module(self):
"""Return a cmodule.DynamicModule instance full of the code for our env. """Return a cmodule.DynamicModule instance full of the code for our env.
...@@ -1056,10 +1074,10 @@ class CLinker(link.Linker): ...@@ -1056,10 +1074,10 @@ class CLinker(link.Linker):
except KeyError: except KeyError:
key = None key = None
if key is None: if key is None:
#if we can't get a key, then forget the cache mechanism # If we can't get a key, then forget the cache mechanism.
module = self.compile_cmodule() module = self.compile_cmodule()
else: else:
module = get_module_cache().module_from_key(key=key, fn=self.compile_cmodule, keep_lock=keep_lock) module = get_module_cache().module_from_key(key=key, fn=self.compile_cmodule_by_step, keep_lock=keep_lock)
vars = self.inputs + self.outputs + self.orphans vars = self.inputs + self.outputs + self.orphans
# List of indices that should be ignored when passing the arguments # List of indices that should be ignored when passing the arguments
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论