summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-04-04 15:11:31 +0200
committerDaniel Friesel <derf@finalrewind.org>2017-04-04 15:11:31 +0200
commit398f3d6d86433c32a5b69b3581b4a32e5d22410d (patch)
tree3afe91fcaa42e8e75837c5d28f77fa3576761756 /lib
parent418111ca15c3949a9a29b5ebbe908571ed601e1b (diff)
split up rel_energy inte relative energy to previous state and to next state
Diffstat (limited to 'lib')
-rw-r--r--lib/Kratos/DFADriver.pm38
-rw-r--r--lib/Kratos/DFADriver/Model.pm78
-rw-r--r--lib/MIMOSA/Log.pm2
-rwxr-xr-xlib/dfatool.py19
4 files changed, 96 insertions, 41 deletions
diff --git a/lib/Kratos/DFADriver.pm b/lib/Kratos/DFADriver.pm
index a3473f7..9801d99 100644
--- a/lib/Kratos/DFADriver.pm
+++ b/lib/Kratos/DFADriver.pm
@@ -469,9 +469,15 @@ sub assess_model {
$self->printf_aggr( $transition, 'energy', 'pJ' );
$self->printf_parameterized( $transition, 'energy' );
$self->printf_fit( $transition, 'energy', 'pJ' );
- $self->printf_aggr( $transition, 'rel_energy', 'pJ' );
- $self->printf_parameterized( $transition, 'rel_energy' );
- $self->printf_fit( $transition, 'rel_energy', 'pJ' );
+ $self->printf_aggr( $transition, 'rel_energy_prev', 'pJ' );
+ $self->printf_parameterized( $transition, 'rel_energy_prev' );
+ $self->printf_fit( $transition, 'rel_energy_prev', 'pJ' );
+
+ if ( exists $transition->{rel_energy_next}{median} ) {
+ $self->printf_aggr( $transition, 'rel_energy_next', 'pJ' );
+ $self->printf_parameterized( $transition, 'rel_energy_next' );
+ $self->printf_fit( $transition, 'rel_energy_next', 'pJ' );
+ }
if ( exists $transition->{timeout}{median} ) {
$self->printf_aggr( $transition, 'timeout', 'µs' );
@@ -506,12 +512,14 @@ sub assess_model_tex {
printf("\n%20s", $name);
$self->printf_aggr_tex( $transition, 'energy', '\uJ', 1e6 );
- $self->printf_aggr_tex( $transition, 'rel_energy', '\uJ', 1e6 );
+ $self->printf_aggr_tex( $transition, 'rel_energy_prev', '\uJ', 1e6 );
+ $self->printf_aggr_tex( $transition, 'rel_energy_next', '\uJ', 1e6 );
$self->printf_aggr_tex( $transition, 'duration', 'ms', 1e3 );
$self->printf_count_tex( $transition, 'energy' );
print " \\\\";
$self->printf_eval_tex( $transition, 'energy', '\uJ', 1e6 );
- $self->printf_eval_tex( $transition, 'rel_energy', '\uJ', 1e6 );
+ $self->printf_eval_tex( $transition, 'rel_energy_prev', '\uJ', 1e6 );
+ $self->printf_eval_tex( $transition, 'rel_energy_next', '\uJ', 1e6 );
$self->printf_eval_tex( $transition, 'duration', 'ms', 1e3 );
$self->printf_count_tex;
print " \\\\";
@@ -548,11 +556,14 @@ sub assess_validation {
$self->model->get_transition_by_name($name)->{energy}{static},
$transition, 'energy', 'pJ' );
$self->printf_goodness(
- $self->model->get_transition_by_name($name)->{rel_energy}{static},
- $transition, 'rel_energy', 'pJ' );
+ $self->model->get_transition_by_name($name)->{rel_energy_prev}{static},
+ $transition, 'rel_energy_prev', 'pJ' );
+ if ( exists $transition->{rel_energy_next}{median} ) {
+ $self->printf_goodness(
+ $self->model->get_transition_by_name($name)->{rel_energy_next}{static},
+ $transition, 'rel_energy_next', 'pJ' );
+ }
if ( exists $transition->{timeout}{median} ) {
-
- #$self->printf_goodness('?', $transition, 'timeout', 'µs');
$self->printf_fit( $transition, 'timeout', 'µs' );
}
}
@@ -578,9 +589,10 @@ sub update_model {
$name,
$transition->{duration}{median},
$transition->{energy}{median},
- $transition->{rel_energy}{median}
+ $transition->{rel_energy_prev}{median},
+ $transition->{rel_energy_next}{median}
);
- for my $key (qw(duration energy rel_energy timeout)) {
+ for my $key (qw(duration energy rel_energy_prev rel_energy_next timeout)) {
for my $fname ( keys %{ $transition->{$key}{function} } ) {
$self->model->set_transition_params(
$name, $key, $fname,
@@ -698,7 +710,7 @@ EOF
advice ${adv_type}("% ${class_name}::$transition->{name}(...)") ${ignore_nested} : after() {
tjp->target()->passTransition(${class_name}::statepower[tjp->target()->state],
- $transition->{rel_energy}{static}, $transition->{id},
+ $transition->{rel_energy_prev}{static}, $transition->{id},
${dest_state_id});
};
@@ -709,7 +721,7 @@ EOF
advice execution("% ${class_name}::$transition->{name}(...)") : after() {
tjp->target()->passTransition(${class_name}::statepower[tjp->target()->state],
- $transition->{rel_energy}{static}, $transition->{id},
+ $transition->{rel_energy_prev}{static}, $transition->{id},
${dest_state_id});
};
diff --git a/lib/Kratos/DFADriver/Model.pm b/lib/Kratos/DFADriver/Model.pm
index 67fb318..bf57c49 100644
--- a/lib/Kratos/DFADriver/Model.pm
+++ b/lib/Kratos/DFADriver/Model.pm
@@ -117,17 +117,18 @@ sub parse_xml {
}
my $transition = {
- name => $transition_node->getAttribute('name'),
- duration => { static => 0+($transition_node->getAttribute('duration') // 0) },
- energy => { static => 0+($transition_node->getAttribute('energy') // 0) },
- rel_energy => { static => 0+($transition_node->getAttribute('rel_energy') // 0) },
- parameters => [@parameters],
- origins => [@source_states],
- destination => $dst_node->textContent,
- level => $level_node->textContent,
- id => $transition_index,
- affects => {%affects},
- node => $transition_node,
+ name => $transition_node->getAttribute('name'),
+ duration => { static => 0+($transition_node->getAttribute('duration') // 0) },
+ energy => { static => 0+($transition_node->getAttribute('energy') // 0) },
+ rel_energy_prev => { static => 0+($transition_node->getAttribute('rel_energy_prev') // 0) },
+ rel_energy_next => { static => 0+($transition_node->getAttribute('rel_energy_next') // 0) },
+ parameters => [@parameters],
+ origins => [@source_states],
+ destination => $dst_node->textContent,
+ level => $level_node->textContent,
+ id => $transition_index,
+ affects => {%affects},
+ node => $transition_node,
};
for my $fun_node ( $transition_node->findnodes('./timeoutfunction/*') )
@@ -184,18 +185,36 @@ sub parse_xml {
}
}
- for my $fun_node ( $transition_node->findnodes('./rel_energyfunction/*') )
+ for my $fun_node ( $transition_node->findnodes('./rel_energy_prevfunction/*') )
{
my $name = $fun_node->nodeName;
my $function = $fun_node->textContent;
$function =~ s{^ \n* \s* }{}x;
$function =~ s{\s* \n* $}{}x;
- $transition->{rel_energy}{function}{$name}{raw} = $function;
- $transition->{rel_energy}{function}{$name}{node} = $fun_node;
+ $transition->{rel_energy_prev}{function}{$name}{raw} = $function;
+ $transition->{rel_energy_prev}{function}{$name}{node} = $fun_node;
my $attrindex = 0;
while ( $fun_node->hasAttribute("param${attrindex}") ) {
push(
- @{ $transition->{rel_energy}{function}{$name}{params} },
+ @{ $transition->{rel_energy_prev}{function}{$name}{params} },
+ $fun_node->getAttribute("param${attrindex}")
+ );
+ $attrindex++;
+ }
+ }
+
+ for my $fun_node ( $transition_node->findnodes('./rel_energy_nextfunction/*') )
+ {
+ my $name = $fun_node->nodeName;
+ my $function = $fun_node->textContent;
+ $function =~ s{^ \n* \s* }{}x;
+ $function =~ s{\s* \n* $}{}x;
+ $transition->{rel_energy_next}{function}{$name}{raw} = $function;
+ $transition->{rel_energy_next}{function}{$name}{node} = $fun_node;
+ my $attrindex = 0;
+ while ( $fun_node->hasAttribute("param${attrindex}") ) {
+ push(
+ @{ $transition->{rel_energy_next}{function}{$name}{params} },
$fun_node->getAttribute("param${attrindex}")
);
$attrindex++;
@@ -249,7 +268,8 @@ sub reset {
for my $transition (@{$self->{transitions}}) {
$transition->{node}->removeAttribute('duration');
$transition->{node}->removeAttribute('energy');
- $transition->{node}->removeAttribute('rel_energy');
+ $transition->{node}->removeAttribute('rel_energy_prev');
+ $transition->{node}->removeAttribute('rel_energy_next');
for my $list_node (@{$transition->{node}->findnodes('./timeoutfunction')}) {
for my $fun_name (keys %{$transition->{timeout}{function}}) {
my $fun_node = $transition->{timeout}{function}{$fun_name}{node};
@@ -366,7 +386,7 @@ sub set_transition_params {
}
sub set_transition_data {
- my ( $self, $transition_name, $duration, $energy, $rel_energy ) = @_;
+ my ( $self, $transition_name, $duration, $energy, $rel_energy_prev, $rel_energy_next ) = @_;
my $transition = $self->get_transition_by_name($transition_name);
$duration = sprintf( '%.f', $duration );
@@ -383,17 +403,23 @@ sub set_transition_data {
$transition->{energy}{static} = $energy;
$transition->{node}->setAttribute( 'energy', $energy );
- if (defined $rel_energy) {
- $rel_energy = sprintf('%.f', $rel_energy);
- printf( ", relative energy %d -> %d pJ\n",
- $transition->{rel_energy}{static}, $rel_energy );
+ if (defined $rel_energy_prev) {
+ $rel_energy_prev = sprintf('%.f', $rel_energy_prev);
+ printf( ", relative_prev energy %d -> %d pJ",
+ $transition->{rel_energy_prev}{static}, $rel_energy_prev );
- $transition->{rel_energy}{static} = $rel_energy;
- $transition->{node}->setAttribute( 'rel_energy', $rel_energy );
+ $transition->{rel_energy_prev}{static} = $rel_energy_prev;
+ $transition->{node}->setAttribute( 'rel_energy_prev', $rel_energy_prev );
}
- else {
- print("\n");
+ if (defined $rel_energy_next) {
+ $rel_energy_next = sprintf('%.f', $rel_energy_next);
+ printf( ", relative_next energy %d -> %d pJ",
+ $transition->{rel_energy_next}{static}, $rel_energy_next );
+
+ $transition->{rel_energy_next}{static} = $rel_energy_next;
+ $transition->{node}->setAttribute( 'rel_energy_next', $rel_energy_next );
}
+ print("\n");
}
sub save {
@@ -530,7 +556,7 @@ sub TO_JSON {
}
for my $val ( values %transition_copy ) {
delete $val->{node};
- for my $key (qw(duration energy rel_energy timeout)) {
+ for my $key (qw(duration energy rel_energy_prev rel_energy_next timeout)) {
if ( exists $val->{$key}{function} ) {
$val->{$key} = { %{ $val->{$key} } };
$val->{$key}{function} = { %{ $val->{$key}{function} } };
diff --git a/lib/MIMOSA/Log.pm b/lib/MIMOSA/Log.pm
index 4f7c6a2..8574132 100644
--- a/lib/MIMOSA/Log.pm
+++ b/lib/MIMOSA/Log.pm
@@ -14,7 +14,7 @@ use List::Util qw(sum);
#use Statistics::Basic::StdDev;
our $VERSION = '0.00';
-my $CACHE_VERSION = 5;
+my $CACHE_VERSION = 6;
sub new {
my ( $class, %opt ) = @_;
diff --git a/lib/dfatool.py b/lib/dfatool.py
index 8a07b50..994f8a2 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -21,12 +21,23 @@ def is_numeric(n):
except ValueError:
return False
+def append_if_set(aggregate, data, key):
+ if key in data:
+ aggregate.append(data[key])
+
+def mean_or_none(arr):
+ if len(arr):
+ return np.mean(arr)
+ return -1
+
def aggregate_measures(aggregate, actual):
aggregate_array = np.array([aggregate] * len(actual))
return regression_measures(aggregate_array, np.array(actual))
def regression_measures(predicted, actual):
deviations = predicted - actual
+ if len(deviations) == 0:
+ return {}
measures = {
'mae' : np.mean(np.abs(deviations), dtype=np.float64),
'msd' : np.mean(deviations**2, dtype=np.float64),
@@ -281,8 +292,14 @@ class MIMOSA:
if isa == 'transition':
# subtract average power of previous state
# (that is, the state from which this transition originates)
- data['uW_mean_delta'] = data['uW_mean'] - iterdata[-1]['uW_mean']
+ data['uW_mean_delta_prev'] = data['uW_mean'] - iterdata[-1]['uW_mean']
+ # placeholder to avoid extra cases in the analysis
+ data['uW_mean_delta_next'] = data['uW_mean']
data['timeout'] = iterdata[-1]['us']
+ elif len(iterdata) > 0:
+ # subtract average power of next state
+ # (the state into which this transition leads)
+ iterdata[-1]['uW_mean_delta_next'] = iterdata[-1]['uW_mean'] - data['uW_mean']
iterdata.append(data)