Browse Source

feat(mge/device): add python binding for get_mem_status_bytes

GitOrigin-RevId: aa0d3264d6
release-1.1
Megvii Engine Team 4 years ago
parent
commit
ab82c8da79
2 changed files with 15 additions and 0 deletions
  1. +12
    -0
      imperative/python/megengine/device.py
  2. +3
    -0
      imperative/python/src/common.cpp

+ 12
- 0
imperative/python/megengine/device.py View File

@@ -8,6 +8,7 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import os import os
import re import re
from typing import Optional


from .core._imperative_rt.common import CompNode, DeviceType from .core._imperative_rt.common import CompNode, DeviceType
from .core._imperative_rt.common import set_prealloc_config as _set_prealloc_config from .core._imperative_rt.common import set_prealloc_config as _set_prealloc_config
@@ -17,6 +18,7 @@ __all__ = [
"get_device_count", "get_device_count",
"get_default_device", "get_default_device",
"set_default_device", "set_default_device",
"get_mem_status_bytes",
"set_prealloc_config", "set_prealloc_config",
"DeviceType", "DeviceType",
] ]
@@ -92,6 +94,16 @@ def get_default_device() -> str:
return CompNode._get_default_device() return CompNode._get_default_device()




def get_mem_status_bytes(device: Optional[str] = None):
r"""
Get total and free memory on the computing device in bytes.
"""
if device is None:
device = get_default_device()
tot, free = CompNode(device).get_mem_status_bytes
return tot, free


set_default_device(os.getenv("MGE_DEFAULT_DEVICE", "xpux")) set_default_device(os.getenv("MGE_DEFAULT_DEVICE", "xpux"))






+ 3
- 0
imperative/python/src/common.cpp View File

@@ -58,6 +58,9 @@ void init_common(py::module m) {
.def_property_readonly("logical_name", [](const CompNode& cn) { .def_property_readonly("logical_name", [](const CompNode& cn) {
return cn.to_string_logical(); return cn.to_string_logical();
}) })
.def_property_readonly("get_mem_status_bytes", [](const CompNode& cn) {
return cn.get_mem_status_bytes();
})
.def("create_event", &CompNode::create_event, py::arg("flags") = 0ul) .def("create_event", &CompNode::create_event, py::arg("flags") = 0ul)
.def("_set_default_device", &set_default_device) .def("_set_default_device", &set_default_device)
.def("_get_default_device", &get_default_device) .def("_get_default_device", &get_default_device)


Loading…
Cancel
Save