Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions torch_xla/csrc/init_python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,14 @@ void InitXlaModuleBindings(py::module m) {
[]() {
return XLAGraphExecutor::Get()->IsComputationCacheInitialized();
})
.def("_xla_computation_cache_clear",
[]() {
WaitDeviceOps();// wait for any inflight computations which may hold references to cached computations
XLAGraphExecutor::ComputationCache* cache = XLAGraphExecutor::Get()->GetComputationCache();
if (cache != nullptr) {
cache->Clear();
}
})
.def("_get_git_revs", //
&GetRevisions)
.def("_get_xla_tensor_dimension_size",
Expand Down
12 changes: 12 additions & 0 deletions torch_xla/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,15 @@ def get_num_cached_compilation_graph():
the compilation graph will be fetched into the in-memory cache.
"""
return torch_xla._XLAC._xla_get_num_cached_compilation_graph()


def clear_computation_cache():
"""Clears the XLA computation cache contents, if computation cache is initialized.
Returns:
bool: whether the cache was cleared successfully.
"""
if not torch_xla._XLAC._xla_computation_cache_is_initialized():
warnings.warn("Computation cache must be initialized to clear it.")
return False
torch_xla._XLAC._xla_computation_cache_clear()
return True