mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2026-01-05 02:30:08 +01:00
enabled kerncraft marker insertion for aarch64 and more tests
This commit is contained in:
@@ -6,9 +6,12 @@ Unit tests for the CLI of OSACA and running the sample kernels in examples/
|
||||
import argparse
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from io import StringIO
|
||||
from shutil import copyfile
|
||||
|
||||
import osaca.osaca as osaca
|
||||
from osaca.parser import ParserAArch64v81, ParserX86ATT
|
||||
|
||||
|
||||
class ErrorRaisingArgumentParser(argparse.ArgumentParser):
|
||||
@@ -27,7 +30,9 @@ class TestCLI(unittest.TestCase):
|
||||
args = parser.parse_args(['--arch', 'WRONG_ARCH', self._find_file('gs', 'csx', 'gcc')])
|
||||
with self.assertRaises(ValueError):
|
||||
osaca.check_arguments(args, parser)
|
||||
args = parser.parse_args(['--import', 'WRONG_BENCH', self._find_file('gs', 'csx', 'gcc')])
|
||||
args = parser.parse_args(
|
||||
['--arch', 'csx', '--import', 'WRONG_BENCH', self._find_file('gs', 'csx', 'gcc')]
|
||||
)
|
||||
with self.assertRaises(ValueError):
|
||||
osaca.check_arguments(args, parser)
|
||||
|
||||
@@ -47,6 +52,7 @@ class TestCLI(unittest.TestCase):
|
||||
self._find_test_file('asmbench_import_aarch64.dat'),
|
||||
]
|
||||
)
|
||||
osaca.run(args, output_file=output)
|
||||
|
||||
def test_check_db(self):
|
||||
parser = osaca.create_parser(parser=ErrorRaisingArgumentParser())
|
||||
@@ -56,6 +62,49 @@ class TestCLI(unittest.TestCase):
|
||||
output = StringIO()
|
||||
osaca.run(args, output_file=output)
|
||||
|
||||
def test_get_parser(self):
|
||||
self.assertTrue(isinstance(osaca.get_asm_parser('csx'), ParserX86ATT))
|
||||
self.assertTrue(isinstance(osaca.get_asm_parser('tx2'), ParserAArch64v81))
|
||||
with self.assertRaises(ValueError):
|
||||
osaca.get_asm_parser('UNKNOWN')
|
||||
|
||||
def test_marker_insert_x86(self):
|
||||
# copy file to add markers
|
||||
name = self._find_test_file('kernel_x86.s')
|
||||
name_copy = name + '.copy.s'
|
||||
copyfile(name, name_copy)
|
||||
|
||||
user_input = ['.L10']
|
||||
output = StringIO()
|
||||
parser = osaca.create_parser()
|
||||
args = parser.parse_args(['--arch', 'csx', '--insert-marker', name_copy])
|
||||
with patch('builtins.input', side_effect=user_input):
|
||||
osaca.run(args, output_file=output)
|
||||
|
||||
lines_orig = len(open(name).readlines())
|
||||
lines_copy = len(open(name_copy).readlines())
|
||||
self.assertEqual(lines_copy, lines_orig + 5 + 4)
|
||||
# remove copy again
|
||||
os.remove(name_copy)
|
||||
|
||||
def test_marker_insert_aarch64(self):
|
||||
# copy file to add markers
|
||||
name = self._find_test_file('kernel_aarch64.s')
|
||||
name_copy = name + '.copy.s'
|
||||
copyfile(name, name_copy)
|
||||
|
||||
user_input = ['.LBB0_32', '64']
|
||||
parser = osaca.create_parser()
|
||||
args = parser.parse_args(['--arch', 'tx2', '--insert-marker', name_copy])
|
||||
with patch('builtins.input', side_effect=user_input):
|
||||
osaca.run(args)
|
||||
|
||||
lines_orig = len(open(name).readlines())
|
||||
lines_copy = len(open(name_copy).readlines())
|
||||
self.assertEqual(lines_copy, lines_orig + 3 + 2)
|
||||
# remove copy again
|
||||
os.remove(name_copy)
|
||||
|
||||
def test_examples(self):
|
||||
kernels = [
|
||||
'add',
|
||||
@@ -76,7 +125,9 @@ class TestCLI(unittest.TestCase):
|
||||
for a in archs:
|
||||
for c in comps[a]:
|
||||
with self.subTest(kernel=k, arch=a, comp=c):
|
||||
args = parser.parse_args(['--arch', a, self._find_file(k, a, c)])
|
||||
args = parser.parse_args(
|
||||
['--arch', a, self._find_file(k, a, c), '--export-graph', '/dev/null']
|
||||
)
|
||||
output = StringIO()
|
||||
osaca.run(args, output_file=output)
|
||||
self.assertTrue('WARNING' not in output.getvalue())
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
add x10, x10, #64 // =64
|
||||
adds x12, x12, #1 // =1
|
||||
fmov s0, -1.0e+0
|
||||
fmov s1, #2.0e+2f
|
||||
prfm pldl1keep, [x26, #2112]
|
||||
b.ne .LBB0_32
|
||||
// OSACA-END
|
||||
fmov s1, #2.0e+2f
|
||||
prfm pldl1keep, [x26, #2112]
|
||||
|
||||
@@ -10,8 +10,10 @@ from subprocess import call
|
||||
|
||||
import networkx as nx
|
||||
|
||||
from osaca.osaca import get_unmatched_instruction_ratio
|
||||
from osaca.parser import AttrDict, ParserAArch64v81, ParserX86ATT
|
||||
from osaca.semantics import INSTR_FLAGS, ArchSemantics, KernelDG, MachineModel
|
||||
from osaca.semantics import (INSTR_FLAGS, ArchSemantics, KernelDG,
|
||||
MachineModel, reduce_to_section)
|
||||
|
||||
|
||||
class TestSemanticTools(unittest.TestCase):
|
||||
@@ -33,8 +35,10 @@ class TestSemanticTools(unittest.TestCase):
|
||||
self.code_x86 = f.read()
|
||||
with open(self._find_file('kernel_aarch64.s')) as f:
|
||||
self.code_AArch64 = f.read()
|
||||
self.kernel_x86 = self.parser_x86.parse_file(self.code_x86)
|
||||
self.kernel_AArch64 = self.parser_AArch64.parse_file(self.code_AArch64)
|
||||
self.kernel_x86 = reduce_to_section(self.parser_x86.parse_file(self.code_x86), 'x86')
|
||||
self.kernel_AArch64 = reduce_to_section(
|
||||
self.parser_AArch64.parse_file(self.code_AArch64), 'aarch64'
|
||||
)
|
||||
|
||||
# set up machine models
|
||||
self.machine_model_csx = MachineModel(
|
||||
@@ -180,7 +184,7 @@ class TestSemanticTools(unittest.TestCase):
|
||||
test_mm_x86.get_load_throughput(
|
||||
{'base': {'name': 'x'}, 'offset': None, 'index': None, 'scale': 1}
|
||||
),
|
||||
[[1, '23'], [1, ['2D', '3D']]]
|
||||
[[1, '23'], [1, ['2D', '3D']]],
|
||||
)
|
||||
|
||||
# test adding port
|
||||
@@ -232,15 +236,18 @@ class TestSemanticTools(unittest.TestCase):
|
||||
# x86
|
||||
kernel_fixed = deepcopy(self.kernel_x86)
|
||||
self.semantics_csx.add_semantics(kernel_fixed)
|
||||
self.assertEqual(get_unmatched_instruction_ratio(kernel_fixed), 0)
|
||||
kernel_optimal = deepcopy(kernel_fixed)
|
||||
self.semantics_csx.assign_optimal_throughput(kernel_optimal)
|
||||
tp_fixed = self.semantics_csx.get_throughput_sum(kernel_fixed)
|
||||
tp_optimal = self.semantics_csx.get_throughput_sum(kernel_optimal)
|
||||
self.assertNotEqual(tp_fixed, tp_optimal)
|
||||
self.assertTrue(max(tp_optimal) <= max(tp_fixed))
|
||||
|
||||
# arm
|
||||
kernel_fixed = deepcopy(self.kernel_AArch64)
|
||||
self.semantics_tx2.add_semantics(kernel_fixed)
|
||||
self.assertEqual(get_unmatched_instruction_ratio(kernel_fixed), 0)
|
||||
kernel_optimal = deepcopy(kernel_fixed)
|
||||
self.semantics_tx2.assign_optimal_throughput(kernel_optimal)
|
||||
tp_fixed = self.semantics_tx2.get_throughput_sum(kernel_fixed)
|
||||
|
||||
Reference in New Issue
Block a user