Skip to content

Commit 3e9cbf5

Browse files
bmass02Google-ML-Automation
authored andcommitted
Add subprocess registration hooks to JAX profiler libraries.
PiperOrigin-RevId: 893734302
1 parent 1c9d10e commit 3e9cbf5

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

xla/python/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ nanobind_pywrap_extension(
458458
"//xla/backends/profiler:profiler_backends",
459459
"//xla/backends/profiler/cpu:python_tracer",
460460
"//xla/backends/profiler/plugin:plugin_tracer",
461+
"//xla/backends/profiler/subprocess:subprocess_registry",
461462
"//xla/backends/profiler/util:metadata_registry",
462463
"//xla/pjrt:exceptions",
463464
"//xla/pjrt:status_casters",

xla/python/_profiler.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ProfilerServer:
2424

2525
def start_server(port: int) -> ProfilerServer: ...
2626
def register_plugin_profiler(arg: CapsuleType, /) -> None: ...
27+
def register_subprocess(pid: int, port: int) -> bool: ...
28+
def unregister_subprocess(pid: int) -> bool: ...
2729

2830
class ProfilerSession:
2931
@overload

xla/python/profiler.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ limitations under the License.
2828
#include "nanobind/stl/string_view.h" // IWYU pragma: keep
2929
#include "nanobind/stl/unique_ptr.h" // IWYU pragma: keep
3030
#include "nanobind/stl/vector.h" // IWYU pragma: keep
31+
#include "xla/backends/profiler/subprocess/subprocess_registry.h"
3132
#include "xla/backends/profiler/util/metadata_registry.h"
3233
#include "xla/pjrt/c/pjrt_c_api.h"
3334
#include "xla/pjrt/exceptions.h"
@@ -176,6 +177,18 @@ NB_MODULE(_profiler, m) {
176177
") -> None"
177178
// clang-format on
178179
));
180+
m.def(
181+
"register_subprocess",
182+
[](int pid, int port) -> bool {
183+
return xla::profiler::subprocess::RegisterSubprocess(pid, port).ok();
184+
},
185+
nb::arg("pid"), nb::arg("port"));
186+
m.def(
187+
"unregister_subprocess",
188+
[](int pid) -> bool {
189+
return xla::profiler::subprocess::UnregisterSubprocess(pid).ok();
190+
},
191+
nb::arg("pid"));
179192

180193
nb::class_<ProfilerSessionWrapper> profiler_session_class(m,
181194
"ProfilerSession");

0 commit comments

Comments
 (0)