VISUALSIM TRAINING

Training: Planning, Modeling, Simulation, Advanced Features
Planning
Goals &
Requirements

Tasks orOperations

Workloads orTraffic

Hardware or
Platform

Collaboration& Sharing

Data
Management

SupportLook & feelFlow- System,
Beh-Arch,
Data flow

Performance
Power
Functionality

Hierarchical/
Class/ DI
BlocksTraffic/
Results

Hardware/
Software/
Network

Abstraction

Algorithms

Task Graph

Checking

Graphical/
Batch/ MultiCore

Debugging/
Verification

Requirements

PostSimulation

Types of Plots

Advanced
StudiesAccuracy

CompareGeneration

Encryption

Modeling
Parameters/
Variables/ DS/
FieldsSimulation and Analysis
Types ofStudiesParameter
RangesAdvanced Features
FailureIntegration

Agenda- Part 2: Modeling Parameters/Variables/DS/Fields
 Data Types
 Regex
 Flow- System, Beh-Arch, Data flow
 Hierarchical/ Class/ DI Blocks
 Traffic
 Results
 Abstraction

Variable Vs Parameter Vs Data Structure
Variable

Parameter

1. 3 types- Block(In
1. Fixed for a simulation
Script and Expression
and modified for next
List only), Local(Onerunwindow) and Global
2. Example: clock speed,(Full Model)
buffer size
2. Values change during
simulation
3. Used for multi-core andbatch simulation
3. Example: Flag,
Statistics
Common-All standard data types supports by Parameters, Variables and fields-Viewable by Blocks

Data Structure
1. Similar to Struct in C
with Fields and values
2. Contains specificinformation for that
Transaction or packet
3. Dynamically add anddestroy fields

Data Structure
Data Structure is similar to “struct” in C
Fields of the Data Structure represent• Data transmitted through the model• Represents the Control signal info , frames, packets etc.
Data Structures contain 6 standard header• Block (Source name) and DS_Name (Template name)• TIME (creation time-stamp) and ID (sequence number)• INDEX (integer scratch pad) & DELTA (double scratchpad)Data Structure Templates•VisualSim Processor, memory -> Processor_DS•Network modeling -> Task_Class•Non-Processor Hardware -> Hardware_DS•Stochastic -> Header

Processor_DS - template

Replacing the default data structure template which can have 50+ fields with a minimal template (Min DS)(~10 fields) will show significant improvement in Run Time of the Models

Necessary Fields in the Data Structure• A_Source

Note: Error message will be thrown when one or more required fields are absent• A_Destination• A_Command• A_Bytes• A_Bytes_Remaining• A_Bytes_Sent• A_Task_Flag
Adding the necessary
fields resolves the issueParameter
Used to define values which cannot be changed during simulation but can be changed
between simulation
Usage• Any block in the BDE can access these values• Export block parameters to link to the BDE parameters
Types• Generic parameters - Scalar and String• Expressions• File names• Parameter Set

Variable
Variable is a lookup list, variable or register to store data during the simulation
Variable is a named location• Local- available in the current window only
• Global- available throughout the model• Block- available within the Script, ExpressionList

Used to communicate between blocks and routing
Defined in VariableList (Global and local), ExpressionList (Block) and Script (Block)Supports all standard data types

Data Types supported in VisualSim
1. Scalar◦ Integer◦ Double◦ Long2. String
3. Array
4. Matrix

Note:
•
•
•
•

1/5 will be 0
1.0/5 will be 0.2
1/5.0 will be 0.2
1.0/5.0 will be 0.2

RegEx• Collection of Mathematical, Logical, Statistical and Algorithm-Specific Functions• Popular RegEx are used with Array, Queues, Schedulers, Data Structure, Power and Networking• Usage✔Parameters✔Processing, ExpressionList, Script and Queue/Server for defining logic and decisions✔Can combine parameters, variable and data structure fields

Regex Examples
Hardware Architecture Routing table
addToRoutingTable(StringArchitecture_Name,
String Source_Name,
StringDestination_Name,
String Hop_Name,
StringSource_Port_Name)
getRoutingTable(StringArchitecture_Name)

Adds a line to therouting table. Thisis used to add a
specific
connection.

Get Routing Table
as a Data
Structure.

addToRoutingTable("Architecture_1","IO_2","IO_2","Bus_Name_1","Bus_Name_2")

getRoutingTable("Architecture_1")

Statistics
addStats(Stringmemory_name,double value)

Power Regex
Gets the complete
power table. This
will get the details
for all devices thatare associated withthis PowerTable

powerManager(String power_table_name)stateChange(String power_manager_name,
String Device Name String
Operating State, String Statename)powerManager("ARM_Table_Manager ")Changes thestate of a device stateChange("Manager_1
dynamically. See ",device list above. "ARM","Standby","Idle“)File I/O
Updates a statistics memory that is definedusing the Statistics block. If the memory exists,then add double value and return true, else
returns false.

readFile(String filename)writeFile(String filename,java.lang.Object
token)

Get the string text
contained in thespecified file.

readFile("File_Name")

Write the token to thespecified file.

writeFile("File_Name",port_token)Expression List
Some Commonly used Expressions in
ExpressionList

Sequence of mathematical expressions
Requires one transaction on all input ports to fire theblock
Assign values to fields or variables◦ Execution starts when data arrives on all input ports◦ Data at each port is identified by the port name◦ Queued if multiple values arrive at one port

Execution issequential

Usage◦ input.field_name = value

Can useconditional
statements

Output◦ Condition can use any expression containing fields, variables
and logical operators

8/18/2020

MIRABILIS DESIGN INC.

14

Using Regex in ExpressionList – Demo ModelDemo Models – Regex in script block$VS/doc/Training_Material/Tutorial/General/RegEx/
RegEx_File_Test.xml$VS/doc/Training_Material/Tutorial/Gener
al/RegEx/RegEx_Power_Test.xml

Hierarchical/ Class/ DI Blocks

Hierarchical Blocks• Grouping a set of functional blocks
that combine to define a function or
deviceConstruct Hierarchical Block• Select the blocks to be grouped. Select Edit -> Create Hierarchy• Drag from Model Setup -> HierarchicalBlock• Add input and output ports, Parameters• To view inside the Block, Right click- > Open BlockClass• A class is a master version of the block.
• Class is an XML sub-model• Can be instantiated multiple times in the model.
• Changes made to class block are replicated to alllinked instances• All sub-models need a Simulator

How to construct a Class?
• Assemble the initial block diagram✔Use the library blocks to assemble the model✔Create a Hierarchical block of this block diagram• Create a class✔Convert the Hierarchical block into a Class✔Save as a sub-model• Instantiate a new class for use in a model✔To use the Class, you need to instantiate the block inthe model using Graph> Instantiate. Entity. Make
sure the Class is located within the
VS_Model_Library directory• To test the class✔ Test the class by constructing a simple modelaround it.

• Save in Library✔Right-click the block and select Save Block in Library.

Constructing a class
CREATE HIERARCHY

CONVERT TO CLASSOPEN CLASS AND SAVE AS

Instantiating the ClassCreating Sub Class• Right click on the Class Block• Select Class Actions > Create Subclass• Can add additional parameters and Blocks

Do’s and Don’t for Class Block
Save all class blocks in a common location
Make sure the location is below a Classpath
Organize the Classes in folders under this Classpath
Use the Open Instance for Listen to Block and Listen to Port ONLY
Do not modify any functionality inside the Open Instance.
◦ This will reflect only in that instance of this Class.
◦ Any changes to the instance is extremely hard to debug.

Dynamic Instantiation• Creates multiple instances of itself during thepreinitialize phase of model execution.
• Each instance of this block behaves exactly like a
Hierarchical block.
• Helps significantly in building large designs where themodel structure scales.

Example of Dynamic Instantiation

DI block from
Model -> Hierarchical_Blocks

Specifies instanceon input & output

Advantages of Dynamic Instantiation• Dynamic Instances solves modeling problems where objects are arbitrarily required.
• Examples are:✔ Mobile units entering, traversing and exiting a coverage area
✔ Creation and deletion of virtual circuits✔ Peer-to-peer protocol connections• Above problems are difficult to model using Static Instantiation✔ Place many copies of a block in a diagram and use block logic to emulate creation and deletion and to branch data to/fromthe appropriate blocks.
✔ Create a primitive that does all the work.

• Static Instantiation requires over-specification and makes model engineering and presentation difficult.

Differences• Modification in one Hierarchical block does not affect another• Changes in Open Block of Class block will be reflected at all places were used
• Changes in Instance will only be reflected in that one location• Open Block for Dynamic Instantiation and Hierarchical Block for Listeners• Open Instance for Classes for Listeners

TrafficData Structure Generation• Traffic✔

Time distribution✔

Requires an input trigger to generate DS✔

Custom list of operations✔

Periodic distribution✔

Read from a file

• TriggeredTraffic• Transaction Sequence• Custom Traffic• Trace• Using RegEX✔

newToken(Value)

Defining Data Structure in Traffic Blocks
Data Structures template• .txt can be located anywhere• .class located in VS_AR/VisualSim/data● Absolute path is required for accessing
files located anywhere.
● File name if located in the$VS/VisualSim/data directory.

Types• Statistics Distribution- Single request, periodic or fixed, uniform within a range, normal,
exponential• Custom- Based on a combination of data size and interface speed. Can also be triggered byexternal event• Trace file- Existing file from hardware bus, network, software thread execution sequence,
instruction order• Sequence- Special case to typically debug with a order such as command of “Read, Write,
Write, Read , or packet sizes of “128, 1512, 256”

Traffic- Double click to configure

This Parameter is an alternate to the
Data_Structure_Name field above. If the user defines afile name here, the above parameter is not considered.

Select the “Time_Distribution”
according to design
Restrict the number oftransactions

Mirabilis Design Inc.

34

ReturnType I - Statistical• Define a distribution• Parameters for mean and standard distribution• Specify values for the Data Structure fields. It can be source, destination, data, priority or bus
delayType II - Custom• If a custom distribution is required or the
Data Structure is generated as a function ofanother activity, or triggered during theflow, use the Triggered Traffic.
• Every time the input port is triggered the
Triggered Traffic block generates atransaction

Type III – Transaction Sequence• Generate transactions or Data Structures in a
specific sequence• Define sequences in the parameter window or
specify a file + path
• Time interval between Data Structure is aparameter• Specify an output processing using the Regular
Expression (RegEx) Language

Type IV – Custom Traffic• Generate data structure during the T_Interval
period• Stalls all transmission during the T_Pause.
• Equally distributes the Number_Of_Transactions
during the T_Interval range.

Plotting, Displays and Statistics

Result• Statistics✔ ResourceStatistics✔ Statistics blocks to collect statistics at intermediate points• Assertions or tests✔ High/low value for scalar✔ Conditional model activity✔ Model termination• Collect data

✔ Write to screen or to files (Excel, text or XML)• Plot data

✔ Bar, Histogram or XY plots✔ Special viewers- Matrix, Image, MPEG and speakers• 3D- Interactive Creation✔ Create custom animated views that resemble the system

Using TimeData Plotter• Plot double values against simulation time
• View or save the results of the simulation in a
XY format.

• Used to depict latency, throughput and othervariables that vary against time.

X-axis : Sim Time (s), Y-axis : Utilization

XY Plotter• Any scalar value against any other scalar value.
Both values must arrive synchronously.

• The X- and Y-axis can have different data values.
• Plots can be Latency vs. Packet Size or Task Delay vs.
Processor Speed.
• The parameters of this block match the fields (orRegEx) of the incoming Data Structure to determine
the coordinates, color and trace identifier (Dataset).
• Values, color, legend defined in fields of incoming
data structure. Plot similar to XYPlotter

Histogram• The plotter accepts data on the input and plots them as ahistogram.
• View the plot in real-time or save for future viewing.

Using Bar Graph• The bar graph plots series• The input is an array

Using Timing Diagram

Need to add details

Text Display• Output to text the data structure and statistics• The input type can be of any type.
• Can be set to Save/View from Post Processor• Cannot be viewed from the Post Processor

writeStats To File
• Generates Statistics for all the blocks in the modelat the end of simulation• Writes into a Text File in the model directoryDifferences between ArchitectureSetup
and Resource Statistics Blocks

Resource Statistics from Architecture setup – Covers all the hardware Blocks

Using Resource Statistics – Generates Stats for Stochastic Blocks like queues, servers ,system resources

Model Location:$VS/doc/Training_Material/Tutorial/General/Statistics_Plotting/Resource-Statistics.xml

Resource Statistics Block output – Covers all the Blocks in Resource_List

Abstraction

Multiple Levels of Abstraction
Stochastic vs Hybrid vs Cycle Accurate

Stochastic•••

Easy to build the target
SoC/System (Starting version)
Stochastic subsystems can be
replaced with more accurate
blocks as required
Get an early estimate on Powerand Performance metrics

Hybrid – More detailed than stochastic, focus
on the application than on the processor
micro architecture
Cycle Accurate – Very detailed
implementation, focus on processor microarchitecture

Algorithms - Adding Custom
BlockScript•Used for :• Custom logic• Scheduling algorithm• Arbitration algorithm

A VERY POWERFUL MODULE• Statistics and plot generation•Can be used to define Resources, Cycle-accurate hardware components and algorithmic behaviors•Can use if, else-if, else, while, for, SWITCH/CASE/BREAK•Can implement dependencies, Task Graphs etc.

Getting Started with Script
1

Drag and drop the Script block from the library

2

Right Click on script -> Customize -> configure ;give a unique Block NameGetting Started with Script
3

Double click on Script; It already has default contents. Delete them4

Now we can add our logic here.

NOTE
Model has to be saved
before running a model
which has scriptHow Does Script block work?
Even if the script has multiple
input ports, the script
doesn’t have to wait for all
input ports to have data to
start execution• When the packets comes into the script, they will be put into a queue called Input Queue• If a script was idle and a packet comes, then it will be processed immediately.
• If a script was busy executing a packet and another packet comes into the script, then the latest packet will
be in the Input Queue until the current execution finishes/stops.
• until the current execution finishes, it can also start the next one when the block DS stalls at a TIMEQ.
The Input Queue is a Virtual QueueScript Overview
1. port_token is the pointer to the currently executing data structure.
2. Do not use the port name to identify the data structure.
3. Script block maintains the currently executing Data Structure at each line.

SEND
FORMAT

What is happening here?
destination can be aport or a virtualconnection like
another script

Here, the data coming to thescript is send out through theoutput port

LABEL:BEGIN
Implementing counter logic: Left or Right

Counter = 0 is executed every time script is
triggered

Counter = 0 is only executed once duringinitialize

All lines of code defined before LABEL:BEGIN is executed atinitialize and all lines of code after LABEL:BEGIN are executed
when an input comes to scriptCan we use “SEND” to send packet toanother Script block?
YES

Packet comes into the second script througha port_name called “virtual”

GTO
FORMAT

GTO -> Go To
GTO(END) -> finish script execution at this line
So script execution stops at line 7.
Line 8 and 9 not executed

GTO(LABEL name) -> sends the execution to that LABELLine 7 to Line 9.
Line 8 wont be executed.

What happens here?

SWITCH

By using a SWITCH CASE logic, we select appropriate operation as per
the parameter value.
FORMAT
Note: Switch always requires a case (default)

if – else
FORMAT

Here, when the counter value reaches 10, westop the script execution. Otherwise, wesend the output.

port_name
port_name = input

port_name = input2

When a packet comes into the script, the port
through which it came in will be the port_name.

TNow and TStop

TNow -> gives the current time in simulation
Tstop -> gives the simulation stop time

TStop is obtained from the top level Digital Simulator

WAIT
During the delay
period, entire script islocked up. No otherline or transaction
can be executed

WAIT(time) -> Provides delay for the time specified
Until the delay is over, script cannot execute other transactions
FORMATTIMEQ
With TIMEQ, the current port_token
is stored in the Queue and a newone can be read from the input
queue to start executing fromLABEL:BEGIN

FORMAT

With TIMEQ, we get line number 5 to execute at simulation
stop time while other Data Structures (DS) will be executed

getBlockStatus
FORMAT
Keyword can be any of the following:“length” -> gives us the current buffer occupancy ( no need to specify Queue Position )“copy” -> gives us the copy of the packet present in the specified Queue“pop” -> pop the Specified Queue virtuallyArbitration algorithm : Queue + ScriptUsing regex to send data to script Virtually
Virtual (<script_block_name>, <data_to_be_sent>)

Task Graph Modeling

Blocks Required To Model a Basic Task
Graph in VisualSim
Traffic Block – Explained in the Section Traffic
Traffic Generator – Explained in the next section
Trace Mapper – Explained in the next section
Mapper Blocks – Explained in the Library Blocks Power Point

System Resource or Processor to represent the hardware on which the task graph will be executed Explained in the Library Blocks Power PointTask Generator Module•Custom Task generator – number of instructions, type of instructions, order of tasks (loop,
random) can be set•More dynamic and distributed traffic profile can be generated•“n” number of Software tasks can be defined•In case software development hasn’t started yet, we can use this module to generate theinstruction traces

5/14/2024

MIRABILIS DESIGN INC.

76

Task Generator – Config File (Instruction Mix Table)

Software tasks

5/14/2024

Number of
instructions pertask

The Total Number of instructions are made up of instructions ofdifferent types. The percentages of each type of instruction is
specified here.
MIRABILIS DESIGN INC.

77

Task Generator - Config File (Instruction Mix Table)

This type descriptor is used in the previous slide.
User can specify the percentage of each type of
instruction for each software operation
5/14/2024

MIRABILIS DESIGN INC.

78

Trace Mapper and structure of CSV Filecontaining traces
Note: File name to be specified
in CSV format onlyTrace Generation using GEM5 or othersimulators compatible with VisualSim
Source CodeCompileriscv64unknown-elfgcc./Source_Code/main.cRun on Spike./riscv-isasim/build/spike -l --logcommits -isa=RV64IMAC./riscvpk/build/pk
a.out
2>gcc_out.log

Generate log

Parse log – remove pk
overheadGen.
data incsv
formatLoadinto themodel

VisualSim
ArchitectDynamic Mapper
Mapping of tasks on▪ Target processor,▪ SystemResource▪ SystemResource_Extend

8/18/2020

MIRABILIS DESIGN INC.

81

Model Showcasing the usage of TraceMapper and Task generator