From 5d0dd10cfa04967d8e6b9814f03a09b4b901a362 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Fri, 10 Feb 2023 21:01:34 +0000 Subject: [PATCH] stdlib: Add LooppointJsonResource resource This resource wraps the LooppointJsonLoader class for use with gem5 resources. Change-Id: Ic00d689c289330bab8564abc4c68a9047d5096e0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67858 Reviewed-by: Bobby Bruce Tested-by: kokoro Maintainer: Bobby Bruce --- src/python/gem5/resources/resource.py | 23 +++++++++++++++- .../pyunit_resource_specialization.py | 27 ++++++++++++++++++- .../refs/resource-specialization.json | 10 +++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/python/gem5/resources/resource.py b/src/python/gem5/resources/resource.py index 0cf58800f2..9cba9cf88f 100644 --- a/src/python/gem5/resources/resource.py +++ b/src/python/gem5/resources/resource.py @@ -31,7 +31,7 @@ from m5.util import warn, fatal from .downloader import get_resource, get_resources_json_obj -from .looppoint import LooppointCsvLoader +from .looppoint import LooppointCsvLoader, LooppointJsonLoader from ..isas import ISA, get_isa_from_str from typing import Optional, Dict, Union, Type, Tuple, List @@ -415,6 +415,26 @@ class LooppointCsvResource(FileResource, LooppointCsvLoader): LooppointCsvLoader.__init__(self, pinpoints_file=Path(local_path)) +class LooppointJsonResource(FileResource, LooppointJsonLoader): + def __init__( + self, + local_path: str, + region_id: Optional[Union[str, int]] = None, + documentation: Optional[str] = None, + source: Optional[str] = None, + **kwargs, + ): + FileResource.__init__( + self, + local_path=local_path, + documentation=documentation, + source=source, + ) + LooppointJsonLoader.__init__( + self, looppoint_file=local_path, region_id=region_id + ) + + class SimpointDirectoryResource(SimpointResource): """A Simpoint diretory resource. This Simpoint Resource assumes the existance of a directory containing a simpoint file and a weight file.""" @@ -736,4 +756,5 @@ _get_resource_json_type_map = { "simpoint-directory": SimpointDirectoryResource, "resource": Resource, "looppoint-pinpoint-csv": LooppointCsvResource, + "looppoint-json": LooppointJsonResource, } diff --git a/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py b/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py index 5c60eb5c4a..660bf5f38f 100644 --- a/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py +++ b/tests/pyunit/stdlib/resources/pyunit_resource_specialization.py @@ -29,7 +29,12 @@ import unittest from pathlib import Path from gem5.resources.resource import * -from gem5.resources.looppoint import LooppointCsvLoader + +from gem5.resources.looppoint import ( + LooppointCsvLoader, + LooppointJsonLoader, +) + from gem5.isas import ISA @@ -256,3 +261,23 @@ class ResourceSpecializationSuite(unittest.TestCase): "A looppoint pinpoints csv file.", resource.get_documentation() ) self.assertIsNone(resource.get_source()) + + def test_looppoint_json_restore_resource(self) -> None: + """Tests the creation of LooppointJsonResource via a + Looppoint JSON file.""" + + resource = obtain_resource( + resource_name="looppoint-json-restore-resource-region-1", + resource_directory=self.get_resource_dir(), + ) + + self.assertIsInstance(resource, LooppointJsonResource) + self.assertIsInstance(resource, LooppointJsonLoader) + + self.assertEquals(1, len(resource.get_regions())) + self.assertTrue("1" in resource.get_regions()) + + self.assertEquals( + "A looppoint json file resource.", 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 bfe0d4a448..c4d5eb4714 100644 --- a/tests/pyunit/stdlib/resources/refs/resource-specialization.json +++ b/tests/pyunit/stdlib/resources/refs/resource-specialization.json @@ -117,6 +117,16 @@ "md5sum" : "199ab22dd463dc70ee2d034bfe045082", "url": "http://dist.gem5.org/dist/develop/pinpoints/x86-matrix-multiply-omp-100-8-global-pinpoints-20230127", "source" : null + }, + { + "type": "looppoint-json", + "name": "looppoint-json-restore-resource-region-1", + "documentation" : "A looppoint json file resource.", + "is_zipped" : false, + "region_id" : "1", + "md5sum" : "a71ed64908b082ea619b26b940a643c1", + "url": "http://dist.gem5.org/dist/develop/looppoints/x86-matrix-multiply-omp-100-8-looppoint-json-20230128", + "source" : null } ] }