hlsfactory.utils

Module Contents

Classes

CallToolResult

Represents the result of a tool call using call_tool.

FlowTimer

A class for measuring the execution time of a flow.

DirSource

Enum class representing different sources for directories.

ToolPathsSource

Enumeration representing the source of tool paths.

Functions

call_tool

terminate_process_and_children

Terminate a process and all its child processes.

wait_for_files_creation

find_bin_path

Find the path of a binary executable.

log_execution_time_to_file

Logs the execution time of a specific flow to a file.

serialize_methods_for_dataclass

Decorator function that adds serialization methods to a dataclass.

timeout_not_supported

Raises a RuntimeError indicating that timeout is not supported for the current flow.

get_work_dir

Get the working directory path based on the specified directory source.

get_tool_paths

Get the paths for Vitis HLS and Vivado tools based on the specified source.

remove_dir_if_exists

Remove a directory if it exists.

remove_and_make_new_dir_if_exists

Removes the directory at the given path if it exists, and then creates a new directory at the same path.

Data

T

API

class hlsfactory.utils.CallToolResult(*args, **kwds)[source]

Bases: enum.Enum

Represents the result of a tool call using call_tool.

Initialization

SUCCESS = 'auto(...)'
TIMEOUT = 'auto(...)'
ERROR = 'auto(...)'
hlsfactory.utils.call_tool(cmd: str, cwd: pathlib.Path, shell: bool = False, timeout: float | None = None, log_output: bool = False, raise_on_error: bool = True) hlsfactory.utils.CallToolResult[source]
hlsfactory.utils.terminate_process_and_children(pid: int) None[source]

Terminate a process and all its child processes.

Args:

pid (int): The process ID of the parent process.

hlsfactory.utils.wait_for_files_creation(file_paths: list[pathlib.Path], timeout: float, poll_interval: float = 1) bool[source]
hlsfactory.utils.find_bin_path(cmd: str) str[source]

Find the path of a binary executable.

Args:

cmd (str): The name of the binary executable.

Returns:

str: The path of the binary executable.

Raises:

RuntimeError: If the binary executable cannot be found.

hlsfactory.utils.log_execution_time_to_file(design_dir: pathlib.Path, flow_name: str, t_0: float, t_1: float) None[source]

Logs the execution time of a specific flow to a file.

Args:

design_dir (Path): The directory where the design is located. flow_name (str): The name of the flow. t_0 (float): The start time of the execution. t_1 (float): The end time of the execution.

Raises:

RuntimeError: If the design directory does not exist.

class hlsfactory.utils.FlowTimer(flow_name: str, dir_path: pathlib.Path)[source]

A class for measuring the execution time of a flow.

Attributes:

flow_name (str): The name of the flow. dir_path (Path): The directory path where the execution time will be logged. t_0 (float | None): The start time of the flow execution. t_1 (float | None): The stop time of the flow execution.

Initialization

start() None[source]

Start the timer for measuring the flow execution time.

stop() None[source]

Stop the timer for measuring the flow execution time.

log() None[source]

Log the execution time of the flow to a file. Raises:

RuntimeError: If either t_0 or t_1 is None.

__enter__() hlsfactory.utils.FlowTimer[source]

Start the timer when entering a context. Returns:

FlowTimer: The FlowTimer instance.

__exit__(_exc_type, _exc_value, _traceback) None[source]

Stop the timer and log the execution time when exiting a context.

hlsfactory.utils.T = 'TypeVar(...)'
hlsfactory.utils.serialize_methods_for_dataclass(cls: type[hlsfactory.utils.T]) type[hlsfactory.utils.T][source]

Decorator function that adds serialization methods to a dataclass.

The serialization methods added are: - from_json: A class method that creates a dataclass instance from a JSON file. - to_json: An instance method that writes the dataclass instance to a JSON file. - from_yaml: A class method that creates a dataclass instance from a YAML file. - to_yaml: An instance method that writes the dataclass instance to a YAML file.

Args:

cls (type[T]): The dataclass to decorate.

Returns:

type[T]: The decorated dataclass.

Raises:

TypeError: If the decorated class is not a dataclass.

hlsfactory.utils.timeout_not_supported(flow_name: str) None[source]

Raises a RuntimeError indicating that timeout is not supported for the current flow.

Args:

flow_name (str): The name of the current flow.

Raises:

RuntimeError: Indicates that timeout is not supported for the current flow.

class hlsfactory.utils.DirSource(*args, **kwds)[source]

Bases: enum.Enum

Enum class representing different sources for directories.

Used by get_work_dir to determine the source to look for a specific work directory to use.

Options: - ENVFILE: Look for the directory in the .env file. - ENV: Look for the directory in the environment variables. - TEMP: Create a temporary directory.

Initialization

ENVFILE = 'auto(...)'
ENV = 'auto(...)'
TEMP = 'auto(...)'
hlsfactory.utils.get_work_dir(dir_source: hlsfactory.utils.DirSource = DirSource.ENVFILE, env_file_path: pathlib.Path | None = None, use_cwd: bool = True) pathlib.Path[source]

Get the working directory path based on the specified directory source.

Args:

dir_source (DirSource, optional): The directory source to use. Defaults to DirSource.ENVFILE.

Returns:

pathlib.Path: The path to the working directory.

Raises:

ValueError: If the specified directory source is invalid or the working directory path is not found.

class hlsfactory.utils.ToolPathsSource(*args, **kwds)[source]

Bases: enum.Enum

Enumeration representing the source of tool paths.

Used by get_tool_paths to determine the source to look for the paths of the tools to use.

Options: - ENVFILE: Look for the paths in the .env file. - ENV: Look for the paths in the environment variables.

Initialization

ENVFILE = 'auto(...)'
ENV = 'auto(...)'
hlsfactory.utils.get_tool_paths(tool_paths_source: hlsfactory.utils.ToolPathsSource, env_file_path: pathlib.Path | None = None, use_cwd: bool = True) tuple[pathlib.Path, pathlib.Path][source]

Get the paths for Vitis HLS and Vivado tools based on the specified source.

Args:

tool_paths_source (ToolPathsSource): The source from which to retrieve the tool paths.

Returns:

tuple[pathlib.Path, pathlib.Path]: A tuple containing the paths for Vitis HLS and Vivado tools.

Raises:

ValueError: If the tool paths are not found in the specified source.

hlsfactory.utils.remove_dir_if_exists(dir_path: pathlib.Path) None[source]

Remove a directory if it exists.

Args:

dir_path (pathlib.Path): The path to the directory.

Returns:

None

hlsfactory.utils.remove_and_make_new_dir_if_exists(dir_path: pathlib.Path) None[source]

Removes the directory at the given path if it exists, and then creates a new directory at the same path.

Args:

dir_path (pathlib.Path): The path to the directory.

Returns:

None