hlsfactory.utils
¶
Module Contents¶
Classes¶
Represents the result of a tool call using call_tool. |
|
A class for measuring the execution time of a flow. |
|
Enum class representing different sources for directories. |
|
Enumeration representing the source of tool paths. |
Functions¶
Terminate a process and all its child processes. |
|
Find the path of a binary executable. |
|
Logs the execution time of a specific flow to a file. |
|
Decorator function that adds serialization methods to a dataclass. |
|
Raises a RuntimeError indicating that timeout is not supported for the current flow. |
|
Get the working directory path based on the specified directory source. |
|
Get the paths for Vitis HLS and Vivado tools based on the specified source. |
|
Remove a directory if it exists. |
|
Removes the directory at the given path if it exists, and then creates a new directory at the same path. |
Data¶
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
- 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.
- 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.