scalesim package

Subpackages

Submodules

scalesim.scale module

scalesim.scale_config module

class scalesim.scale_config.scale_config[source]

Bases: object

force_valid()[source]
get_array_dims()[source]
get_bandwidths_as_list()[source]
get_bandwidths_as_string()[source]
get_conf_as_list()[source]
get_dataflow()[source]
static get_default_conf_as_list()[source]
get_mem_sizes()[source]
get_min_dram_bandwidth()[source]
get_offsets()[source]
get_run_name()[source]
get_topology_name()[source]
get_topology_path()[source]
read_conf_file(conf_file_in)[source]
set_arr_dims(rows=1, cols=1)[source]
set_buffer_sizes_kb(ifmap_size_kb=1, filter_size_kb=1, ofmap_size_kb=1)[source]
set_bw_mode_to_calc()[source]
set_dataflow(dataflow='os')[source]
set_offsets(ifmap_offset=0, filter_offset=10000000, ofmap_offset=20000000)[source]
set_topology_file(topofile='')[source]
update_from_list(conf_list)[source]
use_user_dram_bandwidth()[source]
write_conf_file(conf_file_out)[source]

scalesim.scale_sim module

class scalesim.scale_sim.scalesim(save_disk_space=False, verbose=True, config='', topology='', input_type_gemm=False)[source]

Bases: object

The top level class for the SCALE-Sim v2 simulator Provides methods for setting parameters, running sims, and generating results

get_total_cycles()[source]

Method to get the total cycles (stalls + compute) for the workload once the simulation is completed

Returns:

Total cycles

print_run_configs()[source]

Method to print the banner of input parameters for verbose scalesim runs

Returns:

None

run_once()[source]

Method to run the simulation once with preset config and topology objects

Returns:

None

run_scale(top_path='.')[source]

Method to initialize the internal simulation objects and run scalesim once

Parameters:

top_path – Path to the directory where generated outputs will be dumped

Returns:

None

set_params(config_filename='', topology_filename='')[source]

Set or update the paths to the scalesim input files

Parameters:
  • config_filename – Name and path to the config file

  • topology_filename – Name and path to the topology file

Returns:

None

scalesim.simulator module

class scalesim.simulator.simulator[source]

Bases: object

Class which runs the simulations and manages generated data across various layers

generate_reports()[source]

Method to generate the report files for scalesim run if the runs are already completed. For each layer, this method collects the report data from single_layer_sim objects and then prints them out into COMPUTE_REPORT.csv, BANDWIDTH_REPORT.csv, and DETAILED_ACCESS_REPORT.csv files.

Returns:

None

get_total_cycles()[source]

Method which aggregates the total cycles (both compute and stall) across all the layers for the given workload.

Returns:

Total runtime in cycles across all layers

Return type:

int

run()[source]

Method to run scalesim simulation for all layers. This method first runs compute and memory simulations for each layer and gathers the required stats. Once the simulation runs are done, it gathers the stats from single_layer_sim objects and calls generate_report() method to create the report files. If save_trace flag is set, then layer wise traces are saved as well.

Returns:

None

set_params(config_obj=<scalesim.scale_config.scale_config object>, topo_obj=<scalesim.topology_utils.topologies object>, top_path='./', verbosity=True, save_trace=True)[source]

Method to set the run parameters including inputs and parameters for housekeeping.

Parameters:
  • config_obj – Object of scalesim.scale_config which is used to lookup the architecture and run parameters set by the user

  • topo_obj – Object of scalesim.topologies which is used to obtain the workload dimensions

  • top_path – Path where the generated logs and traces will be saved

  • verbosity – Flag to indicate verbosity of runs. If set to False, no output is generated on console

  • save_trace – Flag to indicate if cycle accurate traces needs to be saved

Returns:

None

scalesim.single_layer_sim module

class scalesim.single_layer_sim.single_layer_sim[source]

Bases: object

Class which runs the simulation for a single layer and generates report data

calc_report_data()[source]

Method to generate the report data for a single layer if the run is already completed. This method collects and calculates the data for compute, bandwidth and detail reports.

Returns:

None

get_bandwidth_report_items()[source]

Method to calculate data for the bandwidth report if not already done.

Returns:

List of SRAM and DRAM bandwidths for the bandwidth report

get_compute_report_items()[source]

Method to calculate data for the compute report if not already done.

Returns:

List of data items for the compute report

get_detail_report_items()[source]

Method to calculate data for the detailed report if not already done.

Returns:

List of data items for the detailed report

get_layer_id()[source]

Method to return layer id.

Returns:

Layer number of the workload

run()[source]

Method to run scalesim simulation for a single layer. This method first runs the compute part to generate operand, prefetch and demand matrices in order. After that, it runs the memory simulation using the demand matrices.

Returns:

None

save_traces(top_path)[source]

Method to save SRAM and DRAM traces for ifmap, filter and ofmap matrices.

Parameters:

top_path – Path where the generated traces will be saved

Returns:

None

set_memory_system(mem_sys_obj=<scalesim.memory.double_buffered_scratchpad_mem.double_buffered_scratchpad object>)[source]
set_params(layer_id=0, config_obj=<scalesim.scale_config.scale_config object>, topology_obj=<scalesim.topology_utils.topologies object>, verbose=True)[source]

Method to set the run parameters for housekeeping.

Parameters:
  • layer_id – Layer number of the workload

  • config_obj – Object of scalesim.scale_config which is used to lookup the architecture and run parameters set by the user

  • topology_obj – Object of scalesim.topologies which is used to obtain the workload dimensions

  • verbose – Flag to indicate verbosity of runs. If set to False, no output is generated on console

Returns:

None

scalesim.topology_utils module

class scalesim.topology_utils.topologies[source]

Bases: object

Class which contains the methods to preprocess the data from topology file (.csv format) before doing compute simulation.

append_layer_entry(entry, toponame='')[source]

Method to append data of a single layer to the array containing data of all the layers. This method also calls topo_calc_hyperparams method to calculate the hyperparameters.

Parameters:
  • entry – List containing dimensions(int data type) of the workload layer and its name

  • toponame – Name of the workload

Returns:

None

append_topo_arrays(layer_name, elems)[source]

Method to append the layer dimensions in int data type and layer name to the topo_arrays variable. This method also checks that the filter dimensions do not exceed the ifmap dimensions.

Parameters:
  • layer_name – Name of the workload layer

  • elems – List of elements containing dimensions of the workload layer

Returns:

None

append_topo_entry_from_list(layer_entry_list=[])[source]

Method to append the layer dimensions in int data type and layer name.

Parameters:

layer_entry_list – List of elements containing dimensions and name of the workload layer

Returns:

None

calc_spatio_temporal_params(df='os', layer_id=0)[source]

Method to calculate spatio-temporal parameters (S_r, S_c and T) based on the dataflow. (Refer the scalesim paper for more info)

Parameters:
  • df – Name of the dataflow (input, output or weight stationary)

  • layer_id – Layer number of the workload

Returns:

spatio-temporal parameters (S_r, S_c and T)

get_all_mac_ops()[source]

Method to get the total number of mac operations of all the layer if hyper-parameters are calculated. If not, calculate the hyper-parameters first.

Returns:

Total number of mac operations of all the layers

get_current_topo_name()[source]

Method to get the name of the workload if available. If not, print an error message.

Returns:

Name of the workload

get_layer_filter_dims(layer_id=0)[source]

Method to get the filter dimensions of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Filter height and width

get_layer_id_from_name(layer_name='')[source]

Method to get layer number from the given layer name if available. If not, print an error message.

Parameters:

layer_name – Name of the layer

Returns:

Layer number of the workload

get_layer_ifmap_dims(layer_id=0)[source]

Method to get the ifmap dimensions of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Ifmap height and width

get_layer_mac_ops(layer_id=0)[source]

Method to get the number of mac operations of the layer if hyper-parameters are calculated. If not, calculate the hyper-parameters first.

Parameters:

layer_id – Layer number of the workload

Returns:

Number of mac operations of the layer

get_layer_name(layer_id=0)[source]

Method to get the layer name from the given layer number if available. If not, print an error message.

Parameters:

layer_name – Layer number of the workload

Returns:

Name of the layer

get_layer_names()[source]

Method to get the names of all the layers in the workload. If not, print an error message.

Returns:

Names of all the layers

get_layer_num_channels(layer_id=0)[source]

Method to get the number of channels of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

:return:Number of channels

get_layer_num_filters(layer_id=0)[source]

Method to get the number of filters of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Number of filters

get_layer_num_ofmap_px(layer_id=0)[source]

Method to get the number of ofmap pixels of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Number of ofmap pixels

get_layer_ofmap_dims(layer_id=0)[source]

Method to get the ofmap dimensions of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Ofmap height and width

get_layer_params(layer_id=0)[source]

Method to get the parameters of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Parameters of the layer

get_layer_strides(layer_id=0)[source]

Method to get the strides of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Strides (both horizontal and vertical) of the convolution

get_layer_window_size(layer_id=0)[source]

Method to get the convolution window size of the layer if available. If not, print an error message.

Parameters:

layer_id – Layer number of the workload

Returns:

Convolution window size

get_num_layers()[source]

Method to get the number of layers of the workload if available. If not, print an error message.

Returns:

Number of layers of the workload

get_spatiotemporal_dims(layer_id=0, df='')[source]

Method to get the spatio-temporal dimensions (S_r, S_c, T) of the layer if spatio-temporal parameters are calculated. If not, calculate the spatio-temporal parameters first. (refer to the scalesim paper for more info)

Parameters:
  • layer_id – Layer number of the workload

  • df – Name of the dataflow (input, output or weight stationary)

Returns:

Spatio-temporal dimensions of the layer (S_r, S_c, T)

get_transformed_mnk_dimensions()[source]

Method to get M, N and K parameters for all the layers. These are GEMM parameters in which an input matrix of dimensions MxN is multiplied to a filter matrix of dimensions NxK.

Returns:

M, N and K parameters array

load_arrays(topofile='')[source]

Method to read the topology file and collect names and dimensions of all the workload layers.

Parameters:

topofile – Name of the topology file

Returns:

None

load_layer_params_from_list(layer_name, elems_list=[])[source]

Method to load layer parameters from the given layer name and element list.

Parameters:
  • layer_name – Name of the workload layer

  • elem_list – List of elements containing dimensions of the workload layer

Returns:

None

reset()[source]

Method to reset the topology parameters.

Returns:

None

set_spatio_temporal_params()[source]

Method to calculate spatio-temporal parameters (S_r, S_c and T) for all the layers

Returns:

None

topo_calc_hyperparams(topofilename='')[source]

Method to calculate hyper-parameters (ofmap dimensions, number of MACs, and window size of filter) if topology array is loaded.

Parameters:

topofilename – Name of the topology file

Returns:

None

write_topo_file(path='', filename='')[source]

Method to write the workload data into a csv file.

Parameters:
  • path – Location where the csv file is to be stored

  • filename – Name of the csv file

Returns:

None

Module contents