hw_config
Hardware configuration module for the Chimera GPNPU.
This module provides the HWConfig class for representing and manipulating Chimera GPNPU hardware configurations. It includes utilities for creating, validating, and converting between different hardware configuration formats.
Class: HWConfig
Dataclass representing a Chimera GPNPU hardware configuration.
This class encapsulates all hardware configuration parameters for the Chimera GPNPU (General Purpose Neural Processing Unit). It provides methods for creating, validating, and manipulating hardware configurations, as well as converting between different representation formats. The class validates all configuration parameters upon initialization to ensure they are within supported ranges and compatible with each other.
Attributes:
product : str The product name (e.g., "QC-U", "QC-P", "QC-N"). ocm_size : str The size of on-chip memory in MB format (e.g., "16MB"). lrm_size : str The size of local register memory in kB format (e.g., "4kB"). ext_rd_bw : str External read bandwidth in GBps format (e.g., "128GBps"). ext_wr_bw : str External write bandwidth in GBps format (e.g., "128GBps"). macs_per_pe : int Number of MACs per processing element (8 or 16). num_cores : int Number of cores in the GPNPU configuration (1, 2, 4, or 8). num_clusters : int Number of clusters in the GPNPU configuration (1, 2, 4, or 8). clock_freq_ghz : float Clock frequency in GHz (e.g., 1.7). mem_prot : str Sets the memory protection mode (OFF, PAR or ECC) hw_version : str Hardware version string in hex format (e.g., "0x0C010102").
Methods Overview
from_json(cls, json_data, clock_freq_ghz)- Create a HWConfig instance from a JSON configuration.from_studio_sku_string(cls, input_string)- Create a HWConfig instance from a studio SKU config string.__str__()- Return a string representation of the hardware configuration.__post_init__()-macs_per_cycle()- Calculate the total MACs per cycle for this hardware configuration.clock_period_ns()- Compute the clock period in nanoseconds.compute_latency(cycles)- Compute latency in seconds from cycle count.compute_fps(cycles)- Compute frames per second from cycle count.array_size()- Get the array size for the current product.arch_version()- Get the architecture version for the current product.effective_core_count()- Get the effective number of cores across all clusters.randomize_config()- Randomize the hardware configuration with valid parameter values.to_dict()- Convert the HWConfig to a Python dictionary.
Methods Details
from_json(cls, json_data, clock_freq_ghz)
Create a HWConfig instance from a JSON configuration.
This method parses a JSON configuration (either as a string or a dictionary) and extracts the hardware configuration parameters to create a new HWConfig instance. It's particularly useful when loading configuration from files or external systems.
Parameters:
json_data:dict or strA dictionary containing the JSON configuration or a JSON string. The JSON must contain specific hardware configuration keys.
Returns:
HWConfigA new hardware configuration instance with parameters extracted from the JSON data.
Raises:
ValueError If the JSON data is missing required keys or contains invalid configuration parameters.
Examples:
## From a JSON string
json_str = '{"HW_VERSION": "0x0C010102", "ARRAY_SIZE": 32, "L2M_SIZE": 16777216, "D_AXI_DATA_WIDTH": 1024, "NUM_PE_MACS": 16, "NUM_GPNPU": 1, "LRM_SIZE": 4096}'
hw_config = HWConfig.from_json(json_str)
## From a dictionary
json_dict = {
"HW_VERSION": "0x0C010102",
"ARRAY_SIZE": 32,
"L2M_SIZE": 16777216,
"D_AXI_DATA_WIDTH": 1024,
"NUM_PE_MACS": 16,
"NUM_GPNPU": 1,
"LRM_SIZE": 4096
}
hw_config = HWConfig.from_json(json_dict)
from_studio_sku_string(cls, input_string)
Create a HWConfig instance from a studio SKU config string.
This method parses a Studio SKU (Stock Keeping Unit) string representation of hardware configuration and creates a corresponding HWConfig instance. The SKU string uses a standardized format to encode product type, memory size, bandwidth, and MAC count information.
Parameters:
input_string:strA string in the format "QC-[NPU]-(MB)-(GBps)-(MAC)" For example: "QC-N-8MB-128GBps-16MAC" represents a QC-N product with 8MB of OCM, 128GBps bandwidth, and 16 MACs per PE.
Returns:
HWConfigA new hardware configuration instance with parameters parsed from the SKU string.
Raises:
ValueError If the input string format is invalid or doesn't match the expected pattern.
Examples:
## Create a config for a QC-N device with 8MB OCM and 16 MACs
hw_config = HWConfig.from_studio_sku_string("QC-N-8MB-128GBps-16MAC")
## Create a config for a QC-U device with 16MB OCM and 8 MACs
hw_config = HWConfig.from_studio_sku_string("QC-U-16MB-128GBps-8MAC")
__str__()
Return a string representation of the hardware configuration.
Returns:
strA string representation in the format: product_clock_ocm_lrm_rd_bw_wr_bw_macs_mem_prot__cores Example: "QC-U_1d7_16MB_4kB_128GBps_128GBps_16_x1"
__post_init__()
macs_per_cycle()
Calculate the total MACs per cycle for this hardware configuration.
Returns:
intThe total number of multiplier-accumulator operations per cycle, calculated as array_size^2 * macs_per_pe.
clock_period_ns()
Compute the clock period in nanoseconds.
Returns:
floatThe clock period in nanoseconds, calculated as 1/clock_freq_ghz.
compute_latency(cycles)
Compute latency in seconds from cycle count.
Parameters:
cycles:intNumber of clock cycles.
Returns:
floatLatency in seconds, calculated as cycles * clock_period_ns * 1e-9.
compute_fps(cycles)
Compute frames per second from cycle count.
Parameters:
cycles:intNumber of clock cycles required to process one frame.
Returns:
floatFrames per second, calculated as (clock_freq_ghz * 1e9) / cycles.
array_size()
Get the array size for the current product.
Returns:
intThe array size dimension (e.g., 8, 16, or 32).
arch_version()
Get the architecture version for the current product.
Returns:
intThe architecture version number (e.g., 2 for QB, 3 for QC).
effective_core_count()
Get the effective number of cores across all clusters.
Returns:
intThe total number of cores (num_cores * num_clusters).
Notes:
For the current use model, networks are split across all available cores. This property calculates the effective core count by multiplying num_cores by num_clusters. Future use models may execute kernels on a subset of cores, in which case this calculation will need to be updated.
randomize_config()
Randomize the hardware configuration with valid parameter values.
This method selects random values for product, ocm_size, lrm_size, bandwidth, and macs_per_pe within the allowed ranges for each parameter. For QB products, macs_per_pe is fixed at 8.
to_dict()
Convert the HWConfig to a Python dictionary.
Returns:
dictA dictionary containing all the attributes of the HWConfig instance.