Skip to content

Commit fd820ad

Browse files
authored
[Disco] Expose disco.Session.shutdown through the python API (#16979)
Prior to this commit, the `SessionObj::Shutdown` method could be called from the C++ API, but could not be called through the Python API. While it is implicitly called when the `SessionObj` is destructed, Python's garbage collection may result in the destruction occurring later than expected. This commit exposes `SessionObj::Shutdown` through the Python API as `disco.Session.shutdown`, allowing it to be closed cleanly.
1 parent 1d4b9ea commit fd820ad

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

python/tvm/runtime/disco/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def empty(
142142
func = self._get_cached_method("runtime.disco.empty")
143143
return func(ShapeTuple(shape), dtype, device)
144144

145+
def shutdown(self):
146+
"""Shut down the Disco session"""
147+
_ffi_api.SessionShutdown(self) # type: ignore # pylint: disable=no-member
148+
145149
def get_global_func(self, name: str) -> DRef:
146150
"""Get a global function on workers.
147151

src/runtime/disco/session.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ TVM_REGISTER_GLOBAL("runtime.disco.SessionCallPacked").set_body([](TVMArgs args,
5252
*rv = SessionObj::FFI::CallWithPacked(
5353
self, TVMArgs(args.values + 1, args.type_codes + 1, args.num_args - 1));
5454
});
55+
TVM_REGISTER_GLOBAL("runtime.disco.SessionShutdown")
56+
.set_body_method<Session>(&SessionObj::Shutdown);
5557

5658
} // namespace runtime
5759
} // namespace tvm

0 commit comments

Comments
 (0)