Skip to content

Commit

Permalink
add dump_power (#70)
Browse files Browse the repository at this point in the history
* add power to opentimer

* cleanup the compute power API

* read the voltage needed for power compute
  • Loading branch information
renau authored Oct 1, 2022
1 parent 8b70a65 commit e57dff6
Show file tree
Hide file tree
Showing 18 changed files with 487 additions and 60 deletions.
4 changes: 3 additions & 1 deletion example/simple/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ int main(int argc, char *argv[]) {
}

// dump the timing graph to dot format for debugging
timer.dump_graph(std::cout);
//timer.dump_graph(std::cout);
timer.dump_at(std::cout);
timer.dump_power(std::cout);

return 0;
}
Expand Down
137 changes: 135 additions & 2 deletions ot/liberty/celllib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,56 @@ Cell* Celllib::cell(const std::string& name) {
}
}

// Function: _extract_operating_conditions
std::optional<float> Celllib::_extract_operating_conditions(token_iterator& itr, const token_iterator end) {

std::optional<float> voltage;
std::string operating_condition_name;

if(itr=on_next_parentheses(
itr,
end,
[&] (auto& name) mutable { operating_condition_name = name; }); itr == end) {
OT_LOGF("can't find lut template name");
}

// Extract the lut template group
if(itr = std::find(itr, end, "{"); itr == end) {
OT_LOGF("can't find lut template group brace '{'");
}

//std::cout << lt.name << std::endl;

int stack = 1;

while(stack && ++itr != end) {

// variable 1
if(*itr == "voltage") { // Read the variable.

if(++itr == end) {
OT_LOGF("volate error in operating_conditions template ", operating_condition_name);
}

voltage = std::strtof(std::string(*itr).c_str(), nullptr);
}
else if(*itr == "}") {
stack--;
}
else if(*itr == "{") {
stack++;
}
else {
}
}

if(stack != 0 || *itr != "}") {
OT_LOGF("can't find operating_conditions template group brace '}'");
}

return voltage;
}

// Function: _extract_lut_template
LutTemplate Celllib::_extract_lut_template(token_iterator& itr, const token_iterator end) {

Expand Down Expand Up @@ -342,6 +392,51 @@ Lut Celllib::_extract_lut(token_iterator& itr, const token_iterator end) {
return lut;
}

// Function: _extract_internal_power
InternalPower Celllib::_extract_internal_power(token_iterator& itr, const token_iterator end) {

InternalPower power;

// Extract the lut template group
if(itr = std::find(itr, end, "{"); itr == end) {
OT_LOGF("can't find group brace '{' in timing");
}

int stack = 1;

while(stack && ++itr != end) {

if (*itr == "rise_power") {
power.rise_power = _extract_lut(itr, end);
}
else if (*itr == "fall_power") { // Rise delay.
power.fall_power = _extract_lut(itr, end);
}
else if (*itr == "related_pin") {

if(++itr == end) {
OT_LOGF("syntax error in related_pin");
}

power.related_pin = *itr;
}
else if(*itr == "}") {
stack--;
}
else if(*itr == "{") {
stack++;
}
else {
}
}

if(stack != 0 || *itr != "}") {
OT_LOGF("can't find group brace '}' in internal_power");
}

return power;
}

// Function: _extract_timing
Timing Celllib::_extract_timing(token_iterator& itr, const token_iterator end) {

Expand Down Expand Up @@ -513,8 +608,39 @@ Cellpin Celllib::_extract_cellpin(token_iterator& itr, const token_iterator end)
OT_LOGF_IF(++itr == end, "can't get the original pin in cellpin ", cellpin.name);
cellpin.original_pin = *itr;
}
else if(*itr == "internal_power") {
auto ipower = _extract_internal_power(itr, end);
bool found = false;
for(auto &t:cellpin.timings) {
if (t.related_pin != ipower.related_pin)
continue;

t.internal_power = ipower;
found = true;
break;
}
if (!found) {
Timing t;
t.related_pin = ipower.related_pin;
t.internal_power = ipower;
cellpin.timings.emplace_back(t);
}
}
else if(*itr == "timing") {
cellpin.timings.push_back(_extract_timing(itr, end));
auto ti = _extract_timing(itr, end);
bool found = false;
for(auto &t:cellpin.timings) {
if (t.related_pin != ti.related_pin)
continue;
auto ipower_copy = t.internal_power;
t = ti;
t.internal_power = ipower_copy;
found = true;
break;
}
if (!found) {
cellpin.timings.push_back(ti);
}
}
else if(*itr == "}") {
stack--;
Expand Down Expand Up @@ -638,6 +764,10 @@ void Celllib::read(const std::filesystem::path& path) {
auto lut = _extract_lut_template(itr, end);
lut_templates[lut.name] = lut;
}
else if(*itr == "power_lut_template") {
auto lut = _extract_lut_template(itr, end);
lut_templates[lut.name] = lut;
}
else if(*itr == "delay_model") {
OT_LOGF_IF(++itr == end, "syntax error in delay_model");
if(auto ditr = delay_models.find(*itr); ditr != delay_models.end()) {
Expand Down Expand Up @@ -675,8 +805,11 @@ void Celllib::read(const std::filesystem::path& path) {
OT_LOGF_IF(++itr == end, "syntax error in default_max_transition");
default_max_transition = std::strtof(itr->data(), nullptr);
}
else if(*itr == "operating_conditions") {
OT_LOGF_IF(++itr == end, "syntax error in operating_conditions");
voltage = _extract_operating_conditions(itr, end);
// TODO: Unit field.
else if(*itr == "time_unit") {
}else if(*itr == "time_unit") {
OT_LOGF_IF(++itr == end, "time_unit syntax error");
time_unit = make_time_unit(*itr);
}
Expand Down
14 changes: 9 additions & 5 deletions ot/liberty/celllib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct Celllib {
std::optional<ampere_t> current_unit;
std::optional<volt_t> voltage_unit;

std::optional<float> voltage;

std::optional<float> default_cell_leakage_power;
std::optional<float> default_inout_pin_cap;
std::optional<float> default_input_pin_cap;
Expand Down Expand Up @@ -71,11 +73,13 @@ struct Celllib {

private:

LutTemplate _extract_lut_template(token_iterator&, const token_iterator);
Lut _extract_lut (token_iterator&, const token_iterator);
Cell _extract_cell (token_iterator&, const token_iterator);
Cellpin _extract_cellpin (token_iterator&, const token_iterator);
Timing _extract_timing (token_iterator&, const token_iterator);
std::optional<float> _extract_operating_conditions(token_iterator& itr, const token_iterator end);
LutTemplate _extract_lut_template (token_iterator&, const token_iterator);
Lut _extract_lut (token_iterator&, const token_iterator);
Cell _extract_cell (token_iterator&, const token_iterator);
Cellpin _extract_cellpin (token_iterator&, const token_iterator);
InternalPower _extract_internal_power(token_iterator&, const token_iterator);
Timing _extract_timing (token_iterator&, const token_iterator);

void _apply_default_values();
void _uncomment(std::vector<char>&);
Expand Down
3 changes: 2 additions & 1 deletion ot/liberty/lut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ inline const std::unordered_map<std::string_view, LutVar> lut_vars {
{"input_net_transition", LutVar::INPUT_NET_TRANSITION},
{"constrained_pin_transition", LutVar::CONSTRAINED_PIN_TRANSITION},
{"related_pin_transition", LutVar::RELATED_PIN_TRANSITION},
{"input_transition_timing", LutVar::INPUT_TRANSITION_TIME}
{"input_transition_timing", LutVar::INPUT_TRANSITION_TIME},
{"input_transition_time", LutVar::INPUT_TRANSITION_TIME}
};

// Function: is_time_lut_var
Expand Down
114 changes: 114 additions & 0 deletions ot/liberty/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,119 @@

namespace ot {

void InternalPower::scale_time(float s) {

if(rise_power) {
rise_power->scale_time(s);
}

if(fall_power) {
fall_power->scale_time(s);
}
}

void InternalPower::scale_capacitance(float s) {

if(rise_power) {
rise_power->scale_capacitance(s);
}

if(fall_power) {
fall_power->scale_capacitance(s);
}
}

std::optional<float> InternalPower::power(Tran irf, Tran orf, float time, float load) const {

const Lut* lut {nullptr};

switch(orf) {
case RISE:
lut = rise_power ? &(rise_power.value()) : nullptr;
break;

case FALL:
lut = fall_power ? &(fall_power.value()) : nullptr;
break;

default:
assert(false);
break;
};

if(lut == nullptr) {
return std::nullopt;
}

// Case 1: scalar.
if(lut->lut_template == nullptr) {
if(lut->is_scalar()) {
return lut->table[0];
}
else {
OT_LOGF("lut without template must contain a single scalar");
}
}

// Case 2: non-scalar table.
float val1 {.0f}, val2 {.0f};

// - obtain the input numerics
assert(lut->lut_template->variable1);

switch(*(lut->lut_template->variable1)) {

case LutVar::TOTAL_OUTPUT_NET_CAPACITANCE:
if(lut->lut_template->variable2) {
assert(lut->lut_template->variable2 == LutVar::INPUT_TRANSITION_TIME);
}
val1 = load;
val2 = time;
break;

case LutVar::INPUT_TRANSITION_TIME:
if(lut->lut_template->variable2) {
assert(lut->lut_template->variable2 == LutVar::TOTAL_OUTPUT_NET_CAPACITANCE);
}
val1 = time;
val2 = load;
break;

default:
OT_LOGF("invalid power lut template variable");
break;
};

// - perform the linear inter/extro-polation on indices1 and indices2
return (*lut)(val1, val2);
}

std::ostream& operator << (std::ostream& os, const InternalPower& power) {

// Write the timing.
os << " internal_power () {\n";

// Write the related pin (from cellpin).
os << " related_pin : \"" << power.related_pin << "\";\n";

if(power.rise_power) {
os << " rise_power (\"" << power.rise_power->name << "\") {\n";
os << *(power.rise_power);
os << " }\n";
}

if(power.fall_power) {
os << " fall_power (\"" << power.fall_power->name << "\") {\n";
os << *(power.fall_power);
os << " }\n";
}

// Write the ending group symbol.
os << " }\n";

return os;
}

}; // end of namespace ot. -----------------------------------------------------------------------


8 changes: 7 additions & 1 deletion ot/liberty/power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ namespace ot {
struct InternalPower {

std::string related_pin;

std::optional<Lut> rise_power;
std::optional<Lut> fall_power;

void scale_time(float s);
void scale_capacitance(float s);

std::optional<float> power(Tran, Tran, float, float) const;
};

std::ostream& operator << (std::ostream&, const InternalPower&);

}; // end of namespace ot. -----------------------------------------------------------------------


Expand Down
8 changes: 8 additions & 0 deletions ot/liberty/timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ void Timing::scale_time(float s) {
if(fall_constraint) {
fall_constraint->scale_time(s);
}

internal_power.scale_time(s);
}

// Procedure: scale_capacitance
Expand Down Expand Up @@ -402,6 +404,8 @@ void Timing::scale_capacitance(float s) {
if(fall_constraint) {
fall_constraint->scale_capacitance(s);
}

internal_power.scale_capacitance(s);
}

// Function: delay
Expand Down Expand Up @@ -695,6 +699,10 @@ std::ostream& operator << (std::ostream& os, const Timing& timing) {
// Write the ending group symbol.
os << " }\n";

if (!timing.internal_power.related_pin.empty()) {
os << timing.internal_power;
}

return os;
}

Expand Down
Loading

0 comments on commit e57dff6

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy