Skip to content

Commit 24767eb

Browse files
authored
Merge pull request #2 from lexming/feature-archdetect
move CPU arch specifications to separate spec files
2 parents 3eddc78 + d4d9681 commit 24767eb

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

init/arch_specs/eessi_arch_arm.spec

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ARM CPU architecture specifications
2+
# Software path in EESSI | Vendor ID | List of defining CPU features
3+
"aarch64/arm/neoverse-n1" "ARM" "asimd" # Ampere Altra
4+
"aarch64/arm/neoverse-n1" "" "asimd" # AWS Graviton2
5+
"aarch64/arm/neoverse-v1" "ARM" "asimd svei8mm"
6+
"aarch64/arm/neoverse-v1" "" "asimd svei8mm" # AWS Graviton3

init/arch_specs/eessi_arch_ppc.spec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# POWER CPU architecture specifications
2+
# Software path in EESSI | Vendor ID | List of defining CPU features
3+
"ppc64le/power9le" "" "POWER9" # IBM Power9

init/arch_specs/eessi_arch_x86.spec

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# x86_64 CPU architecture specifications
2+
# Software path in EESSI | Vendor ID | List of defining CPU features
3+
"x86_64/intel/haswell" "GenuineIntel" "avx2 fma" # Intel Haswell, Broadwell
4+
"x86_64/intel/skylake_avx512" "GenuineIntel" "avx2 fma avx512f" # Intel Skylake, Cascade Lake
5+
"x86_64/amd/zen2" "AuthenticAMD" "avx2 fma" # AMD Rome
6+
"x86_64/amd/zen3" "AuthenticAMD" "avx2 fma vaes" # AMD Milan, Milan-X

init/eessi_archdetect.sh

+36-26
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env bash
22

3-
# x86_64 CPU architecture specifications
4-
arch_x86=()
5-
arch_x86+=('("x86_64/intel/haswell" "GenuineIntel" "avx2 fma")') # Intel Haswell, Broadwell
6-
arch_x86+=('("x86_64/intel/skylake_avx512" "GenuineIntel" "avx2 fma avx512f")') # Intel Skylake, Cascade Lake
7-
arch_x86+=('("x86_64/amd/zen2" "AuthenticAMD" "avx2 fma")') # AMD Rome
8-
arch_x86+=('("x86_64/amd/zen3" "AuthenticAMD" "avx2 fma vaes")') # AMD Milan, Milan-X
9-
10-
# ARM CPU architecture specifications
11-
arch_arm=()
12-
arch_arm+=('("aarch64/arm/neoverse-n1" "ARM" "asimd")') # Ampere Altra
13-
arch_arm+=('("aarch64/arm/neoverse-n1" "" "asimd")') # AWS Graviton2
14-
arch_arm+=('("aarch64/arm/neoverse-v1" "ARM" "asimd svei8mm")')
15-
arch_arm+=('("aarch64/arm/neoverse-v1" "" "asimd svei8mm")') # AWS Graviton3
16-
17-
# Power CPU architecture specifications
18-
arch_power=()
19-
arch_power+=('("ppc64le/power9le" "" "POWER9")') # IBM Power9
3+
# Supported CPU specifications
4+
update_arch_specs(){
5+
# Add contents of given spec file into an array
6+
# 1: array with CPU arch specs
7+
# 2: spec file with the additional specs
8+
9+
[ -z "$1" ] && echo "[ERROR] update_arch_specs: missing array in argument list" >&2 && exit 1
10+
local -n arch_specs=$1
11+
12+
[ ! -f "$2" ] && echo "[ERROR] update_arch_specs: spec file not found: $2" >&2 && exit 1
13+
local spec_file="$2"
14+
while read spec_line; do
15+
# format spec line as an array and append it to array with all CPU arch specs
16+
arch_specs+=("(${spec_line})")
17+
# remove comments from spec file
18+
done < <(sed -E 's/(^|[\s\t])#.*$//g;/^\s*$/d' "$spec_file")
19+
}
2020

2121
# CPU specification of host system
2222
get_cpuinfo(){
@@ -35,14 +35,24 @@ check_flags(){
3535

3636
ARGUMENT=${1:-none}
3737

38-
cpupath () {
39-
#MACHINE_TYPE=$(uname -m)
40-
MACHINE_TYPE=${EESSI_MACHINE_TYPE:-$(uname -m)}
41-
echo cpu architecture seems to be $MACHINE_TYPE >&2
42-
[ "${MACHINE_TYPE}" == "x86_64" ] && CPU_ARCH_SPEC=("${arch_x86[@]}")
43-
[ "${MACHINE_TYPE}" == "aarch64" ] && CPU_ARCH_SPEC=("${arch_arm[@]}")
44-
[ "${MACHINE_TYPE}" == "ppc64le" ] && CPU_ARCH_SPEC=("${arch_power[@]}")
45-
[[ -z $CPU_ARCH_SPEC ]] && echo "ERROR: Unsupported CPU architecture $MACHINE_TYPE" && exit
38+
cpupath(){
39+
# Return the best matching CPU architecture from a list of supported specifications for the host CPU
40+
local CPU_ARCH_SPEC=()
41+
42+
# Identify the host CPU architecture
43+
local MACHINE_TYPE=${EESSI_MACHINE_TYPE:-$(uname -m)}
44+
echo "[INFO] cpupath: Host CPU architecture identified as $MACHINE_TYPE" >&2
45+
46+
# Populate list of supported specs for this architecture
47+
case $MACHINE_TYPE in
48+
"x86_64") local spec_file="eessi_arch_x86.spec";;
49+
"aarch64") local spec_file="eessi_arch_arm.spec";;
50+
"ppc64le") local spec_file="eessi_arch_ppc.spec";;
51+
*) echo "[ERROR] cpupath: Unsupported CPU architecture $MACHINE_TYPE" >&2 && exit 1
52+
esac
53+
# spec files are located in a subfolder with this script
54+
local base_dir=$(dirname $(realpath $0))
55+
update_arch_specs CPU_ARCH_SPEC "$base_dir/arch_specs/${spec_file}"
4656

4757
#CPU_VENDOR_TAG="vendor_id"
4858
CPU_VENDOR_TAG="vendor[ _]id"
@@ -78,6 +88,6 @@ if [ ${ARGUMENT} == "none" ]; then
7888
echo usage: $0 cpupath
7989
exit
8090
elif [ ${ARGUMENT} == "cpupath" ]; then
81-
echo $(cpupath)
91+
cpupath
8292
exit
8393
fi

0 commit comments

Comments
 (0)