Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instruction_check: enhancement #405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions BM/instruction-check/auto_gen_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python
import os
from feature_list import cpuid_info
from feature_list import feature_list
from feature_list import get_platform

# Template string, used to generate code for each test class
class_template = """
Expand Down Expand Up @@ -29,8 +30,14 @@ def generate_cpuid_tests():
expected_result = 0
''')
# For each feature in feature_list.py generates a test class
for feature, args in cpuid_info.items():
class_code = class_template.format(class_name=feature, args=args)
f.write(class_code)
feature_name_list = feature_list.keys()
platform = get_platform()
for feature_name in feature_name_list:
if platform in feature_list[feature_name]["platforms"]:
args = feature_list[feature_name]["cpuid"]
class_code = class_template.format(class_name=feature_name, args=args)
f.write(class_code)
else:
continue

generate_cpuid_tests()
277 changes: 227 additions & 50 deletions BM/instruction-check/feature_list.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,228 @@
cpuid_info = {
"AESNI": ['1', '0', '0', '0', 'c', '25'],
"XSAVE": ['1', '0', '0', '0', 'c', '26'],
"FSGSBASE": ['7', '0', '0', '0', 'b', '0'],
"SMEP": ['7', '0', '0', '0', 'b', '7'],
"RDT_A": ['7', '0', '0', '0', 'b', '15'],
"AVX512_IFMA": ['7', '0', '0', '0', 'b', '21'],
"SHA_NI": ['7', '0', '0', '0', 'b', '29'],
"AVX512_VBMI": ['7', '0', '0', '0', 'c', '1'],
"UMIP": ['7', '0', '0', '0', 'c', '2'],
"WAITPKG": ['7', '0', '0', '0', 'c', '5'],
"AVX512_VBMI2": ['7', '0', '0', '0', 'c', '6'],
"CET_SS": ['7', '0', '0', '0', 'c', '7'],
"GFNI": ['7', '0', '0', '0', 'c', '8'],
"VAES": ['7', '0', '0', '0', 'c', '9'],
"AVX512_VNNI": ['7', '0', '0', '0', 'c', '11'],
"AVX512_BITALG": ['7', '0', '0', '0', 'c', '12'],
"RDPID": ['7', '0', '0', '0', 'c', '22'],
"KL": ['7', '0', '0', '0', 'c', '23'],
"CLDEMOTE": ['7', '0', '0', '0', 'c', '25'],
"MOVDIRI": ['7', '0', '0', '0', 'c', '27'],
"MOVDIR64B": ['7', '0', '0', '0', 'c', '28'],
"PKS": ['7', '0', '0', '0', 'c', '31'],
"UINTR": ['7', '0', '0', '0', 'd', '5'],
"AVX512_VP2INTERSECT": ['7', '0', '0', '0', 'd', '8'],
"SERIALIZE": ['7', '0', '0', '0', 'd', '14'],
"TSXLDTRK": ['7', '0', '0', '0', 'd', '16'],
"CET_IBT": ['7', '0', '0', '0', 'd', '20'],
"AMX_BF16": ['7', '0', '0', '0', 'd', '22'],
"AVX512_FP16": ['7', '0', '0', '0', 'd', '23'],
"AMX_TILE": ['7', '0', '0', '0', 'd', '24'],
"AMX_INT8": ['7', '0', '0', '0', 'd', '25'],
"AVX_VNNI": ['7', '0', '1', '0', 'a', '4'],
"CMPCCXADD": ['7', '0', '1', '0', 'a', '7'],
"FRED": ['7', '0', '1', '0', 'a', '17'],
"WRMSRNS": ['7', '0', '1', '0', 'a', '19'],
"AMX_FP16": ['7', '0', '1', '0', 'a', '21'],
"AVX_IFMA": ['7', '0', '1', '0', 'a', '23'],
"AVX_VNNI_INT8": ['7', '0', '1', '0', 'd', '4'],
"AVX_NE_CONVERT": ['7', '0', '1', '0', 'd', '5'],
"PREFETCHI": ['7', '0', '1', '0', 'd', '14'],
"XFD": ['d', '0', '1', '0', 'a', '4'],
"KL_BITMAP0": ['19', '0', '0', '0', 'a', '0'],
"KL_BITMAP1": ['19', '0', '0', '0', 'a', '1'],
"KL_BITMAP2": ['19', '0', '0', '0', 'a', '2'],
"AESKLE": ['19', '0', '0', '0', 'b', '0'],
"AES_WIDE": ['19', '0', '0', '0', 'b', '2'],
"KL_IWKEYBACKUP": ['19', '0', '0', '0', 'b', '4'],
"KL_RANDOM_IWKEY": ['19', '0', '0', '0', 'c', '1']
# Add more cpuid_info here
import subprocess

cpu_family_mapping = {
"SPR" : {0x8F, 143},
"EMR" : {0xCF, 207},
"GNR" : {0xAD, 173},
"SRF" : {0xAF, 175},
"CWF" : {0xDD, 221}
}

feature_list = {
"AESNI": {
"cpuid": ['1', '0', '0', '0', 'c', '25'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"XSAVE": {
"cpuid": ['1', '0', '0', '0', 'c', '26'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"FSGSBASE": {
"cpuid": ['7', '0', '0', '0', 'b', '0'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"SMEP": {
"cpuid": ['7', '0', '0', '0', 'b', '7'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"RDT_A": {
"cpuid": ['7', '0', '0', '0', 'b', '15'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AVX512_IFMA": {
"cpuid": ['7', '0', '0', '0', 'b', '21'],
"platforms": {"SPR", "EMR", "GNR"}
},
"SHA_NI": {
"cpuid": ['7', '0', '0', '0', 'b', '29'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AVX512_VBMI": {
"cpuid": ['7', '0', '0', '0', 'c', '1'],
"platforms": {"SPR", "EMR", "GNR"}
},
"UMIP": {
"cpuid": ['7', '0', '0', '0', 'c', '2'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"WAITPKG": {
"cpuid": ['7', '0', '0', '0', 'c', '5'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AVX512_VBMI2": {
"cpuid": ['7', '0', '0', '0', 'c', '6'],
"platforms": {"SPR", "EMR", "GNR"}
},
"CET_SS": {
"cpuid": ['7', '0', '0', '0', 'c', '7'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"GFNI": {
"cpuid": ['7', '0', '0', '0', 'c', '8'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"VAES": {
"cpuid": ['7', '0', '0', '0', 'c', '9'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AVX512_VNNI": {
"cpuid": ['7', '0', '0', '0', 'c', '11'],
"platforms": {"SPR", "EMR", "GNR"}
},
"AVX512_BITALG": {
"cpuid": ['7', '0', '0', '0', 'c', '12'],
"platforms": {"SPR", "EMR", "GNR"}
},
"RDPID": {
"cpuid": ['7', '0', '0', '0', 'c', '22'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"KL": {
"cpuid": ['7', '0', '0', '0', 'c', '23'],
"platforms": {}
},
"CLDEMOTE": {
"cpuid": ['7', '0', '0', '0', 'c', '25'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"MOVDIRI": {
"cpuid": ['7', '0', '0', '0', 'c', '27'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"MOVDIR64B": {
"cpuid": ['7', '0', '0', '0', 'c', '28'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"PKS": {
"cpuid": ['7', '0', '0', '0', 'c', '31'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"UINTR": {
"cpuid": ['7', '0', '0', '0', 'd', '5'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AVX512_VP2INTERSECT": {
"cpuid": ['7', '0', '0', '0', 'd', '8'],
"platforms": {}
},
"SERIALIZE": {
"cpuid": ['7', '0', '0', '0', 'd', '14'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"TSXLDTRK": {
"cpuid": ['7', '0', '0', '0', 'd', '16'],
"platforms": {"SPR", "EMR", "GNR"}
},
"CET_IBT": {
"cpuid": ['7', '0', '0', '0', 'd', '20'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"AMX_BF16": {
"cpuid": ['7', '0', '0', '0', 'd', '22'],
"platforms": {"SPR", "EMR", "GNR"}
},
"AVX512_FP16": {
"cpuid": ['7', '0', '0', '0', 'd', '23'],
"platforms": {"SPR", "EMR", "GNR"}
},
"AMX_TILE": {
"cpuid": ['7', '0', '0', '0', 'd', '24'],
"platforms": {"SPR", "EMR", "GNR"}
},
"AMX_INT8": {
"cpuid": ['7', '0', '0', '0', 'd', '25'],
"platforms": {"SPR", "EMR", "GNR"}
},
"AVX_VNNI": {
"cpuid": ['7', '0', '1', '0', 'a', '4'],
"platforms": {"SPR", "EMR", "GNR", "SRF", "CWF"}
},
"CMPCCXADD": {
"cpuid": ['7', '0', '1', '0', 'a', '7'],
"platforms": {"SRF", "CWF"}
},
"FRED": {
"cpuid": ['7', '0', '1', '0', 'a', '17'],
"platforms": {"CWF"}
},
"WRMSRNS": {
"cpuid": ['7', '0', '1', '0', 'a', '19'],
"platforms": {"SRF", "CWF"}
},
"AMX_FP16": {
"cpuid": ['7', '0', '1', '0', 'a', '21'],
"platforms": {"GNR"}
},
"AVX_IFMA": {
"cpuid": ['7', '0', '1', '0', 'a', '23'],
"platforms": {"SRF", "CWF"}
},
"AVX_VNNI_INT8": {
"cpuid": ['7', '0', '1', '0', 'd', '4'],
"platforms": {"SRF", "CWF"}
},
"AVX_NE_CONVERT": {
"cpuid": ['7', '0', '1', '0', 'd', '5'],
"platforms": {"SRF", "CWF"}
},
"PREFETCHI": {
"cpuid": ['7', '0', '1', '0', 'd', '14'],
"platforms": {"GNR"}
},
"XFD": {
"cpuid": ['d', '0', '1', '0', 'a', '4'],
"platforms": {"SPR", "EMR", "GNR"}
},
"KL_BITMAP0": {
"cpuid": ['19', '0', '0', '0', 'a', '0'],
"platforms": {}
},
"KL_BITMAP1": {
"cpuid": ['19', '0', '0', '0', 'a', '1'],
"platforms": {}
},
"KL_BITMAP2": {
"cpuid": ['19', '0', '0', '0', 'a', '2'],
"platforms": {}
},
"AESKLE": {
"cpuid": ['19', '0', '0', '0', 'b', '0'],
"platforms": {}
},
"AES_WIDE": {
"cpuid": ['19', '0', '0', '0', 'b', '2'],
"platforms": {}
},
"KL_IWKEYBACKUP": {
"cpuid": ['19', '0', '0', '0', 'b', '4'],
"platforms": {}
},
"KL_RANDOM_IWKEY": {
"cpuid": ['19', '0', '0', '0', 'c', '1'],
"platforms": {}
}
# Add more feature_info here
}

def get_cpu_family_id():
# Run the 'lscpu' command and capture its output
result = subprocess.run(['/usr/bin/lscpu'], capture_output=True, text=True, check=True)

# Split the output into lines
output_lines = result.stdout.splitlines()

# Find the line containing "Model:" and extract the family ID
for line in output_lines:
if "Model:" in line:
# Assuming the family ID follows 'Model:' and is separated by spaces
family_id = line.split(':')[1].strip()
return int(family_id)

def get_platform():
cpu_family_id = get_cpu_family_id()
platform = None
for key, values in cpu_family_mapping.items():
if cpu_family_id in values:
platform = key
break
return platform
32 changes: 21 additions & 11 deletions BM/instruction-check/instruction_check.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
#!/usr/bin/python

import sys
import os

from avocado.core.job import Job
from avocado.core.nrunner.runnable import Runnable
from avocado.core.suite import TestSuite
from feature_list import cpuid_info
from feature_list import feature_list
from feature_list import get_platform

current_dir = os.path.dirname(os.path.realpath(__file__))
BM_dir = os.path.dirname(current_dir)
source_dir = f"{BM_dir}/tools/cpuid_check"

def main():
feature_name_list = cpuid_info.keys()
feature_name_list = feature_list.keys()
platform = get_platform()

tests = []
for feature_name in feature_name_list:
if platform in feature_list[feature_name]["platforms"]:
args = feature_list[feature_name]["cpuid"]
runnable = Runnable("exec-test", f"{source_dir}/cpuid_check", *args, identifier=feature_name)
tests.append(runnable)
else:
continue

suites = []
suite = TestSuite(name="Check", tests=tests)

for feature_name in feature_name_list:
args = cpuid_info[feature_name]
runnable = Runnable("exec-test", "../tools/cpuid_check/cpuid_check", *args)
suite = TestSuite(name=feature_name, tests=[runnable])
suites.append(suite)

# Run the test suites
with Job(test_suites=suites) as j:
with Job(test_suites=[suite]) as j:
sys.exit(j.run())

if __name__=="__main__":
Expand Down