Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.18.0 adding code hash sum #48

Merged
merged 15 commits into from
Apr 9, 2024
11 changes: 10 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.18.0] - 2024-03-22

### Added
- calculation of hash sum of source code (#48).

### Changed
- updated VHDL templates (#48).

## [2.17.1] - 2024-02-28

### Fixed
Expand Down Expand Up @@ -310,7 +318,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- adjusted `--dryrun` and `--ratio` options.

[unreleased]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.17.1...HEAD
[unreleased]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.18.0...HEAD
[2.18.0]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.17.1...2.18.0
[2.17.1]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.17.0...2.17.1
[2.17.0]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.16.0...2.17.0
[2.16.0]: https://github.com/cms-l1-globaltrigger/tm-vhdlproducer/compare/2.15.1...2.16.0
Expand Down
2 changes: 1 addition & 1 deletion tmVhdlProducer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.17.1"
__version__ = "2.18.0"
30 changes: 28 additions & 2 deletions tmVhdlProducer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import glob
import hashlib
import logging
import os
import re
Expand All @@ -10,13 +11,13 @@
import tmEventSetup
import tmReporter

from .vhdlproducer import VhdlProducer
from . import __version__
from .algodist import ProjectDir
from .algodist import distribute, constraint_t
from .algodist import MinModules, MaxModules
from .algodist import kExternals, kZDCPlus, kZDCMinus
from .algodist import DefaultConfigFile
from . import __version__
from .vhdlproducer import VhdlProducer

EXIT_SUCCESS: int = 0
EXIT_FAILURE: int = 1
Expand Down Expand Up @@ -63,6 +64,26 @@ def ratio_t(value: str) -> float:
return ratio
raise ValueError(ratio)

def calc_sw_hash(path: str) -> str:
"""Calculate a SHA-256 hash value of the content of all source files at given path."""
filenames = []
# Collect all python modules and VHDL templates
for pattern in ["**/*.py", "templates/vhdl/**/*.vhd"]:
for filename in glob.glob(os.path.join(path, pattern), recursive=True):
filenames.append(filename)

hash_sha256 = hashlib.sha256()
# Sort filenames for deterministic hash
for filename in sorted(filenames):
with open(filename, "rb") as f:
while True:
# Reading is buffered, so we can read smaller chunks.
chunk = f.read(hash_sha256.block_size)
if not chunk:
break
hash_sha256.update(chunk)
return hash_sha256.hexdigest()

# -----------------------------------------------------------------------------
# Command line parser
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -148,6 +169,10 @@ def main() -> int:

logging.info("running VHDL producer...")

sw_hash = calc_sw_hash(os.path.dirname(__file__))
logging.info("version: %s", __version__)
logging.info("hash: %s", sw_hash)

logging.info("loading XML menu: %s", args.menu)
eventSetup = tmEventSetup.getTriggerMenu(args.menu)
output_dir = os.path.join(args.output, f"{eventSetup.getName()}-d{args.dist}")
Expand Down Expand Up @@ -207,6 +232,7 @@ def main() -> int:
logging.info("writing VHDL modules...")
template_dir = os.path.join(ProjectDir, 'templates', 'vhdl')
producer = VhdlProducer(template_dir)
producer.config.update({"sw_hash": sw_hash})
producer.write(collection, output_dir)
logging.info("writing updated XML file %s", args.menu)

Expand Down
1 change: 1 addition & 0 deletions tmVhdlProducer/algodist.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tmGrammar

from .constants import BRAMS_TOTAL, SLICELUTS_TOTAL, PROCESSORS_TOTAL, NR_CALOS, NR_MUONS
from . import __version__

from .handles import Payload
from .handles import ObjectHandle
Expand Down
9 changes: 5 additions & 4 deletions tmVhdlProducer/templates/vhdl/algo_index.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
-- Scale set:
-- {{ menu.info.scale_set }}

-- VHDL producer version
-- v{{ menu.info.sw_version }}
-- VHDL producer
-- version: {{ menu.info.sw_version }}
-- hash value: {{ menu.info.sw_hash }}

-- tmEventSetup version
-- v{{ menu.info.version }}
-- tmEventSetup
-- version: {{ menu.info.version }}

-- HB 2016-09-16: constants for algo_mapping_rop.
type global_index_array is array (0 to NR_ALGOS-1) of integer;
Expand Down
10 changes: 5 additions & 5 deletions tmVhdlProducer/templates/vhdl/gtl_module_instances.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
-- Scale set:
-- {{ menu.info.scale_set }}

-- VHDL producer version
-- v{{ menu.info.sw_version }}
-- VHDL producer
-- version: {{ menu.info.sw_version }}
-- hash value: {{ menu.info.sw_hash }}

-- tmEventSetup version
-- v{{ menu.info.version }}
-- tmEventSetup
-- version: {{ menu.info.version }}

-- ========================================================
-- Instantiations of conditions
Expand Down Expand Up @@ -96,4 +97,3 @@ algo({{ algorithm.module_index | d }}) <= {{ algorithm.vhdl_signal }};
-- muon charge correlations
{% include "instances/muon_charge_correlations.vhd" %}
-- ========================================================

9 changes: 5 additions & 4 deletions tmVhdlProducer/templates/vhdl/gtl_module_signals.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
-- Scale set:
-- {{ menu.info.scale_set }}

-- VHDL producer version
-- v{{ menu.info.sw_version }}
-- VHDL producer
-- version: {{ menu.info.sw_version }}
-- hash value: {{ menu.info.sw_hash }}

-- tmEventSetup version
-- v{{ menu.info.version }}
-- tmEventSetup
-- version: {{ menu.info.version }}

-- Signal definition of pt, eta and phi for correlation conditions.
{%- include "signals/signal_correlation_conditions_parameter.vhd" %}
Expand Down
9 changes: 5 additions & 4 deletions tmVhdlProducer/templates/vhdl/ugt_constants.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
-- Scale set:
-- {{ menu.info.scale_set }}

-- VHDL producer version
-- v{{ menu.info.sw_version }}
-- VHDL producer
-- version: {{ menu.info.sw_version }}
-- hash value: {{ menu.info.sw_hash }}

-- tmEventSetup version
-- v{{ menu.info.version }}
-- tmEventSetup
-- version: {{ menu.info.version }}

-- Algorithms
constant NR_ALGOS : positive := {{ module.algorithms | length }}; -- number of algorithmns (min. 32 for FDL registers width !!!) - written by TME
Expand Down
14 changes: 8 additions & 6 deletions tmVhdlProducer/vhdlhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import tmEventSetup
import tmGrammar # import after tmEventSetup

from . import algodist
from . import __version__
from . import algodist

# -----------------------------------------------------------------------------
# Precompiled regular expressions
Expand Down Expand Up @@ -251,7 +251,6 @@ def bx_encode_4_array(value: int) -> str:
"""
return format([2, 1, 0, -1, -2].index(value), 'd')


# -----------------------------------------------------------------------------
# Factories
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -317,9 +316,9 @@ class MenuHelper(VhdlHelper):
modules [list]
"""

def __init__(self, collection):
def __init__(self, collection, config: dict) -> None:
# Init attribiutes
self.info = InfoHelper(collection)
self.info = InfoHelper(collection, config)
self.algorithms = collection.algorithms
self.conditions = collection.conditions
self.modules = []
Expand All @@ -344,9 +343,10 @@ class InfoHelper(VhdlHelper):
scale_set [str]
version [str]
sw_version [str]
sw_hash [str] (optional)
"""

def __init__(self, collection):
def __init__(self, collection, config: dict) -> None:
eventSetup = collection.eventSetup
# Init attribiutes
self.name = eventSetup.getName()
Expand All @@ -355,6 +355,7 @@ def __init__(self, collection):
self.scale_set = eventSetup.getScaleSetName()
self.version = VersionHelper(tmEventSetup.__version__)
self.sw_version = VersionHelper(__version__)
self.sw_hash = config.get("sw_hash", "")

class ModuleHelper(VhdlHelper):
"""Module template helper.
Expand Down Expand Up @@ -1661,7 +1662,7 @@ def update(self, cut_handle):
collection.reverse_sorting = True
collection.distribute(modules=6)
# Create template helper
menu = MenuHelper(collection)
menu = MenuHelper(collection, {"sw_hash": "42"})

# Info
print("*" * 80)
Expand All @@ -1671,6 +1672,7 @@ def update(self, cut_handle):
print("menu.info.scale_set :", menu.info.scale_set)
print("menu.info.version :", menu.info.version)
print("menu.info.sw_version :", menu.info.sw_version)
print("menu.info.sw_hash :", menu.info.sw_hash)
print("*" * 80)
print("menu.algorithms|length :", len(menu.algorithms))
print("menu.conditions|length :", len(menu.conditions))
Expand Down
Loading
Loading