From 4ad1150372aa1b3ecced8438c50b625ae6433f55 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Fri, 10 Feb 2023 15:15:42 +0000 Subject: [PATCH] stdlib: Add the LooppointCsvResource resource This resource wraps the LooppointCsvLoader class so it may be obtained as a specialized resource via gem5 resources. Relevant tests and config scripts have been updated. Change-Id: Ib8e5ff5500fb1560951c9c0110e3c3aec8ca3c42 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67857 Maintainer: Bobby Bruce Reviewed-by: Bobby Bruce Tested-by: kokoro --- .../create-looppoint-checkpoints.py | 12 ++-------- src/python/gem5/resources/resource.py | 22 +++++++++++++++++++ .../pyunit_resource_specialization.py | 21 ++++++++++++++++++ .../refs/resource-specialization.json | 9 ++++++++ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/configs/example/gem5_library/looppoints/create-looppoint-checkpoints.py b/configs/example/gem5_library/looppoints/create-looppoint-checkpoints.py index f967aa56e4..6c23d38c7d 100644 --- a/configs/example/gem5_library/looppoints/create-looppoint-checkpoints.py +++ b/configs/example/gem5_library/looppoints/create-looppoint-checkpoints.py @@ -61,7 +61,7 @@ from pathlib import Path from gem5.simulate.exit_event_generators import ( looppoint_save_checkpoint_generator, ) -from gem5.resources.looppoint import LooppointCsvLoader + import argparse requires(isa_required=ISA.X86) @@ -103,15 +103,6 @@ processor = SimpleProcessor( num_cores=9, ) -looppoint = LooppointCsvLoader( - # Pass in the LoopPoint data file - looppoint_file=Path( - obtain_resource( - "x86-matrix-multiply-omp-100-8-global-pinpoints" - ).get_local_path() - ) -) - board = SimpleBoard( clk_freq="3GHz", processor=processor, @@ -119,6 +110,7 @@ board = SimpleBoard( cache_hierarchy=cache_hierarchy, ) +looppoint = obtain_resource("x86-matrix-multiply-omp-100-8-global-pinpoints") board.set_se_looppoint_workload( binary=obtain_resource("x86-matrix-multiply-omp"), arguments=[100, 8], diff --git a/src/python/gem5/resources/resource.py b/src/python/gem5/resources/resource.py index 678497eaa7..0cf58800f2 100644 --- a/src/python/gem5/resources/resource.py +++ b/src/python/gem5/resources/resource.py @@ -31,6 +31,7 @@ from m5.util import warn, fatal from .downloader import get_resource, get_resources_json_obj +from .looppoint import LooppointCsvLoader from ..isas import ISA, get_isa_from_str from typing import Optional, Dict, Union, Type, Tuple, List @@ -394,6 +395,26 @@ class SimpointResource(AbstractResource): return warmup_list +class LooppointCsvResource(FileResource, LooppointCsvLoader): + """This Looppoint resource used to create a Looppoint resource from a + pinpoints CSV file""" + + def __init__( + self, + local_path: str, + documentation: Optional[str] = None, + source: Optional[str] = None, + **kwargs, + ): + FileResource.__init__( + self, + local_path=local_path, + documentation=documentation, + source=source, + ) + LooppointCsvLoader.__init__(self, pinpoints_file=Path(local_path)) + + class SimpointDirectoryResource(SimpointResource): """A Simpoint diretory resource. This Simpoint Resource assumes the existance of a directory containing a simpoint file and a weight file.""" @@ -714,4 +735,5 @@ _get_resource_json_type_map = { "simpoint": SimpointResource, "simpoint-directory": SimpointDirectoryResource, "resource": Resource, + "looppoint-pinpoint-csv": LooppointCsvResource, } diff --git a/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py b/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py index f31e35d719..5c60eb5c4a 100644 --- a/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py +++ b/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py @@ -29,6 +29,7 @@ import unittest from pathlib import Path from gem5.resources.resource import * +from gem5.resources.looppoint import LooppointCsvLoader from gem5.isas import ISA @@ -235,3 +236,23 @@ class ResourceSpecializationSuite(unittest.TestCase): "directory-example documentation.", resource.get_documentation() ) self.assertIsNone(resource.get_source()) + + def test_looppoint_pinpoints_resource(self) -> None: + """Tests the creation of LooppointCreatorCSVResource via a Looppoint + pinpoints csv file.""" + + resource = obtain_resource( + resource_name="looppoint-pinpoint-csv-resource", + resource_directory=self.get_resource_dir(), + ) + + self.assertIsInstance(resource, LooppointCsvResource) + + # The LooppointCreatorCSVResource should be a subtype of + # LooppointCsvLoader. + self.assertIsInstance(resource, LooppointCsvLoader) + + self.assertEquals( + "A looppoint pinpoints csv file.", resource.get_documentation() + ) + self.assertIsNone(resource.get_source()) diff --git a/tests/pyunit/stdlib/resources/refs/resource-specialization.json b/tests/pyunit/stdlib/resources/refs/resource-specialization.json index 01671b564b..bfe0d4a448 100644 --- a/tests/pyunit/stdlib/resources/refs/resource-specialization.json +++ b/tests/pyunit/stdlib/resources/refs/resource-specialization.json @@ -108,6 +108,15 @@ "warmup_interval": 23445, "simpoint_list" : [2,3,4,15], "weight_list" : [0.1, 0.2, 0.4, 0.3] + }, + { + "type": "looppoint-pinpoint-csv", + "name": "looppoint-pinpoint-csv-resource", + "documentation" : "A looppoint pinpoints csv file.", + "is_zipped" : false, + "md5sum" : "199ab22dd463dc70ee2d034bfe045082", + "url": "http://dist.gem5.org/dist/develop/pinpoints/x86-matrix-multiply-omp-100-8-global-pinpoints-20230127", + "source" : null } ] }