From 71206409b0d5a972f841ba1e350c76f5b2bd4fa3 Mon Sep 17 00:00:00 2001 From: Jan <20126033+JanLJL@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:08:09 +0100 Subject: [PATCH 1/4] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b5fe491..733309a 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ kerncraft Loop Kernel Analysis and Performance Modeling Toolkit -This tool allows automatic analysis of loop kernels using the Execution Cache Memory (ECM) model, +This tool allows automatic analysis of loop kernels using the `Execution Cache Memory (ECM) model `_, the Roofline model and actual benchmarks. kerncraft provides a framework to investigate the data reuse and cache requirements by static code analysis. In combination with the Intel IACA tool kerncraft can give a good overview of both in-core and memory bottlenecks and use that data to From 26f61309a5fd77a16041ca269121db6322ffa64c Mon Sep 17 00:00:00 2001 From: JanLJL Date: Thu, 11 Jan 2024 14:12:38 +0100 Subject: [PATCH 2/4] changed pyyaml to ruamel.yaml --- kerncraft/cachetile.py | 5 ++++- kerncraft/kerncraft.py | 7 +++++-- kerncraft/machinemodel.py | 10 ++++++---- kerncraft/prefixedunit.py | 9 ++++----- kerncraft/roofline-plot.py | 4 +++- tests/test_kernel.py | 7 +++++-- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/kerncraft/cachetile.py b/kerncraft/cachetile.py index dd93307..2b14086 100755 --- a/kerncraft/cachetile.py +++ b/kerncraft/cachetile.py @@ -3,11 +3,12 @@ import sys import sympy -from ruamel import yaml +import ruamel.yaml from . import models from .kernel import KernelDescription from .machinemodel import MachineModel +from .prefixedunit import PrefixedUnit def create_parser(): @@ -49,6 +50,8 @@ def run(parser, args): # process kernel description description = str(args.description_file.read()) + yaml = ruamel.yaml.YAML(typ='unsafe') + yaml.register_class(PrefixedUnit) kernel = KernelDescription(yaml.load(description)) # Add constants from define arguments diff --git a/kerncraft/kerncraft.py b/kerncraft/kerncraft.py index 54e5d33..7031c16 100755 --- a/kerncraft/kerncraft.py +++ b/kerncraft/kerncraft.py @@ -16,10 +16,11 @@ import io from collections import OrderedDict -from ruamel import yaml +import ruamel.yaml from . import models from . import __version__ +from .prefixedunit import PrefixedUnit from .kernel import KernelCode, KernelDescription, symbol_pos_int from .machinemodel import MachineModel from .pycparser_utils import clean_code @@ -327,7 +328,9 @@ def run(parser, args, output_file=sys.stdout): else: description = str(args.code_file.read()) args.code_file.close() - kernel = KernelDescription(yaml.load(description, Loader=yaml.Loader), machine=machine) + yaml = ruamel.yaml.YAML(typ='unsafe') + yaml.register_class(PrefixedUnit) + kernel = KernelDescription(yaml.load(description), machine=machine) loop_indices = set([symbol_pos_int(l['index']) for l in kernel.get_loop_stack()]) # define constants diff --git a/kerncraft/machinemodel.py b/kerncraft/machinemodel.py index 02a442b..173ae58 100755 --- a/kerncraft/machinemodel.py +++ b/kerncraft/machinemodel.py @@ -15,8 +15,7 @@ from functools import lru_cache import psutil -from ruamel import yaml -from ruamel.yaml.comments import CommentedMap +import ruamel.yaml import cachesim from sympy.parsing.sympy_parser import parse_expr @@ -156,12 +155,14 @@ def __init__(self, path_to_yaml=None, machine_yaml=None, args=None): self._path = path_to_yaml self._args = args if path_to_yaml: + yaml = ruamel.yaml.YAML(typ='unsafe') + yaml.register_class(PrefixedUnit) # Load into cache and save to self._data abspath_to_yaml = os.path.abspath(path_to_yaml) if abspath_to_yaml not in self._loaded_machine_yaml: with open(path_to_yaml, 'r') as f: # Ignore ruamel unsafe loading warning, by supplying Loader parameter - self._loaded_machine_yaml[abspath_to_yaml] = yaml.load(f, Loader=yaml.Loader) + self._loaded_machine_yaml[abspath_to_yaml] = yaml.load(f) self._data = self._loaded_machine_yaml[abspath_to_yaml] elif machine_yaml: self._data = machine_yaml @@ -612,7 +613,8 @@ def dump(self, f=None): """ Return YAML string to store machine model and store to f (if path or fp passed). """ - yaml_string = yaml.dump(self._data, Dumper=yaml.Dumper) + yaml = ruamel.yaml.YAML() + yaml_string = yaml.dump(self._data) if f is None: f = self._path diff --git a/kerncraft/prefixedunit.py b/kerncraft/prefixedunit.py index 578af3b..8268a30 100755 --- a/kerncraft/prefixedunit.py +++ b/kerncraft/prefixedunit.py @@ -1,16 +1,15 @@ #!/usr/bin/env python3 import re -from ruamel import yaml +import ruamel.yaml -class PrefixedUnit(yaml.YAMLObject): +class PrefixedUnit(ruamel.yaml.YAMLObject): PREFIXES = {'k': 1e3, 'M': 1e6, 'G': 1e9, 'T': 1e13, 'P': 1e16, 'E': 1e19, 'Z': 1e21, 'Y': 1e24, '': 1} - yaml_loader = yaml.Loader - yaml_dumper = yaml.Dumper + yaml = ruamel.yaml.YAML() yaml_tag = u'!prefixed' yaml_implicit_pattern = re.compile(re.compile( r'^(?P[0-9]+(?:\.[0-9]+)?) (?P[kMGTP])?(?P.*)$')) @@ -204,4 +203,4 @@ def __ne__(self, other): # Make this tag automatic -yaml.add_implicit_resolver(PrefixedUnit.yaml_tag, PrefixedUnit.yaml_implicit_pattern) +ruamel.yaml.add_implicit_resolver(PrefixedUnit.yaml_tag, PrefixedUnit.yaml_implicit_pattern) diff --git a/kerncraft/roofline-plot.py b/kerncraft/roofline-plot.py index a896c52..1b0351d 100755 --- a/kerncraft/roofline-plot.py +++ b/kerncraft/roofline-plot.py @@ -2,7 +2,7 @@ from pprint import pprint import matplotlib.pyplot as plt -from ruamel import yaml +import ruamel.yaml from .prefixedunit import PrefixedUnit @@ -27,6 +27,8 @@ def frange(start, stop, step=1.0): {'performance': PrefixedUnit(11175000000.0, '', 'FLOP/s'), 'bandwidth': PrefixedUnit(22.35, u'G', u'B/s'), 'arithmetic intensity': 0.5, 'bw kernel': 'triad', 'level': 'L3-MEM'}]} +yaml = ruamel.yaml.YAML(typ='unsafe') +yaml.register_class(PrefixedUnit) machine = yaml.load(open('machine-files/emmy.yaml')) max_flops = machine['clock']*sum(machine['FLOPs per cycle']['DP'].values()) max_flops.unit = "FLOP/s" diff --git a/tests/test_kernel.py b/tests/test_kernel.py index d0a36d0..c1eff24 100644 --- a/tests/test_kernel.py +++ b/tests/test_kernel.py @@ -5,19 +5,22 @@ import os import unittest -from ruamel import yaml +import ruamel.yaml from kerncraft.kernel import KernelCode, KernelDescription +from kerncraft.prefixedunit import PrefixedUnit class TestKernel(unittest.TestCase): def setUp(self): + yaml = ruamel.yaml.YAML(typ='unsafe') + yaml.register_class(PrefixedUnit) with open(self._find_file('2d-5pt.c')) as f: self.twod_code = f.read() with open(self._find_file('3d-7pt.c')) as f: self.threed_code = f.read() with open(self._find_file('2d-5pt.yml')) as f: - self.twod_description = yaml.load(f.read(), Loader=yaml.Loader) + self.twod_description = yaml.load(f) with open(self._find_file('copy-2d-linearized.c')) as f: self.twod_linear = f.read() From c6749ffd3602978a3ea2cf4ac2b647532953c79d Mon Sep 17 00:00:00 2001 From: JanLJL Date: Thu, 11 Jan 2024 15:49:05 +0100 Subject: [PATCH 3/4] removed iaca_get from GHA workflow and set to use OSACA as default for tests --- .github/workflows/test-n-publish.yml | 1 - examples/machine-files/HaswellEP_E5-2695v3.yml | 2 +- examples/machine-files/SandyBridgeEP_E5-2680.yml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-n-publish.yml b/.github/workflows/test-n-publish.yml index 7d9f6c2..824b1eb 100644 --- a/.github/workflows/test-n-publish.yml +++ b/.github/workflows/test-n-publish.yml @@ -20,7 +20,6 @@ jobs: python -m pip install --upgrade pip python -m pip install codecov requests sympy python -m pip install -e . - iaca_get --I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul - name: Test run: | coverage run -p tests/all_tests.py diff --git a/examples/machine-files/HaswellEP_E5-2695v3.yml b/examples/machine-files/HaswellEP_E5-2695v3.yml index 7dad17e..b577391 100644 --- a/examples/machine-files/HaswellEP_E5-2695v3.yml +++ b/examples/machine-files/HaswellEP_E5-2695v3.yml @@ -17,8 +17,8 @@ compiler: !!omap - gcc: -O3 -march=core-avx2 -D_POSIX_C_SOURCE=200809L -fopenmp -lm -ffreestanding in-core model: !!omap - - IACA: HSW - OSACA: HSW + - IACA: HSW - LLVM-MCA: -mcpu=haswell isa: x86 diff --git a/examples/machine-files/SandyBridgeEP_E5-2680.yml b/examples/machine-files/SandyBridgeEP_E5-2680.yml index d34a0c2..5c15473 100644 --- a/examples/machine-files/SandyBridgeEP_E5-2680.yml +++ b/examples/machine-files/SandyBridgeEP_E5-2680.yml @@ -11,8 +11,8 @@ cores per NUMA domain: 8 transparent hugepage: always in-core model: !!omap - - IACA: SNB - OSACA: SNB + - IACA: SNB - LLVM-MCA: -mcpu=sandybridge isa: x86 From 004d69d53098d83b8057dbc715f44f79078b2dfc Mon Sep 17 00:00:00 2001 From: Jan <20126033+JanLJL@users.noreply.github.com> Date: Thu, 11 Jan 2024 16:19:09 +0100 Subject: [PATCH 4/4] Update README.rst --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 733309a..1dd5c09 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,9 @@ for the latest release. In order to get the `Intel Achitecture Code Analyzer (IA ``iaca_get --I-accept-the-Intel-What-If-Pre-Release-License-Agreement-and-please-take-my-soul`` +.. warning:: + As for 2023, Intel removed the download link for any IACA version. If you have any IACA version existing on your system, you can still use it with kerncraft by putting it in ``~/.kerncraft/iaca/vX.Y`` in your home directory. + Additional requirements are: * `likwid `_ (used in Benchmark model and by ``likwid_bench_auto``)