forked from mdekauwe/CABLE_benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Intel code-coverage analysis
- Loading branch information
1 parent
fc625c0
commit ef27b5b
Showing
13 changed files
with
357 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2024 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""A module containing functions and data structures for running coverage tasks.""" | ||
|
||
import multiprocessing | ||
import operator | ||
from typing import Optional | ||
|
||
from benchcab import internal | ||
from benchcab.environment_modules import EnvironmentModules, EnvironmentModulesInterface | ||
from benchcab.model import Model | ||
from benchcab.utils import get_logger | ||
from benchcab.utils.fs import chdir | ||
from benchcab.utils.subprocess import SubprocessWrapper, SubprocessWrapperInterface | ||
|
||
|
||
class CoverageTask: | ||
"""A class used to represent a single bitwise coverage task.""" | ||
|
||
subprocess_handler: SubprocessWrapperInterface = SubprocessWrapper() | ||
modules_handler: EnvironmentModulesInterface = EnvironmentModules() | ||
|
||
def __init__( | ||
self, | ||
coverage_dir: str, | ||
project_name: Optional[str] = "CABLE", | ||
dpi_file: Optional[str] = "pgopti.dpi", | ||
spi_file: Optional[str] = "pgopti.spi", | ||
) -> None: | ||
"""Constructor. | ||
Parameters | ||
---------- | ||
coverage_dir: | ||
Name of directory where coverage analysis is to be done | ||
project_name: | ||
Name of project on which codecov is run | ||
dpi_file: | ||
name of DPI file created after merging .dyn files created after all runs | ||
spi_file: | ||
Static profile information on compilation | ||
""" | ||
self.logger = get_logger() | ||
self.coverage_dir = coverage_dir | ||
self.project_name = project_name | ||
self.dpi_file = dpi_file | ||
self.spi_file = spi_file | ||
|
||
def run(self) -> None: | ||
"""Executes `profmerge` and `codecov` to run codecov analysis for a given realisation.""" | ||
with chdir(self.coverage_dir), self.modules_handler.load( | ||
[internal.DEFAULT_MODULES["intel-compiler"]] | ||
): | ||
self.subprocess_handler.run_cmd(f"profmerge -prof-dpi {self.dpi_file}") | ||
self.subprocess_handler.run_cmd( | ||
f"codecov -prj {self.project_name} -dpi {self.dpi_file} -spi {self.spi_file}" | ||
) | ||
|
||
|
||
def run_coverage_tasks(coverage_tasks: list[CoverageTask]) -> None: | ||
"""Runs coverage tasks serially.""" | ||
for task in coverage_tasks: | ||
task.run() | ||
|
||
|
||
def get_coverage_tasks_default(models: list[Model]) -> list[CoverageTask]: | ||
"""Returns list of Coveragee Tasks setting default values for optional parameters.""" | ||
return [CoverageTask(model.get_coverage_dir()) for model in models] | ||
|
||
|
||
def run_coverages_in_parallel( | ||
coverage_tasks: list[CoverageTask], | ||
n_processes=internal.FLUXSITE_DEFAULT_PBS["ncpus"], | ||
) -> None: | ||
"""Runs coverage tasks in parallel across multiple processes.""" | ||
run_task = operator.methodcaller("run") | ||
with multiprocessing.Pool(n_processes) as pool: | ||
pool.map(run_task, coverage_tasks, chunksize=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.