Add feature to output citations automatically based on configuration (#90)
This change adds a new file to m5out which is citations.bib. This file will contain the citations to the papers which describe the aspects of the gem5 simulator that the simulation uses. In other words, each simulation configuration could generate a different bib file referencing different works. Each SimObject can now have a set of citations associated with it. After the system is built (in `instantiate`), the citations.bib file is created by parsing all SimObjects that have been instantiated and taking the union of their associated citations. This commit is not meant to add all citations, but to act as an example for others to add more citations to gem5. Change-Id: Icd5c46fd9ee44adbeec1fea162657f5716f7e5ef Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
@@ -311,6 +311,7 @@ PySource('gem5.utils.multiprocessing',
|
||||
PySource('', 'importer.py')
|
||||
PySource('m5', 'm5/__init__.py')
|
||||
PySource('m5', 'm5/SimObject.py')
|
||||
PySource('m5', 'm5/citations.py')
|
||||
PySource('m5', 'm5/core.py')
|
||||
PySource('m5', 'm5/debug.py')
|
||||
PySource('m5', 'm5/event.py')
|
||||
|
||||
@@ -47,6 +47,8 @@ import m5
|
||||
from m5.util import *
|
||||
from m5.util.pybind import *
|
||||
|
||||
from m5.citations import gem5_citations
|
||||
|
||||
# Use the pyfdt and not the helper class, because the fdthelper
|
||||
# relies on the SimObject definition
|
||||
from m5.ext.pyfdt import pyfdt
|
||||
@@ -215,6 +217,8 @@ class MetaSimObject(type):
|
||||
cls._instantiated = False # really instantiated, cloned, or subclassed
|
||||
cls._init_called = False # Used to check if __init__ overridden
|
||||
|
||||
cls._citations = gem5_citations # Default to gem5's citations
|
||||
|
||||
# We don't support multiple inheritance of sim objects. If you want
|
||||
# to, you must fix multidict to deal with it properly. Non sim-objects
|
||||
# are ok, though
|
||||
|
||||
191
src/python/m5/citations.py
Normal file
191
src/python/m5/citations.py
Normal file
@@ -0,0 +1,191 @@
|
||||
# Copyright (c) 2023 The Regents of The University of California
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met: redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer;
|
||||
# redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution;
|
||||
# neither the name of the copyright holders nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Type
|
||||
|
||||
import m5.options
|
||||
|
||||
|
||||
def add_citation(sim_obj_cls: Type["SimObject"], citation: str):
|
||||
"""Add a citation to a SimObject class.
|
||||
|
||||
:param sim_obj_cls: The SimObject class to add the citation to.
|
||||
:param citation: The citation to add. Should be bibtex compatible
|
||||
entry or entries
|
||||
|
||||
This function will encode the citation into the SimObject class and it
|
||||
will be included in the citations in the output directory when the
|
||||
SimObject is used. If you have multiple citations, then you should include
|
||||
one multiline string with all of the citations.
|
||||
"""
|
||||
|
||||
sim_obj_cls._citations += citation
|
||||
|
||||
|
||||
def gather_citations(root: "SimObject"):
|
||||
"""Based on the root SimObject, walk the object hierarchy and gather all
|
||||
of the citations together and then print them to citations.bib in the
|
||||
output directory.
|
||||
"""
|
||||
|
||||
citations = {}
|
||||
for obj in root.descendants():
|
||||
loc = 0
|
||||
while loc >= 0:
|
||||
key, cite, loc = _get_next_key_entry(obj._citations, loc)
|
||||
# If a key repeats, then just overwrite it
|
||||
citations[key] = cite
|
||||
|
||||
with open(Path(m5.options.outdir) / "citations.bib", "w") as output:
|
||||
output.writelines(citations.values())
|
||||
|
||||
|
||||
def _get_next_key_entry(citations: str, loc: int = 0):
|
||||
"""Return the key, the citation, and the end of the citation location"""
|
||||
|
||||
start = citations.find("@", loc)
|
||||
key_start = citations.find("{", start)
|
||||
key_end = citations.find(",", key_start)
|
||||
end = citations.find("@", start + 1)
|
||||
if end == -1:
|
||||
end = len(citations)
|
||||
next = -1
|
||||
else:
|
||||
next = end
|
||||
|
||||
return citations[key_start:key_end], citations[start:end], next
|
||||
|
||||
|
||||
gem5_citations = """@article{Binkert:2011:gem5,
|
||||
author = {Nathan L. Binkert and
|
||||
Bradford M. Beckmann and
|
||||
Gabriel Black and
|
||||
Steven K. Reinhardt and
|
||||
Ali G. Saidi and
|
||||
Arkaprava Basu and
|
||||
Joel Hestness and
|
||||
Derek Hower and
|
||||
Tushar Krishna and
|
||||
Somayeh Sardashti and
|
||||
Rathijit Sen and
|
||||
Korey Sewell and
|
||||
Muhammad Shoaib Bin Altaf and
|
||||
Nilay Vaish and
|
||||
Mark D. Hill and
|
||||
David A. Wood},
|
||||
title = {The gem5 simulator},
|
||||
journal = {{SIGARCH} Comput. Archit. News},
|
||||
volume = {39},
|
||||
number = {2},
|
||||
pages = {1--7},
|
||||
year = {2011},
|
||||
url = {https://doi.org/10.1145/2024716.2024718},
|
||||
doi = {10.1145/2024716.2024718}
|
||||
}
|
||||
@article{Lowe-Power:2020:gem5-20,
|
||||
author = {Jason Lowe{-}Power and
|
||||
Abdul Mutaal Ahmad and
|
||||
Ayaz Akram and
|
||||
Mohammad Alian and
|
||||
Rico Amslinger and
|
||||
Matteo Andreozzi and
|
||||
Adri{\`{a}} Armejach and
|
||||
Nils Asmussen and
|
||||
Srikant Bharadwaj and
|
||||
Gabe Black and
|
||||
Gedare Bloom and
|
||||
Bobby R. Bruce and
|
||||
Daniel Rodrigues Carvalho and
|
||||
Jer{\'{o}}nimo Castrill{\'{o}}n and
|
||||
Lizhong Chen and
|
||||
Nicolas Derumigny and
|
||||
Stephan Diestelhorst and
|
||||
Wendy Elsasser and
|
||||
Marjan Fariborz and
|
||||
Amin Farmahini Farahani and
|
||||
Pouya Fotouhi and
|
||||
Ryan Gambord and
|
||||
Jayneel Gandhi and
|
||||
Dibakar Gope and
|
||||
Thomas Grass and
|
||||
Bagus Hanindhito and
|
||||
Andreas Hansson and
|
||||
Swapnil Haria and
|
||||
Austin Harris and
|
||||
Timothy Hayes and
|
||||
Adrian Herrera and
|
||||
Matthew Horsnell and
|
||||
Syed Ali Raza Jafri and
|
||||
Radhika Jagtap and
|
||||
Hanhwi Jang and
|
||||
Reiley Jeyapaul and
|
||||
Timothy M. Jones and
|
||||
Matthias Jung and
|
||||
Subash Kannoth and
|
||||
Hamidreza Khaleghzadeh and
|
||||
Yuetsu Kodama and
|
||||
Tushar Krishna and
|
||||
Tommaso Marinelli and
|
||||
Christian Menard and
|
||||
Andrea Mondelli and
|
||||
Tiago M{\"{u}}ck and
|
||||
Omar Naji and
|
||||
Krishnendra Nathella and
|
||||
Hoa Nguyen and
|
||||
Nikos Nikoleris and
|
||||
Lena E. Olson and
|
||||
Marc S. Orr and
|
||||
Binh Pham and
|
||||
Pablo Prieto and
|
||||
Trivikram Reddy and
|
||||
Alec Roelke and
|
||||
Mahyar Samani and
|
||||
Andreas Sandberg and
|
||||
Javier Setoain and
|
||||
Boris Shingarov and
|
||||
Matthew D. Sinclair and
|
||||
Tuan Ta and
|
||||
Rahul Thakur and
|
||||
Giacomo Travaglini and
|
||||
Michael Upton and
|
||||
Nilay Vaish and
|
||||
Ilias Vougioukas and
|
||||
Zhengrong Wang and
|
||||
Norbert Wehn and
|
||||
Christian Weis and
|
||||
David A. Wood and
|
||||
Hongil Yoon and
|
||||
{\'{E}}der F. Zulian},
|
||||
title = {The gem5 Simulator: Version 20.0+},
|
||||
journal = {CoRR},
|
||||
volume = {abs/2007.03152},
|
||||
year = {2020},
|
||||
url = {https://arxiv.org/abs/2007.03152},
|
||||
eprinttype = {arXiv},
|
||||
eprint = {2007.03152}
|
||||
}
|
||||
"""
|
||||
@@ -51,6 +51,7 @@ from . import SimObject
|
||||
from . import ticks
|
||||
from . import objects
|
||||
from . import params
|
||||
from .citations import gather_citations
|
||||
from m5.util.dot_writer import do_dot, do_dvfs_dot
|
||||
from m5.util.dot_writer_ruby import do_ruby_dot
|
||||
|
||||
@@ -164,6 +165,8 @@ def instantiate(ckpt_dir=None):
|
||||
# a checkpoint, If so, this call will shift them to be at a valid time.
|
||||
updateStatEvents()
|
||||
|
||||
gather_citations(root)
|
||||
|
||||
|
||||
need_startup = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user