提交 e2d07514 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Include C cache preloading in profile output

Also don't do it if there's no C compilation
上级 7ecb9f8c
...@@ -1474,7 +1474,7 @@ class FunctionMaker: ...@@ -1474,7 +1474,7 @@ class FunctionMaker:
if getattr(mode, "profile", None): if getattr(mode, "profile", None):
raise TypeError("profile passed via 'mode'. This isn't supported anymore") raise TypeError("profile passed via 'mode'. This isn't supported anymore")
self.profile = profile self.profile = profile
if profile: if profile and config.cxx:
# This is very important: # This is very important:
# 1) We preload the cache here to not have its timing # 1) We preload the cache here to not have its timing
# included with the rewrites. # included with the rewrites.
...@@ -1482,7 +1482,12 @@ class FunctionMaker: ...@@ -1482,7 +1482,12 @@ class FunctionMaker:
# too much execution time during testing as we compile # too much execution time during testing as we compile
# much more functions then the number of compile c # much more functions then the number of compile c
# module. # module.
start_get_cache = time.perf_counter()
pytensor.link.c.basic.get_module_cache().refresh() pytensor.link.c.basic.get_module_cache().refresh()
get_cache_time = time.perf_counter() - start_get_cache
self.profile.linker_time += get_cache_time
self.profile.preload_cache_time += get_cache_time
# Handle the case where inputs and/or outputs is a single # Handle the case where inputs and/or outputs is a single
# Variable (not in a list) # Variable (not in a list)
unpack_single = False unpack_single = False
...@@ -1722,7 +1727,8 @@ def orig_function( ...@@ -1722,7 +1727,8 @@ def orig_function(
""" """
t1 = time.perf_counter() if profile:
t1 = time.perf_counter()
mode = pytensor.compile.mode.get_mode(mode) mode = pytensor.compile.mode.get_mode(mode)
inputs = list(map(convert_function_input, inputs)) inputs = list(map(convert_function_input, inputs))
...@@ -1755,8 +1761,8 @@ def orig_function( ...@@ -1755,8 +1761,8 @@ def orig_function(
with config.change_flags(compute_test_value="off"): with config.change_flags(compute_test_value="off"):
fn = m.create(defaults) fn = m.create(defaults)
finally: finally:
t2 = time.perf_counter() if profile and fn:
if fn and profile: t2 = time.perf_counter()
profile.compile_time += t2 - t1 profile.compile_time += t2 - t1
# TODO: append # TODO: append
profile.nb_nodes = len(fn.maker.fgraph.apply_nodes) profile.nb_nodes = len(fn.maker.fgraph.apply_nodes)
......
...@@ -269,6 +269,9 @@ class ProfileStats: ...@@ -269,6 +269,9 @@ class ProfileStats:
linker_time: float = 0.0 linker_time: float = 0.0
# time spent linking graph (FunctionMaker.create) # time spent linking graph (FunctionMaker.create)
preload_cache_time: float = 0.0
# time spent preloading the cache, so it does not affect rewrites profiling
import_time: float = 0.0 import_time: float = 0.0
# time spent in importing compiled python module. # time spent in importing compiled python module.
...@@ -811,6 +814,7 @@ class ProfileStats: ...@@ -811,6 +814,7 @@ class ProfileStats:
), ),
file=file, file=file,
) )
print(f" C-cache preloading {self.preload_cache_time:e}s", file=file)
print(f" Import time {self.import_time:e}s", file=file) print(f" Import time {self.import_time:e}s", file=file)
print( print(
f" Node make_thunk time {self.linker_node_make_thunks:e}s", file=file f" Node make_thunk time {self.linker_node_make_thunks:e}s", file=file
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论