8000 Add getDeviceProperties api to torch mtia device by emasap · Pull Request #153577 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Add getDeviceProperties api to torch mtia device #153577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions aten/src/ATen/detail/MTIAHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ struct TORCH_API MTIAHooksInterface : AcceleratorHooksInterface {
return nullptr;
}

virtual PyObject* getDeviceProperties(DeviceIndex device) const {
FAIL_MTIAHOOKS_FUNC(__func__);
return nullptr;
}

virtual void emptyCache() const {
FAIL_MTIAHOOKS_FUNC(__func__);
}
Expand Down
1 change: 1 addition & 0 deletions torch/_C/__init__.pyi.in
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,7 @@ def _mtia_setCurrentStream(stream: Stream) -> None: ...
def _mtia_getDefaultStream(device: _int) -> Stream: ...
def _mtia_memoryStats(device: _int) -> dict[str, Any]: ...
def _mtia_getDeviceCapability(device: _int) -> tuple[_int, _int]: ...
def _mtia_getDeviceProperties(device: _int) -> dict[str, Any]: ...
def _mtia_emptyCache() -> None: ...
def _mtia_recordMemoryHistory(
enabled: str | None,
Expand Down
6 changes: 6 additions & 0 deletions torch/csrc/mtia/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ void initModule(PyObject* module) {
return py::reinterpret_steal<py::object>(raw_pyobject);
});

m.def("_mtia_getDeviceProperties", [](c10::DeviceIndex device_index) {
PyObject* raw_pyobject =
at::detail::getMTIAHooks().getDeviceProperties(device_index);
return py::reinterpret_steal<py::object>(raw_pyobject);
});

m.def("_mtia_emptyCache", []() { at::detail::getMTIAHooks().emptyCache(); });

m.def(
Expand Down
12 changes: 12 additions & 0 deletions torch/mtia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ def set_device(device: _device_t) -> None:
torch._C._accelerator_hooks_set_current_device(device)


def get_device_properties(device: Optional[_device_t] = None) -> dict[str, Any]:
r"""Return a dictionary of MTIA device properties

Args:
device (torch.device or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
"""
return torch._C._mtia_getDeviceProperties(_get_device_index(device, optional=True))


class device:
r"""Context-manager that changes the selected device.

Expand Down Expand Up @@ -383,6 +394,7 @@ def set_rng_state(
"max_memory_allocated",
"reset_peak_memory_stats",
"get_device_capability",
"get_device_properties",
"record_memory_history",
"snapshot",
"attach_out_of_memory_observer",
Expand Down
Loading
0