forked from modular/mojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeviceinfo.mojo
68 lines (64 loc) · 2.06 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
# ===----------------------------------------------------------------------=== #
# 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.
# ===----------------------------------------------------------------------=== #
# This sample prints the current host system information using APIs from the
# sys module.
from runtime.llcl import num_cores
from sys.info import (
os_is_linux,
os_is_windows,
os_is_macos,
has_sse4,
has_avx,
has_avx2,
has_avx512f,
has_avx512_vnni,
has_neon,
is_apple_m1,
has_intel_amx,
_current_target,
_current_cpu,
_triple_attr,
)
def main():
var os = ""
if os_is_linux():
os = "linux"
elif os_is_macos():
os = "macOS"
else:
os = "windows"
let cpu = String(_current_cpu())
let arch = String(_triple_attr())
var cpu_features = String(" ")
if has_sse4():
cpu_features = cpu_features.join(" sse4")
if has_avx():
cpu_features = cpu_features.join(" avx")
if has_avx2():
cpu_features = cpu_features.join(" avx2")
if has_avx512f():
cpu_features = cpu_features.join(" avx512f")
if has_avx512_vnni():
cpu_features = cpu_features.join(" avx512_vnni")
if has_intel_amx():
cpu_features = cpu_features.join(" intel_amx")
if has_neon():
cpu_features = cpu_features.join(" neon")
if is_apple_m1():
cpu_features = cpu_features.join(" Apple M1")
print("System information: ")
print(" OS : ", os)
print(" CPU : ", cpu)
print(" Arch : ", arch)
print(" Num Cores : ", num_cores())
print(" CPU Features:", cpu_features)