Skip to content
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

Update getDevices.py #81

Closed
wants to merge 5 commits into from
Closed
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
35 changes: 10 additions & 25 deletions script/python/getDevices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# https://stackoverflow.com/questions/4383571/importing-files-from-different-folder#answer-4383597
import json
import sys

Expand All @@ -7,30 +6,16 @@

from core.leras.device import Devices

# Initialize the environment
Devices.initialize_main_env()

all_devices = []
for device in Devices.getDevices():
deviceJson = {}
# https://stackoverflow.com/questions/25150955/python-iterating-through-object-attributes#answer-25151000
for attr, value in device.__dict__.items():
deviceJson[attr] = value
all_devices.append(deviceJson)
# all_devices.append({
# 'index': 0,
# 'tf_dev_type': 'tf_dev_type',
# 'name': 'name',
# 'total_mem': 3221225472,
# 'total_mem_gb': 3221225472 / 1024 ** 3,
# 'free_mem': 3221225472,
# 'free_mem_gb': 3221225472 / 1024 ** 3,
# })
# all_devices.append({
# 'index': 1,
# 'tf_dev_type': 'tf_dev_type',
# 'name': 'name',
# 'total_mem': 3221225472,
# 'total_mem_gb': 3221225472 / 1024 ** 3,
# 'free_mem': 3221225472,
# 'free_mem_gb': 3221225472 / 1024 ** 3,
# })
try:
for device in Devices.getDevices():
deviceJson = {attr: value for attr, value in device.__dict__.items()}
all_devices.append(deviceJson)
except Exception as e:
print(f"An error occurred: {e}", file=sys.stderr)

# Convert device data to JSON format and print it
print(json.dumps(all_devices), end='')
Loading