Commit 4baa0a08 authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

Added functionality to estimate resources.

Regs are calculated, LUTs are estimated by multiplying the Regs in the respective entity
with an experimentally determined min and max factor.
parent 34d95d04
......@@ -33,6 +33,9 @@ use Scalar::Util 'blessed';
use Log::Log4perl qw(get_logger);
use Scalar::Util "looks_like_number";
use Config::Simple;
use Data::Dumper;
use POSIX qw(ceil);
use List::Util qw(max);
use FIJI qw(:all);
......@@ -79,6 +82,7 @@ sub new ($;$$) {
_set_defaults(DESIGNMAP, $fiji_settings_ref->{'design'}, $phase);
$fiji_settings_ref->{'fius'} = [];
}
return $fiji_settings_ref;
}
......@@ -624,4 +628,146 @@ sub _sanitize_design {
return $consts_ref;
}
sub _log2 {
my $val = shift;
return ($val > 0) ? (log($val)/log(2)) : 0;
}
sub calculate_resources {
my $logger = get_logger();
my ($settings_ref) = @_;
# FIXME Don't expect these values to hold...
my $CTRL_COMB_FACTOR_MIN = 0.85; # c5 ft1
my $CTRL_COMB_FACTOR_MAX = 1.2; # c3de0
my $FIU_COMB_FACTOR_RT_MIN = 0.36; # v5max
my $FIU_COMB_FACTOR_RT_MAX = 1.22; # c3 de0
my $FIU_COMB_FACTOR_SI_MIN = 0.42; # v5mid
my $FIU_COMB_FACTOR_SI_MAX = 0.75; # c3 de0
my $BUFFER_COMB_FACTOR_MIN = 0.85; # v5max
my $BUFFER_COMB_FACTOR_MAX = 1.1; # c5 ft1
my $UART_COMB_FACTOR_MIN = 0.9; # v5mid
my $UART_COMB_FACTOR_MAX = 1.83; # c3 de0
my $consts_ref = $settings_ref->{'design'};
my $fiu_ref = $settings_ref->{'fius'};
my $comb_min = 0;
my $comb_max = 0;
my $reg = 0;
my $uart_regs = 0;
my $ctrl_regs = 0;
my $fiu_regs = 0;
my $buffer_regs = 0;
my $rv;
# resources for FIC
# Trigger edge detection
$ctrl_regs += 3;
# number of FSM states
$ctrl_regs += 9;
$logger->debug("Num FIUs: ".@$fiu_ref);
# Number of bytes in a config -> byte counter width
my $fiubytes = ceil((@$fiu_ref*$consts_ref->{'CFGS_PER_MSG'}*$consts_ref->{'FIU_CFG_BITS'})/8.0);
my $cfgbytes = ($consts_ref->{'TIMER_WIDTH'} * $consts_ref->{'CFGS_PER_MSG'} + 4);
$ctrl_regs += ceil(_log2(max($fiubytes,$cfgbytes)));
# CRC
$ctrl_regs += 8; # CRC8
# Error bits
$ctrl_regs += 3; # U/I/C
# Inj-Start bit
$ctrl_regs += 1;
# Reset Counter
$ctrl_regs += ceil(_log2($consts_ref->{'RESET_DUT_IN_DURATION'})) if $consts_ref->{'RESET_DUT_IN_EN'};
# Pattern counter
$ctrl_regs += ceil(_log2($consts_ref->{'CFGS_PER_MSG'})) * 2; # we need to store an older value, too
# ID
$ctrl_regs += 16;
# Timer value storage
$ctrl_regs += $consts_ref->{'TIMER_WIDTH'} * 8 * $consts_ref->{'CFGS_PER_MSG'}; # value storage
# Config
$ctrl_regs += 8; # Config Byte
# Timer Counter value + Idle reg
$ctrl_regs += $consts_ref->{'TIMER_WIDTH'} * 8 + 1;
# resources for UART
$uart_regs += 4; # RX sync
$uart_regs += 3; # RX bit count
$uart_regs += ceil(_log2($consts_ref->{'FREQUENCY'}/$consts_ref->{'BAUDRATE'})); # reciever baud gen
$uart_regs += 4; # RX state
$uart_regs += 3; # TX bit count
$uart_regs += ceil(_log2($consts_ref->{'FREQUENCY'}/$consts_ref->{'BAUDRATE'})); # transmitter baud gen
$uart_regs += 8 + 1; # TX data reg, TX output reg
$uart_regs += 4; # TX state
$uart_regs += 4; # UART -> FIC Output regs
# resources for Buffer
$buffer_regs += 10; # Buffer width * (Depth+1)
$buffer_regs += 3 + 3; # Buffer indices (ceil(log2(depth)) + 1) for rd & wr
$buffer_regs += 2; # Buffer reader state
my $stuck_open_flag = 0;
# resources for FIUs
foreach my $fiu (@$fiu_ref) {
my $this_fiu_reg;
$this_fiu_reg += 12; # we don't assume regs get optimized away when using a single model
$this_fiu_reg += 1 if ($fiu->{'FIU_MODEL'} eq "RUNTIME" or $fiu->{'FIU_MODEL'} eq "DELAY");
if (($fiu->{'FIU_MODEL'} eq "RUNTIME" or $fiu->{'FIU_MODEL'} eq "STUCK_OPEN")) {
# actually, STUCK_OPEN will only be implemented if additionally $fiu->{'FIU_LFSR_MASK'} != 0
# but to give the user a conservative estimate immediately, we omit this condition
$this_fiu_reg += 1;
$stuck_open_flag = 1;
}
if ($fiu->{'FIU_MODEL'} eq "RUNTIME") {
$comb_min += $this_fiu_reg * $FIU_COMB_FACTOR_RT_MIN;
$comb_max += $this_fiu_reg * $FIU_COMB_FACTOR_RT_MAX;
} else {
$comb_min += $this_fiu_reg * $FIU_COMB_FACTOR_SI_MIN;
$comb_max += $this_fiu_reg * $FIU_COMB_FACTOR_RT_MAX;
}
$fiu_regs += $this_fiu_reg
}
# LFSR will get optimized away if it is not used
$ctrl_regs += $consts_ref->{'LFSR_WIDTH'} if $stuck_open_flag != 0;
$logger->debug("ESTIMATE: CTRL will need ~$ctrl_regs registers");
$logger->debug("ESTIMATE: UART will need ~$uart_regs registers");
$logger->debug("ESTIMATE: BUFF will need ~$buffer_regs registers");
$logger->debug("ESTIMATE: FIUS will need ~$fiu_regs registers");
$reg = $ctrl_regs + $buffer_regs + $uart_regs + $fiu_regs;
$comb_min += $ctrl_regs * $CTRL_COMB_FACTOR_MIN;
$comb_max += $ctrl_regs * $CTRL_COMB_FACTOR_MAX;
$comb_min += $buffer_regs * $BUFFER_COMB_FACTOR_MIN;
$comb_max += $buffer_regs * $BUFFER_COMB_FACTOR_MAX;
$comb_min += $uart_regs * $UART_COMB_FACTOR_MIN;
$comb_max += $uart_regs * $UART_COMB_FACTOR_MAX;
$rv->{'regs'} = ceil($reg/10)*10;
$rv->{'comb_min'} = ceil($comb_min/10)*10;
$rv->{'comb_max'} = ceil($comb_max/10)*10;
$logger->debug("ESTIMATE: current config will need ~$rv->{'regs'} registers and ~$rv->{'comb_min'} - $rv->{'comb_max'} LUTs (tech-dependent)");
return $rv;
}
1;
......@@ -31,7 +31,7 @@ use warnings;
use Log::Log4perl qw(get_logger);
use Scalar::Util 'blessed';
use Tk;
use Tk::widgets qw(LabFrame Label Entry Pane Button Dialog Checkbutton CompleteEntry NoteBook);
use Tk::widgets qw(LabFrame Label Entry Pane Button Dialog Checkbutton CompleteEntry NoteBook StatusBar);
use Tk::DynaMouseWheelBind;
......@@ -79,8 +79,9 @@ sub Populate {
$self->SUPER::Populate($args);
$self->_populate_widget($self);
$self->ConfigSpecs(
-nets => [qw/METHOD nets Nets/, undef],
-settings => [qw/METHOD settings Settings/, undef],
-nets => [qw/METHOD nets Nets/, undef],
-settings => [qw/METHOD settings Settings/, undef],
-resources => [qw/METHOD resources Resources/, undef],
);
$self->update();
}
......@@ -117,6 +118,12 @@ sub settings {
return $self->{'settings'}
}
sub resources {
my ($self, $resources) = @_;
$self->{'resources'} = $resources;
$self->update();
}
## @method update()
# @brief redraws the widget on fundamental changes
......@@ -228,6 +235,12 @@ sub update {
my $fiu_ref = @{$self->{'settings'}->{'fius'}}[$i];
$self->_add_fiu($fiu_ref, $i);
}
####
## Calc resource estimate
my $rh = FIJI::Settings::calculate_resources($self->{'settings'});
${$self->{'resources'}} = "~".$rh->{'regs'}." Registers, ".$rh->{'comb_min'}." - ".$rh->{'comb_max'}." LUTs (tech-dependent)";
}
......@@ -610,6 +623,10 @@ sub _update_fields {
}
$net_entry->validate();
$mask_entry->validate();
####
## Calc resource estimate
my $rh = FIJI::Settings::calculate_resources($self->{'settings'});
${$self->{'resources'}} = "~".$rh->{'regs'}." Registers, ".$rh->{'comb_min'}." - ".$rh->{'comb_max'}." LUTs (tech-dependent)";
}
......@@ -686,6 +703,12 @@ sub _validate_entry {
if ($ok) {
$$old_ref = $$new_ref;
}
####
## Calc resource estimate
my $rh = FIJI::Settings::calculate_resources($self->{'settings'});
${$self->{'resources'}} = "~".$rh->{'regs'}." Registers, ".$rh->{'comb_min'}." - ".$rh->{'comb_max'}." LUTs (tech-dependent)";
return 1; # always allow the new value and show the user what happened.
}
......
......@@ -86,13 +86,24 @@ sub main {
_ctrl_frame($self, $mw);
$self->{'resources'} = "...";
$self->{'StatusBar'} = $mw->StatusBar();
$self->{'StatusBar'} ->addLabel(
-relief => 'flat',
-textvariable => \$self->{'resources'},
);
$self->{'FIJISettingsViewer'} = $mw->FIJISettingsViewer(
-settings => $self->{'settings'},
-settings => $self->{'settings'},
-resources => \$self->{'resources'}
)->pack(
'-fill' => 'both',
'-expand' => 1
);
my $icon_base;
if ($^O eq "MSWin32") {
$icon_base = File::Spec->catpath($vol,$libdir,'/fiji_logo');
......
......@@ -6,7 +6,7 @@ log4perl.rootLogger = TRACE, logfile, screen
log4perl.appender.screen = Log::Log4perl::Appender::Screen
log4perl.appender.screen.stderr = 0
log4perl.appender.screen.Threshold = INFO
log4perl.appender.screen.Threshold = DEBUG
log4perl.appender.screen.layout = ${layout_class}
log4perl.appender.screen.layout.ConversionPattern = ${layout_pattern}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment