Skip to content

Commit

Permalink
remove memory_total func
Browse files Browse the repository at this point in the history
  • Loading branch information
CSY-ModelCloud committed Dec 4, 2024
1 parent a83de9d commit 62e49cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion device_smi/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
from abc import abstractmethod
from typing import Optional, Callable


class BaseDevice:
Expand Down Expand Up @@ -67,7 +68,7 @@ def __repr__(self):
return self.__str__()


def _run(args, line_start: str = None) -> str:
def _run(args, line_start: Optional[str] = None) -> str:
result = subprocess.run(
args,
stdout=subprocess.PIPE,
Expand Down
2 changes: 2 additions & 0 deletions device_smi/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, cls):
command_result = _run(["wmic", "cpu", "get", "manufacturer,name,numberofcores,numberoflogicalprocessors", "/format:csv"]).strip()
command_result = re.sub(r'\n+', '\n', command_result) # windows uses \n\n
result = command_result.split("\n")[1].split(",")

cpu_count = command_result.count('\n')
model = result[2].strip()
cpu_cores = int(result[3])
Expand All @@ -30,6 +31,7 @@ def __init__(self, cls):
command_result = _run(["wmic", "os", "get", "TotalVisibleMemorySize", "/Value", "/format:csv"]).strip()
command_result = re.sub(r'\n+', '\n', command_result)
result = command_result.split("\n")[1].split(",")

mem_total = int(result[1])
elif platform.system().lower() == 'darwin':
model = (_run(["sysctl", "-n", "machdep.cpu.brand_string"]).replace("Apple", "").strip())
Expand Down
4 changes: 1 addition & 3 deletions device_smi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Device:
def __init__(self, device):

# CPU/GPU Device
self.memory_total = None
self.type = None
self.features = None
self.vendor = None
Expand Down Expand Up @@ -86,9 +87,6 @@ def info(self):
)
return self

def memory_total(self):
return self.memory_total

def memory_used(self) -> int:
return self.device.metrics().memory_used

Expand Down
2 changes: 1 addition & 1 deletion tests/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
assert i not in dev.model, f"{i} should be removed in model"

assert dev.vendor in "amd, intel, apple", f"check vendor: {dev.vendor}"
assert dev.memory_total() > 10, f"wrong memory size: {dev.memory_total()}"
assert dev.memory_total > 10, f"wrong memory size: {dev.memory_total}"
assert dev.features is not None

memory_used = dev.memory_used()
Expand Down

0 comments on commit 62e49cb

Please sign in to comment.