Skip to content

Commit

Permalink
Step sim UI (backwards and refresh) (#398)
Browse files Browse the repository at this point in the history
* Added refresh popup dialog

* Added restart sim if steps are overwritten by new data

* Added refresh popup

* Added backwards button, check for sim restart
  • Loading branch information
lucasng32 authored Sep 9, 2023
1 parent 52a8399 commit 2deaba9
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 97 deletions.
21 changes: 21 additions & 0 deletions src/Renderer/DrawBlock/PopupHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,27 @@ let dialogPopup title body buttonText buttonAction isDisabled extraStyle dispatc
]
dynamicClosablePopup title body foot extraStyle dispatch

// Used for refresh popup
let dialogPopupRefresh title body extraStyle dispatch =
let foot =
fun (model: Model) ->
let dialogData = model.PopupDialogData
Level.level [ Level.Level.Props [ Style [ Width "100%" ] ] ] [
Level.left [] []
Level.right [] [
Level.item [] [
Button.button [
Button.Color IsLight
Button.OnClick (fun _ ->
dispatch ClosePopup
dispatch FinishUICmd)
] [ str "Cancel" ]
]
]
]

dynamicClosablePopup title body foot extraStyle dispatch

/// Popup with an input textbox and two buttons.
/// The text is reflected in Model.PopupDialogText.
let dialogVerilogPopup title body saveUpdateText noErrors showingExtraInfo saveButtonAction moreInfoButton isDisabled extraStyle dispatch =
Expand Down
10 changes: 7 additions & 3 deletions src/Renderer/Simulator/Fast/FastReduce.fs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,15 @@ let fastReduce (maxArraySize: int) (numStep: int) (isClockedReduction: bool) (co
/// get last cycle data from output i for component
let inline insOldUInt32 i =
checkInputPortNumber i
comp.GetInputUInt32 (simStepOld) (InputPortNumber i)
match numStep with
| 0 -> 0u
| _ -> comp.GetInputUInt32 (simStepOld) (InputPortNumber i)

let inline insOldBigInt i =
checkInputPortNumber i
comp.GetInputBigInt (simStepOld) (InputPortNumber i)
match numStep with
| 0 -> 0I
| _ -> comp.GetInputBigInt (simStepOld) (InputPortNumber i)

/// Write current step output data for output port pn
let inline putUInt32 pn fd = comp.PutOutputUInt32 (simStep) (OutputPortNumber pn) fd
Expand Down Expand Up @@ -328,7 +332,7 @@ let fastReduce (maxArraySize: int) (numStep: int) (isClockedReduction: bool) (co
| Constant(width, cVal), true -> putBigInt 0 <| (convertInt64ToBigInt width cVal)
| Output width, false ->
let bits = insUInt32 0
//printfn "In output bits=%A, ins = %A" bits comp.InputLinks
// printfn "In output bits=%A, ins = %A" bits comp.InputLinks
checkWidth width (comp.InputWidth 0)
putUInt32 0 bits
| Output width, true ->
Expand Down
60 changes: 48 additions & 12 deletions src/Renderer/Simulator/Fast/FastRun.fs
Original file line number Diff line number Diff line change
Expand Up @@ -509,24 +509,54 @@ let buildFastSimulationFData

/// sets up default no-change input values for the next step
let private propagateInputsFromLastStep (step: int) (fastSim: FastSimulation) =
if step > 0 then
fastSim.FGlobalInputComps
|> Array.iter (fun fc ->
let vec = fc.Outputs[0]
if vec.Width > 32 then
vec.BigIntStep[step] <- vec.BigIntStep[step - 1]
else
vec.UInt32Step[step] <- vec.UInt32Step[step - 1])
let stepsim =
if step = 0 then
fastSim.MaxArraySize
else
step
fastSim.FGlobalInputComps
|> Array.iter (fun fc ->
let vec = fc.Outputs[0]
if vec.Width > 32 then
vec.BigIntStep[step] <- vec.BigIntStep[stepsim - 1]
else
vec.UInt32Step[step] <- vec.UInt32Step[stepsim - 1])


let private setInputstoDefault (fastSim: FastSimulation) =
fastSim.FGlobalInputComps
|> Array.iter (fun fc ->
match fc.FType with
| Input1(w, defaultVal) ->
match defaultVal with
| Some defaultVal ->
let vec = fc.Outputs[0]
if vec.Width > 32 then
vec.BigIntStep[0] <- bigint defaultVal
else
vec.UInt32Step[0] <- uint32 defaultVal
| None -> ()
| _ -> ()
)

/// advance the simulation one step
let private stepSimulation (fs: FastSimulation) =
let index = (fs.ClockTick + 1) % fs.MaxArraySize // index of circular array

propagateInputsFromLastStep index fs
Array.iter (fastReduce fs.MaxArraySize index true) fs.FClockedComps
Array.iter (fastReduce fs.MaxArraySize index false) fs.FOrderedComps
Array.iter (fastReduce fs.MaxArraySize (fs.ClockTick + 1) true) fs.FClockedComps
Array.iter (fastReduce fs.MaxArraySize (fs.ClockTick + 1) false) fs.FOrderedComps

fs.ClockTick <- fs.ClockTick + 1

/// set simulation data for clock tick 0 when regenerating data
let private restartSimulation (fs: FastSimulation) =
setInputstoDefault fs
Array.iter (fastReduce fs.MaxArraySize 0 true) fs.FClockedComps
Array.iter (fastReduce fs.MaxArraySize 0 false) fs.FOrderedComps

fs.ClockTick <- 0

/// sets the mutable simulation data for a given input at a given time step
let private setSimulationInput (cid: ComponentId) (fd: FastData) (step: int) (fs: FastSimulation) =
match Map.tryFind (cid, []) fs.FComps, fd.Width with
Expand Down Expand Up @@ -635,12 +665,18 @@ let extractStatefulComponents (step: int) (fastSim: FastSimulation) =
let runFastSimulation (timeOut: float option) (lastStepNeeded: int) (fs: FastSimulation) : float option =
if fs.MaxArraySize = 0 then
failwithf "ERROR: can't run a fast simulation with 0 length arrays!"
//printfn $"running sim steps={numberOfSteps}, arraySize = {fs.MaxArraySize}, maxstepnum={fs.MaxStepNum}"
// printfn $"running sim clocktick={fs.ClockTick}, arraySize = {fs.MaxArraySize}, laststepneeded={lastStepNeeded}"
let simStartTime = getTimeMs ()
let stepsToDo = lastStepNeeded - fs.ClockTick

if stepsToDo <= 0 then
None // do nothing
if (fs.ClockTick - lastStepNeeded) < 550 then
None
else
restartSimulation fs
while fs.ClockTick < lastStepNeeded do
stepSimulation fs
None
else
let startTick = fs.ClockTick
let mutable time = simStartTime
Expand Down
Loading

0 comments on commit 2deaba9

Please sign in to comment.