-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathdeviceinfo.mojo
80 lines (75 loc) · 2.28 KB
/
deviceinfo.mojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2023, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# 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.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo %s | FileCheck %s
from sys import (
has_avx,
has_avx2,
has_avx512f,
has_intel_amx,
has_neon,
has_sse4,
has_vnni,
is_apple_m1,
is_apple_m2,
is_apple_m3,
num_logical_cores,
num_physical_cores,
os_is_linux,
os_is_macos,
os_is_windows,
)
# This sample prints the current host system information using APIs from the
# sys module.
from sys.info import _current_arch, _current_target, _triple_attr
def main():
var os = ""
if os_is_linux():
os = "linux"
elif os_is_macos():
os = "macOS"
else:
os = "windows"
var cpu = String(_current_arch())
var arch = String(_triple_attr())
var cpu_features = String("")
if has_sse4():
cpu_features += " sse4"
if has_avx():
cpu_features += " avx"
if has_avx2():
cpu_features += " avx2"
if has_avx512f():
cpu_features += " avx512f"
if has_vnni():
if has_avx512f():
cpu_features += " avx512_vnni"
else:
cpu_features += " avx_vnni"
if has_intel_amx():
cpu_features += " intel_amx"
if has_neon():
cpu_features += " neon"
if is_apple_m1():
cpu_features += " Apple M1"
if is_apple_m2():
cpu_features += " Apple M2"
if is_apple_m3():
cpu_features += " Apple M3"
print("System information: ")
print(" OS : ", os)
print(" CPU : ", cpu)
print(" Arch : ", arch)
print(" Physical Cores : ", num_physical_cores())
print(" Logical Cores : ", num_logical_cores())
# CHECK: CPU Features
print(" CPU Features :", cpu_features)