-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43b5569
commit 5a231d8
Showing
4 changed files
with
297 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Copyright 2022 Synnada, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime | ||
import platform | ||
import subprocess | ||
|
||
import psutil | ||
|
||
# testing_fns: dict[type[ml.Backend], Callable] = {} | ||
# array_fns: dict[type[ml.Backend], Callable] = {} | ||
|
||
|
||
try: | ||
import jax.numpy as jnp | ||
import numpy as np | ||
|
||
lambda x, y, rtol, atol: np.allclose( | ||
x.astype(jnp.float64), y.astype(jnp.float64), atol=atol, rtol=rtol | ||
) | ||
|
||
|
||
except ImportError: | ||
pass | ||
|
||
|
||
def get_processor_details(): | ||
try: | ||
# Run sysctl command to get CPU brand string | ||
result = subprocess.run( | ||
["sysctl", "-n", "machdep.cpu.brand_string"], capture_output=True, text=True | ||
) | ||
|
||
# Check if running on Apple Silicon | ||
if platform.processor() == "arm": | ||
# Get detailed chip information | ||
chip_info = subprocess.run( | ||
["sysctl", "-n", "machdep.cpu.brand_string"], | ||
capture_output=True, | ||
text=True, | ||
).stdout.strip() | ||
|
||
# Alternative way to get chip info if above doesn't work | ||
if not chip_info: | ||
system_profiler = subprocess.run( | ||
["system_profiler", "SPHardwareDataType"], | ||
capture_output=True, | ||
text=True, | ||
) | ||
for line in system_profiler.stdout.split("\n"): | ||
if "Chip" in line or "Processor" in line: | ||
chip_info = line.split(":")[-1].strip() | ||
break | ||
|
||
return f"Apple {chip_info}" | ||
else: | ||
return result.stdout.strip() | ||
except Exception: | ||
return platform.processor() | ||
|
||
|
||
def get_macos_info(): | ||
# Basic system information | ||
print("\n=== System Information ===") | ||
print(f"OS: {platform.system()} {platform.mac_ver()[0]}") | ||
print(f"Computer Name: {platform.node()}") | ||
print(f"Architecture: {platform.machine()}") | ||
|
||
# Detailed processor information | ||
processor_info = get_processor_details() | ||
print(f"Processor: {processor_info}") | ||
|
||
# Memory information | ||
mem = psutil.virtual_memory() | ||
print("\n=== Memory Information ===") | ||
print(f"Total Memory: {mem.total / (1024**3):.2f} GB") | ||
print(f"Available Memory: {mem.available / (1024**3):.2f} GB") | ||
print(f"Memory Usage: {mem.percent}%") | ||
|
||
# Detailed chip information from system_profiler | ||
try: | ||
print("\n=== Detailed Chip Information ===") | ||
system_profiler = subprocess.run( | ||
["system_profiler", "SPHardwareDataType"], capture_output=True, text=True | ||
) | ||
for line in system_profiler.stdout.split("\n"): | ||
if any( | ||
keyword in line | ||
for keyword in ["Chip:", "Processor:", "Memory:", "Neural"] | ||
): | ||
print(line.strip()) | ||
except Exception: | ||
pass | ||
|
||
# CPU information | ||
print("\n=== CPU Information ===") | ||
print(f"CPU Cores (Physical): {psutil.cpu_count(logical=False)}") | ||
print(f"CPU Cores (Logical): {psutil.cpu_count(logical=True)}") | ||
print(f"CPU Usage: {psutil.cpu_percent(interval=1)}%") | ||
|
||
# Battery information (if available) | ||
if hasattr(psutil, "sensors_battery"): | ||
battery = psutil.sensors_battery() | ||
if battery: | ||
print("\n=== Battery Information ===") | ||
print(f"Battery Percentage: {battery.percent}%") | ||
print(f"Power Plugged In: {'Yes' if battery.power_plugged else 'No'}") | ||
|
||
# Boot time | ||
boot_time = datetime.datetime.fromtimestamp(psutil.boot_time()) | ||
print("\n=== System Uptime ===") | ||
print(f"Last Boot: {boot_time.strftime('%Y-%m-%d %H:%M:%S')}") | ||
|
||
|
||
def test_info(): | ||
print("test_info") | ||
get_macos_info() | ||
print("test_info done") | ||
|
||
|
||
def test_first(): | ||
print("test_first") | ||
test_info() | ||
x = jnp.array([1, 2, 3], dtype=jnp.bfloat16) | ||
y = jnp.array([1.0, 2, 3], dtype=jnp.bfloat16) | ||
print("x", x) | ||
print("y", y) | ||
jnp.allclose(x, y, 1e-5, 1e-5) | ||
|
||
print("test_first done") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.