1
1
#! /usr/bin/env bash
2
2
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
+ }
20
20
21
21
# CPU specification of host system
22
22
get_cpuinfo (){
@@ -35,14 +35,24 @@ check_flags(){
35
35
36
36
ARGUMENT=${1:- none}
37
37
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} "
46
56
47
57
# CPU_VENDOR_TAG="vendor_id"
48
58
CPU_VENDOR_TAG=" vendor[ _]id"
@@ -78,6 +88,6 @@ if [ ${ARGUMENT} == "none" ]; then
78
88
echo usage: $0 cpupath
79
89
exit
80
90
elif [ ${ARGUMENT} == " cpupath" ]; then
81
- echo $( cpupath)
91
+ cpupath
82
92
exit
83
93
fi
0 commit comments