Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operation/iIR/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ include_directories(${EIGEN3_INCLUDE_DIRS})
aux_source_directory(./ SRC)
add_library(iir-api ${SRC} )

target_link_libraries(iir-api ir_solver ir-matrix Eigen3::Eigen pg-netlist)
target_link_libraries(iir-api ir_solver ir-matrix Eigen3::Eigen pg-netlist spef)
96 changes: 94 additions & 2 deletions src/operation/iIR/api/iIR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,98 @@
*/
#include "iIR.hh"

#include <cstddef>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "SpefParser.hh"
#include "iir-rust/IRRustC.hh"
#include "ir-solver/IRSolver.hh"
#include "log/Log.hh"
#include "matrix/IRMatrix.hh"
#include "usage/usage.hh"

namespace {

template <typename T>
RustVec MakeRustVec(std::vector<T>& values) {
RustVec rust_vec;
rust_vec.data = values.data();
rust_vec.len = values.size();
rust_vec.cap = values.capacity();
rust_vec.type_size = sizeof(T);
return rust_vec;
}

struct RustSpefNetStorage {
std::vector<RustSpefConn> conns;
std::vector<RustSpefResCap> caps;
std::vector<RustSpefResCap> ress;
};

const void* CreateRcDataFromSpefExchange(const ista::spef::Exchange& exchange) {
std::vector<RustSpefNetStorage> storage;
storage.reserve(exchange.nets.size());

std::vector<RustSpefNet> rust_nets;
rust_nets.reserve(exchange.nets.size());

for (const auto& spef_net : exchange.nets) {
auto& net_storage = storage.emplace_back();
net_storage.conns.reserve(spef_net.conns.size());
net_storage.caps.reserve(spef_net.caps.size());
net_storage.ress.reserve(spef_net.ress.size());

for (const auto& conn : spef_net.conns) {
net_storage.conns.push_back(
RustSpefConn{conn.pin_port_name.c_str(),
conn.conn_type == ista::spef::ConnectionType::kExternal});
}

for (const auto& cap : spef_net.caps) {
net_storage.caps.push_back(
RustSpefResCap{cap.node1.c_str(), cap.node2.c_str(),
cap.res_or_cap});
}

for (const auto& res : spef_net.ress) {
net_storage.ress.push_back(
RustSpefResCap{res.node1.c_str(), res.node2.c_str(),
res.res_or_cap});
}

rust_nets.push_back(RustSpefNet{spef_net.name.c_str(),
MakeRustVec(net_storage.conns),
MakeRustVec(net_storage.caps),
MakeRustVec(net_storage.ress)});
}

return create_rc_data_from_spef(MakeRustVec(rust_nets));
}

const void* ReadSpefRcData(std::string_view spef_file_path) {
ista::spef::SpefReader spef_parser;
const std::string spef_path(spef_file_path);
if (!spef_parser.read(spef_path)) {
LOG_ERROR << "read spef file " << spef_path << " failed";
return nullptr;
}

spef_parser.expandName();
auto* spef_file = spef_parser.getSpefFile();
if (spef_file == nullptr) {
LOG_ERROR << "read spef file " << spef_path << " produced no SPEF data";
return nullptr;
}

return CreateRcDataFromSpefExchange(*spef_file);
}

} // namespace

namespace iir {

/**
Expand All @@ -53,10 +136,19 @@ unsigned iIR::init() {
* @return
*/
unsigned iIR::readSpef(std::string_view spef_file_path) {
_rc_data = read_spef(spef_file_path.data());
return 1;
_rc_data = ReadSpefRcData(spef_file_path);
return _rc_data == nullptr ? 0 : 1;
};

void BuildMatrixFromRawData(const char* c_inst_power_path,
const char* c_power_net_spef) {
auto* rc_data = ReadSpefRcData(c_power_net_spef);
if (rc_data == nullptr) {
return;
}
build_matrices_from_rc_data(c_inst_power_path, rc_data);
}

/**
* @brief read instance power db file to build current vector.
*
Expand Down
12 changes: 0 additions & 12 deletions src/operation/iIR/source/iir-rust/IRRustC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,3 @@
*
*/
#include "IRRustC.hh"

namespace iir {

void BuildMatrixFromRawData(const char *c_inst_power_path,
const char *c_power_net_spef) {
// auto matrix_data = build_matrix_from_raw_data(c_inst_power_path, c_power_net_spef);
// fix warning: variable 'matrix_data' set but not used [-Wunused-but-set-variable]
build_matrix_from_raw_data(c_inst_power_path, c_power_net_spef);

}

} // namespace iir
29 changes: 22 additions & 7 deletions src/operation/iIR/source/iir-rust/IRRustC.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,32 @@ typedef struct RustNetConductanceData {
const void *ir_net_raw_ptr;
} RustNetConductanceData;

typedef struct RustSpefConn {
const char *name;
bool is_external;
} RustSpefConn;

typedef struct RustSpefResCap {
const char *node1;
const char *node2;
double value;
} RustSpefResCap;

typedef struct RustSpefNet {
const char *name;
struct RustVec conns;
struct RustVec caps;
struct RustVec ress;
} RustSpefNet;

// iterator for access hash map
void *create_hashmap_iterator(void *hashmap);
bool hashmap_iterator_next(void *iterator, uintptr_t *out_key, double *out_value);
void destroy_hashmap_iterator(void *iterator);

void init_iir(void);

const void *read_spef(const char *c_power_net_spef);
const void *create_rc_data_from_spef(struct RustVec spef_nets);

const void *create_pg_node(const void *c_pg_netlist, const void *c_pg_node);

Expand Down Expand Up @@ -61,11 +79,8 @@ double get_sum_resistance(const void *c_rc_data, const char *c_net_name);
struct RustNetConductanceData build_one_net_conductance_matrix_data(
const void *c_rc_data, const char *c_net_name);

/**
* Build RC matrix and current vector data.
*/
struct RustVec build_matrix_from_raw_data(const char *c_inst_power_path,
const char *c_power_net_spef);
void build_matrices_from_rc_data(const char *c_inst_power_path,
const void *c_rc_data);

/**
* Build one net instance current vector.
Expand All @@ -85,4 +100,4 @@ namespace iir {
void BuildMatrixFromRawData(const char *c_inst_power_path,
const char *c_power_net_spef);

}
}
Loading
Loading