GainSight SCALE-Sim Backend Python API Documentation
This page documents the Python scripts in gainsight/backend/python-scripts/ supporting the SCALE-Sim systolic array simulation backend using mkdocstrings.
Please refer to the backend wiki for a summary of implementation details and usage instructions.
SCALE-Sim Runner Script
The run.py script is the main entry point for running the SCALE-Sim simulator. It handles command-line arguments, initializes the simulation environment, and manages the execution of the simulation.
get_aggregate(lifetime_csv_file, freq_data, aggregate_csv_file)
Parse lifetimes CSV and frequency data to compute aggregate statistics per data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lifetime_csv_file
|
str
|
Path to the CSV file with address-level lifetimes. |
required |
freq_data
|
dict
|
Dictionary with frequency and access statistics from parse_lifetimes. |
required |
aggregate_csv_file
|
str
|
Path to output CSV for aggregate statistics. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in python/run.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
main()
Main entry point for processing SCALE-Sim traces and generating GainSight data.
Parses command-line arguments, processes each layer's memory traces to extract lifetimes, aggregates statistics, and (optionally) generates graphs for each layer.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in python/run.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
parse_args()
Parse command-line arguments for the run.py script.
Returns:
| Type | Description |
|---|---|
Namespace
|
argparse.Namespace: Parsed arguments with source and output_dir attributes. |
Source code in python/run.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
SCALE-Sim Parser Script
The parse_lifetimes.py script is responsible for parsing the trace files generated by the SCALE-Sim simulator. It extracts relevant information about data lifetime, read and write operations, and other performance metrics from the trace files.
parse_lifetimes.py
Module for parsing SCALE-Sim memory access traces to extract data lifetimes and access statistics.
create_access_list(filename, data_type)
Parse a memory trace file to extract access cycles for each address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the trace CSV file. |
required |
data_type
|
str
|
Type of data buffer (ifmap, filter, ofmap). |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict, int]
|
tuple[dict, int]: Dictionary mapping addresses to access cycles, and total active cycles. |
Source code in python/parse_lifetimes.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
export_lifetimes(lifetimes, csvfile)
Export lifetimes dictionary to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lifetimes
|
dict
|
Dictionary of (data_type, {address: [lifetimes]}) pairs. |
required |
csvfile
|
str
|
Path to the output CSV file. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in python/parse_lifetimes.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
find_lifetimes(reads, writes)
Compute lifetimes for each address based on read and write access cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reads
|
dict
|
Dictionary mapping addresses to read cycles. |
required |
writes
|
dict
|
Dictionary mapping addresses to write cycles. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary mapping addresses to lists of lifetimes (in cycles). |
Source code in python/parse_lifetimes.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
get_freq(compute_report, layer, read_active_cycles, write_active_cycles)
Compute read/write frequencies using SCALE-Sim COMPUTE_REPORT and active cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compute_report
|
str
|
Path to the COMPUTE_REPORT.csv file. |
required |
layer
|
int
|
Layer number to analyze. |
required |
read_active_cycles
|
int
|
Number of cycles with read accesses. |
required |
write_active_cycles
|
int
|
Number of cycles with write accesses. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
[read_freq, write_freq] as percentages of total cycles. |
Source code in python/parse_lifetimes.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
main()
Main entry point for parsing memory lifetimes from SCALE-Sim traces.
Parses command-line arguments and processes the specified source directory to extract memory lifetimes and access statistics, writing results to output files.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in python/parse_lifetimes.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
parse_args()
Parse command-line arguments for the parse_lifetimes.py script.
Returns:
| Type | Description |
|---|---|
Namespace
|
argparse.Namespace: Parsed arguments with source and output_dir attributes. |
Source code in python/parse_lifetimes.py
266 267 268 269 270 271 272 273 274 275 276 277 278 | |
parse_lifetimes(src_dir, output_dir)
Parse SCALE-Sim memory access traces to extract data lifetimes and access statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_dir
|
str
|
Path to the directory containing layer trace files. |
required |
output_dir
|
str
|
Path to the output directory for processed results. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary with (data_type, [read_freq, write_freq, ...]) pairs for each memory type. |
Source code in python/parse_lifetimes.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
SCALE-Sim Graph Script
The create_graphs.py script is responsible for generating the graph representation of the computed metrics for individual workloads, including but not limited to data lifetime distributions.
create_graphs.py
Module for generating data lifetime distribution graphs from processed SCALE-Sim traces.
graph(csv_file, layer, addt_title)
Generate histogram plots of data lifetimes for each memory type in a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_file
|
str
|
Path to the CSV file containing lifetime data. |
required |
layer
|
str
|
Name of the layer being analyzed. |
required |
addt_title
|
str
|
Additional title string for the plot. |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib.figure.Figure: The generated figure object. |
Source code in python/create_graphs.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
main()
Main entry point for generating graphs from lifetime CSV data.
Parses command-line arguments and generates graphs for the specified layer's data lifetimes.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in python/create_graphs.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
parse_args()
Parse command-line arguments for the create_graphs.py script.
Returns:
| Type | Description |
|---|---|
Namespace
|
argparse.Namespace: Parsed arguments with file, output, and layer attributes. |
Source code in python/create_graphs.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |