提交 2cafbc23 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Delay compilation of cutils_ext until it is actually needed.

This is useful e.g. to be able to copy a precompiled cutils_ext into the compiledir *after* reading the value of theano.config.compiledir.
上级 a8937a8a
import time, atexit, copy
from theano.gof.link import WrapLinker
from theano.gof.cutils import run_cthunk
from theano.compile.mode import Mode, register_mode, predefined_modes, predefined_linkers, predefined_optimizers
from theano.gof.python25 import any
from theano import gof
from theano.configparser import config, AddConfigVar, IntParam, BoolParam
from theano.compile.function_module import FunctionMaker
run_cthunk = None # Will be imported only when needed.
import_time = time.time()
......@@ -85,7 +85,11 @@ class ProfileMode(Mode):
def profile_thunk(i, node, th):
""" Profile only the execution time
"""
global run_cthunk
if hasattr(th, 'cthunk'):
if run_cthunk is None:
# Lazy import to avoid compilation when importing theano.
from theano.gof.cutils import run_cthunk
t0 = time.time()
failure = run_cthunk(th.cthunk)
dt = time.time() - t0
......@@ -104,7 +108,11 @@ class ProfileMode(Mode):
def profile_thunk2(i, node, th):
""" Profile the execution time and the memory size.
"""
global run_cthunk
if hasattr(th, 'cthunk'):
if run_cthunk is None:
# Lazy import to avoid compilation when importing theano.
from theano.gof.cutils import run_cthunk
t0 = time.time()
failure = run_cthunk(th.cthunk)
dt = time.time() - t0
......
......@@ -36,7 +36,6 @@ AddConfigVar('gcc.cxxflags',
StrParam(""))
# gof imports
import cutils
from env import Env
import graph
import link
......@@ -63,6 +62,9 @@ def error(*args):
from theano.gof.callcache import CallCache
run_cthunk = None # Will be imported only when needed.
def get_module_cache(init_args=None):
"""
:param init_args: If not None, the (k, v) pairs in this dictionary will
......@@ -1116,6 +1118,11 @@ class CLinker(link.Linker):
def _execute(cthunk, init_tasks, tasks, error_storage):
"""WRITEME"""
global run_cthunk
if run_cthunk is None:
# Lazy import to avoid compilation when importing theano.
from theano.gof.cutils import run_cthunk
def find_task(failure_code):
"""
Maps a failure code to the task that is associated to it.
......@@ -1128,7 +1135,7 @@ def _execute(cthunk, init_tasks, tasks, error_storage):
else:
return tasks[failure_code - n]
def execute():
failure = cutils.run_cthunk(cthunk)
failure = run_cthunk(cthunk)
if failure:
task, taskname, id = find_task(failure)
try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论