Commit fec93bd3 by Yijun Tan

electric force bugged

parent 6c0b5d11
images/* images/*
.vscode/* .vscode/*
.build/* .build/*
.data/* .data/*
\ No newline at end of file test.cpp
a.exe
\ No newline at end of file
No preview for this file type
...@@ -1274,7 +1274,7 @@ Pin P60 4298 0 ...@@ -1274,7 +1274,7 @@ Pin P60 4298 0
LibCell N MC221 50 33 1 LibCell N MC221 50 33 1
Pin P1 25 16 Pin P1 25 16
DieSize 0 0 23000 19000 DieSize 0 0 23000 38000
TopDieMaxUtil 80 TopDieMaxUtil 80
BottomDieMaxUtil 80 BottomDieMaxUtil 80
This source diff could not be displayed because it is too large. You can view the blob instead.
NumTechnologies 2 NumTechnologies 2
Tech TA 3 Tech TA 3
LibCell N MC1 7 10 1 LibCell N MC1 400 300 1
Pin P1 2 7 Pin P1 2 7
LibCell N MC2 14 10 2 LibCell N MC2 14 10 2
Pin P1 10 4 Pin P1 10 4
...@@ -20,7 +20,7 @@ Pin P1 2 12 ...@@ -20,7 +20,7 @@ Pin P1 2 12
Pin P2 3 3 Pin P2 3 3
Pin P3 15 7 Pin P3 15 7
DieSize 0 0 40 60 DieSize 0 0 800 600
TopDieMaxUtil 80 TopDieMaxUtil 80
BottomDieMaxUtil 90 BottomDieMaxUtil 90
...@@ -35,35 +35,7 @@ TerminalSize 6 6 ...@@ -35,35 +35,7 @@ TerminalSize 6 6
TerminalSpacing 5 TerminalSpacing 5
TerminalCost 10 TerminalCost 10
NumInstances 8 NumInstances 1
Inst C1 MC1 Inst C1 MC1
Inst C2 MC3
Inst C3 MC3
Inst C4 MC2
Inst C5 MC2
Inst C6 MC3
Inst C7 MC2
Inst C8 MC1
NumNets 6 NumNets 0
Net N1 2 \ No newline at end of file
Pin C1/P1
Pin C2/P2
Net N2 3
Pin C2/P1
Pin C3/P1
Pin C7/P2
Net N3 2
Pin C2/P3
Pin C8/P1
Net N4 3
Pin C3/P3
Pin C6/P2
Pin C7/P1
Net N5 3
Pin C4/P2
Pin C6/P1
Pin C5/P1
Net N6 2
Pin C4/P1
Pin C5/P2
...@@ -16,7 +16,7 @@ public: ...@@ -16,7 +16,7 @@ public:
float scale; //visualizer scale float scale; //visualizer scale
public: public:
void init(); void init(int);
void makeCellList(); void makeCellList();
void setCellTechs(); void setCellTechs();
void makeInstList(); void makeInstList();
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
//cimg //cimg
#if VISUAL #if VISUAL
void draw(std::string, int Scale=1); void draw(std::string, int Scale=1);
void plotDensity(cimg_library::CImg<unsigned char>&);
void plotCells(cimg_library::CImg<unsigned char>&); void plotCells(cimg_library::CImg<unsigned char>&);
void plotNets(cimg_library::CImg<unsigned char>&); void plotNets(cimg_library::CImg<unsigned char>&);
void drawLine(cimg_library::CImg<unsigned char>&, const int, const int, const int, const int, const unsigned int, const unsigned char[]); void drawLine(cimg_library::CImg<unsigned char>&, const int, const int, const int, const int, const unsigned int, const unsigned char[]);
......
...@@ -13,7 +13,7 @@ int main() { ...@@ -13,7 +13,7 @@ int main() {
std::string picname; std::string picname;
circuit->init(); circuit->init(0);
picname = "initial.bmp"; picname = "initial.bmp";
circuit->draw(picname); circuit->draw(picname);
...@@ -24,11 +24,11 @@ int main() { ...@@ -24,11 +24,11 @@ int main() {
std::cout << "Electric potential apply." << std::endl; std::cout << "Electric potential apply." << std::endl;
for (int i = 0; i < 30; ++i) { for (int i = 0; i < 1; ++i) {
circuit->Iteration(i); circuit->Iteration(i);
std::cout << "HPWL:" << circuit->calHPWL() << std::endl; std::cout << "HPWL:" << circuit->calHPWL() << std::endl;
if (i % 1 == 0) { if ((i+1) % 1 == 0) {
picname = "iter" + std::to_string(i) + ".bmp"; picname = "iter" + std::to_string(i) + ".bmp";
circuit->draw(picname); circuit->draw(picname);
......
#include "Circuit.h" #include "Circuit.h"
void Circuit::init() { void Circuit::init(int init_iter) {
makeCellList(); makeCellList();
//makePinList(); //makePinList();
//makeNetList(); //makeNetList();
...@@ -9,15 +9,12 @@ void Circuit::init() { ...@@ -9,15 +9,12 @@ void Circuit::init() {
std::cout << "HPWL: " << calHPWL() << std::endl; std::cout << "HPWL: " << calHPWL() << std::endl;
initialPlacement(30); initialPlacement(init_iter);
std::cout << "HPWL: " << calHPWL() << std::endl; std::cout << "HPWL: " << calHPWL() << std::endl;
fftinit(); fftinit();
for (int i = 0; i < 10; ++i) {
std::cout << "moving force -5: " << fftbin->electricDensity[i][i] << " " << fftbin->electricDensity[i][i]<< std::endl;
}
//std::cout << "h 1" << std::endl; //std::cout << "h 1" << std::endl;
std::cout << "HPWL 0: " << calHPWL() << std::endl; std::cout << "HPWL 0: " << calHPWL() << std::endl;
cellClassify(); cellClassify();
...@@ -36,13 +33,51 @@ void Circuit::init() { ...@@ -36,13 +33,51 @@ void Circuit::init() {
void Circuit::makeCellList() { void Circuit::makeCellList() {
//issue 0 two die average area
//compute filler cell size
float totalArea[2] = {0, 0};
int filler_num[2] = {0, 0};
int stdcell_num = 0;
for (int i = 0; i < tech_num; ++i) {
float averageArea = 0;
for (int j = 0; j < cell_num; ++j) {
Cell c = techs[i][cells[j]];
if (!c.is_macro) {
++stdcell_num;
averageArea += c.area;
}
totalArea[i] += c.area;
//std::cout << "averageArea: " << averageArea << std::endl;
}
averageArea /= static_cast<float>(stdcell_num);
std::cout << "averageArea: " << averageArea << std::endl;
float averageWidth = sqrt(averageArea);
techs[i][0] = Cell(averageWidth, averageWidth);
techs[i][0].is_filler = true;
for (int j = 0; j < techs[i].size(); ++j) {
//std::cout << techs[i][j].h << " " << techs[i][j].w << std::endl;
}
//std::cout << h << " " << w << " " << die_infro[0].MaxUtil << " " << h * w << std::endl;
float moveableArea = static_cast<float>(h)*w*die_infro[0].MaxUtil/100;
float fillerArea = moveableArea - totalArea[i];
filler_num[i] = std::floor(fillerArea / averageArea);
//std::cout << " moveable area: "<< moveableArea << " total area: " << totalArea[i] << std::endl;
}
//float moveable_space = die_infro //float moveable_space = die_infro
filler_num = 0;//cell_num / 2; filler_num[0] = 0;//cell_num / 2;
allcell_num = cell_num + filler_num; std::cout << "filler num: " << filler_num[0] <<std::endl;
allcell_num = cell_num + filler_num[0];
//addstdcell //addstdcell
std::mt19937 genX(std::random_device{}()); std::mt19937 genX(10);
std::mt19937 genY(std::random_device{}()); std::mt19937 genY(std::random_device{}());
std::uniform_real_distribution<float> disX(0, h); std::uniform_real_distribution<float> disX(0, h);
std::uniform_real_distribution<float> disY(0, w); std::uniform_real_distribution<float> disY(0, w);
...@@ -57,35 +92,20 @@ void Circuit::makeCellList() { ...@@ -57,35 +92,20 @@ void Circuit::makeCellList() {
} }
//issue 0 two die average area
//compute filler cell size
for (int i = 0; i < tech_num; ++i) {
float averageArea = 0;
for (int j = 0; j < cell_num; ++j) {
averageArea += techs[i][cells[j]].area;
//std::cout << "averageArea: " << averageArea << std::endl;
}
averageArea /= static_cast<float>(cell_num);
std::cout << "averageArea: " << averageArea << std::endl;
float averageWidth = sqrt(averageArea);
techs[i][0] = Cell(averageWidth, averageWidth);
techs[i][0].is_filler = true;
for (int j = 0; j < techs[i].size(); ++j) {
std::cout << techs[i][j].h << " " << techs[i][j].w << std::endl;
}
}
//add filler cell //add filler cell
std::cout << "filler cell: " << std::endl; std::cout << "filler cell: " << std::endl;
for (int i = cell_num; i < allcell_num; ++i) { for (int i = cell_num; i < allcell_num; ++i) {
cell_pos[i] = std::make_pair(floor(disX(genX)), floor(disY(genY))); cell_pos[i] = std::make_pair(floor(disX(genX)), floor(disY(genX)));
std::cout << cell_pos[i].first << " " << cell_pos[i].second << std::endl; //std::cout << cell_pos[i].first << " " << cell_pos[i].second << std::endl;
} }
//for (int i = 0; i < 10; ++i) {
//std::cout << floor(disX(genX)) << " " << floor(disY(genX)) << std::endl;
//}
} }
...@@ -115,18 +135,22 @@ void Circuit::preCalWL() { ...@@ -115,18 +135,22 @@ void Circuit::preCalWL() {
net_center.resize(net_num); net_center.resize(net_num);
for (int i = 0; i < net_num; ++i) { for (int i = 0; i < net_num; ++i) {
//std::cout << i << std::endl;
std::pair<float, float> tmp = std::make_pair(0.0f, 0.0f); std::pair<float, float> tmp = std::make_pair(0.0f, 0.0f);
for (int j = 0; j < nets[i].size(); ++j) { for (int j = 0; j < nets[i].size(); ++j) {
//std::cout << i << " " << j << std::endl; //if (i > 18600)
// std::cout << "i, j= " << i << " " << j << std::endl;
//std::cout << nets[i][j].first << std::endl; //std::cout << nets[i][j].first << std::endl;
int inst_id = nets[i][j].first; int inst_id = nets[i][j].first;
int pin_id = nets[i][j].second; int pin_id = nets[i][j].second;
//std::cout << "pre caling: " << inst_id << " " << pin_id << std::endl; //if (i > 18600)
// std::cout << "pre caling: " << inst_id << " " << pin_id << std::endl;
int cell_id = cells[inst_id]; int cell_id = cells[inst_id];
std::pair<float, float> pin_pos = techs[layer[i]][cell_id].pins[pin_id]; std::pair<float, float> pin_pos = techs[layer[inst_id]][cell_id].pins[pin_id];
//std::cout << "cell_pos: " << cell_pos[inst_id].first << " " << cell_pos[inst_id].second << std::endl; //if (i > 18600)
// std::cout << "cell_pos: " << cell_pos[inst_id].first << " " << cell_pos[inst_id].second << std::endl;
tmp.first += cell_pos[inst_id].first + pin_pos.first; tmp.first += cell_pos[inst_id].first + pin_pos.first;
tmp.second += cell_pos[inst_id].second + pin_pos.second; tmp.second += cell_pos[inst_id].second + pin_pos.second;
...@@ -192,7 +216,7 @@ void Circuit::initialPlacement(int iteration=30) { ...@@ -192,7 +216,7 @@ void Circuit::initialPlacement(int iteration=30) {
force[i].second = 0; force[i].second = 0;
std::cout << i << " " << force[i].first << " " << force[i].second << std::endl; //std::cout << i << " " << force[i].first << " " << force[i].second << std::endl;
forcesumx += force[i].first; forcesumx += force[i].first;
forcesumy += force[i].second; forcesumy += force[i].second;
...@@ -200,7 +224,7 @@ void Circuit::initialPlacement(int iteration=30) { ...@@ -200,7 +224,7 @@ void Circuit::initialPlacement(int iteration=30) {
} }
std::cout << "force sum check: " << forcesumx << " " << forcesumy << std::endl; std::cout << "force sum check: " << forcesumx << " " << forcesumy << std::endl;
print(); //print();
moveCellCoordinates(); moveCellCoordinates();
...@@ -212,7 +236,7 @@ void Circuit::initialPlacement(int iteration=30) { ...@@ -212,7 +236,7 @@ void Circuit::initialPlacement(int iteration=30) {
//std::cout << "hpwl: " << hpwl << std::endl; //std::cout << "hpwl: " << hpwl << std::endl;
print(); //print();
if (iter % 5 == 0) { if (iter % 5 == 0) {
...@@ -416,7 +440,7 @@ void Circuit::fftinit() { ...@@ -416,7 +440,7 @@ void Circuit::fftinit() {
} }
for (int i = 0; i < binsize_y; ++i) { for (int i = 0; i < binsize_y; ++i) {
fftbin->wy[i] = M_PI * static_cast<float>(i) / static_cast<float>(binsize_y); fftbin->wy[i] = M_PI * static_cast<float>(i) / static_cast<float>(binsize_y) * static_cast<float>(fftbin->size_y) / static_cast<float>(fftbin->size_x);
fftbin->wy_sq[i] = fftbin->wy[i] * fftbin->wy[i]; fftbin->wy_sq[i] = fftbin->wy[i] * fftbin->wy[i];
} }
...@@ -490,10 +514,11 @@ void Circuit::cellClassify() { ...@@ -490,10 +514,11 @@ void Circuit::cellClassify() {
fftbin->correspondCells[i].resize(binsize_y); fftbin->correspondCells[i].resize(binsize_y);
for (int j = 0; j < binsize_y; ++j) { for (int j = 0; j < binsize_y; ++j) {
fftbin->correspondCells[i][j].clear(); fftbin->correspondCells[i][j].clear();
//fftbin->correspondCells[i][j].resize(0);
} }
} }
//std::cout << "herh " << std::endl; //std::cout << "herh " << std::endl;
int binIdx_x, binIdx_y; int binIdx_x, binIdx_y;
for (int i = 0; i < allcell_num; ++i) { for (int i = 0; i < allcell_num; ++i) {
int cell_id = cells[i]; int cell_id = cells[i];
...@@ -523,33 +548,39 @@ void Circuit::Iteration(int iternum) { ...@@ -523,33 +548,39 @@ void Circuit::Iteration(int iternum) {
int cell_len = fftbin->correspondCells[i][j].size(); int cell_len = fftbin->correspondCells[i][j].size();
for (int k = 0; k < cell_len; ++k) { for (int k = 0; k < cell_len; ++k) {
//std::cout << "check 0: " << cell_len << k << std::endl;
int cel = fftbin->correspondCells[i][j][k]; int cel = fftbin->correspondCells[i][j][k];
float e_Density = fftbin->electricDensity[i][j]; //float e_Density = fftbin->electricDensity[i][j];
float cell_area = insts[cel].area; float cell_area = insts[cel].area;
//apply electric force //apply electric force
//std::cout << "check 1: " << std::endl;
force[cel].first = fftbin->electricField_x[i][j] * cell_area; force[cel].first = fftbin->electricField_x[i][j] * cell_area;
force[cel].second= fftbin->electricField_y[i][j] * cell_area; force[cel].second= fftbin->electricField_y[i][j] * cell_area;
// is filler cell // is filler cell
if (cel > cell_num) { //std::cout << "check 2: " << std::endl;
if (cel < cell_num) {
std::pair<float, float> wireforce = calWLf(cel); std::pair<float, float> wireforce = calWLf(cel);
force[cel].first += wireforce.first; force[cel].first += wireforce.first;
force[cel].second += wireforce.second; force[cel].second += wireforce.second;
} }
//std::cout << "check 3: " << std::endl;
float friction_x = frictionCoefficient * velocity[cel].first; float friction_x = frictionCoefficient * velocity[cel].first;
float friction_y = frictionCoefficient * velocity[cel].second; float friction_y = frictionCoefficient * velocity[cel].second;
force[cel].first -= friction_x; force[cel].first -= friction_x;
force[cel].second -= friction_y; force[cel].second -= friction_y;
/* //std::cout << "check 4: " << std::endl;
if (friction_x * force[cel].first > 0 && abs(friction_x) > abs(force[cel].first)) if (friction_x * force[cel].first > 0 && abs(friction_x) > abs(force[cel].first))
force[cel].first = 0; force[cel].first = 0;
if (friction_y * force[cel].second > 0 && abs(friction_y) > abs(force[cel].second)) if (friction_y * force[cel].second > 0 && abs(friction_y) > abs(force[cel].second))
force[cel].second = 0; force[cel].second = 0;
*/
} }
...@@ -557,18 +588,39 @@ void Circuit::Iteration(int iternum) { ...@@ -557,18 +588,39 @@ void Circuit::Iteration(int iternum) {
} }
//print(); //print();
for (int i = 0; i < binsize_x ; ++i) {
for (int j = 0; j < binsize_y; ++j) {
std::cout << fftbin->electricDensity[i][j] << " ";
}
std::cout << std::endl;
}
std::string picname;
picname = "check0.bmp";
draw(picname);
//std::cout << "HPWL 4:" << calHPWL() << std::endl; //std::cout << "HPWL 4:" << calHPWL() << std::endl;
moveCellCoordinates(); moveCellCoordinates();
//std::cout << "HPWL 5:" << calHPWL() << std::endl; //std::cout << "HPWL 5:" << calHPWL() << std::endl;
cellClassify(); cellClassify();
//std::cout << "HPWL 6:" << calHPWL() << std::endl; //std::cout << "HPWL 6:" << calHPWL() << std::endl;
updateDensity(); updateDensity();
for (int i = 0; i < binsize_x ; ++i) {
for (int j = 0; j < binsize_y; ++j) {
std::cout << fftbin->electricDensity[i][j] << " ";
}
std::cout << std::endl;
}
//std::cout << "HPWL 7:" << calHPWL() << std::endl; //std::cout << "HPWL 7:" << calHPWL() << std::endl;
doFFT(); doFFT();
picname = "check1.bmp";
draw(picname);
print(); //print();
//checkCellPlace(); //checkCellPlace();
...@@ -625,28 +677,45 @@ void Circuit::plotCells(cimg_library::CImg<unsigned char>& image) { ...@@ -625,28 +677,45 @@ void Circuit::plotCells(cimg_library::CImg<unsigned char>& image) {
drawLine(image, ll_x, ur_y, ur_x, ll_y, 2, Color::BLACK); drawLine(image, ll_x, ur_y, ur_x, ll_y, 2, Color::BLACK);
} }
else { else {
image.draw_rectangle(ll_x, ll_y, ur_x, ur_y, Color::RED); image.draw_rectangle(ll_x, ll_y, ur_x, ur_y, Color::LIGHT_GREEN);
} }
} }
for (int i = 0; i < binsize_x; ++i) {
for (int j = 0; j < binsize_y; ++j) { for (int i = 0; i < binsize_x; i = i+4) {
for (int j = 0; j < binsize_y; j = j+4) {
//std::cout << fftbin->size_x << " " << fftbin->size_y << std::endl; //std::cout << fftbin->size_x << " " << fftbin->size_y << std::endl;
int ctx = (fftbin->coordx[i]+fftbin->size_x/2) / scale; int ctx = (fftbin->coordx[i]+fftbin->size_x/2) / scale;
int cty = (fftbin->coordy[j]+fftbin->size_y/2) / scale; int cty = (fftbin->coordy[j]+fftbin->size_y/2) / scale;
//std::cout << fftbin->electricField_x[i][j] << std::endl; //std::cout << fftbin->electricField_x[i][j] << std::endl;
int ctx2 = ctx + fftbin->electricField_x[i][j] / 50 / scale; int ctx2 = ctx + fftbin->electricField_x[i][j] / 1 / scale;
int cty2 = cty + fftbin->electricField_y[i][j] / 50 / scale; int cty2 = cty + fftbin->electricField_y[i][j] / 1 / scale;
//std::cout << ctx << " " << cty << " " << ctx2 << " " << cty2 << std::endl; //std::cout << ctx << " " << cty << " " << ctx2 << " " << cty2 << std::endl;
drawLine(image, ctx, cty, ctx2, cty2, 1, Color::RED); drawLine(image, ctx, cty, ctx2, cty2, 2, Color::RED);
} }
} }
for (int i = 0; i < binsize_x; ++i) { for (int i = 0; i < binsize_x; ++i) {
// std::cout << fftbin->coordx[i] << " " << fftbin->coordy[i] << std::endl; // std::cout << fftbin->coordx[i] << " " << fftbin->coordy[i] << std::endl;
} }
//plotDensity(image);
}
void Circuit::plotDensity(cimg_library::CImg<unsigned char>& image) {
for (int i = 0; i < binsize_x; ++i) {
for (int j = 0; j <binsize_y; ++j) {
float tmp = 255 - 255*fftbin->electricDensity[i][j] * densityScale;
//std::cout << i << " " << j << " " << tmp << std::endl;
unsigned char c[] = {tmp, tmp, tmp};
image.draw_rectangle(fftbin->coordx[i]/scale, fftbin->coordx[j]/scale, fftbin->coordx[i+1]/scale, fftbin->coordy[j+1]/scale, c);
}
}
} }
void Circuit::plotNets(cimg_library::CImg<unsigned char>& image) { void Circuit::plotNets(cimg_library::CImg<unsigned char>& image) {
......
...@@ -29,7 +29,7 @@ void Database::readcase(std::string inputfilename) ...@@ -29,7 +29,7 @@ void Database::readcase(std::string inputfilename)
//ss >> techs[i][cell_name].w; //ss >> techs[i][cell_name].w;
//ss >> techs[i][cell_name].h; //ss >> techs[i][cell_name].h;
std::cout << cell_name << " " << techs[i][j+1].is_macro << " " << techs[i][j+1].area << std::endl; //std::cout << cell_name << " " << techs[i][j+1].is_macro << " " << techs[i][j+1].area << std::endl;
int pin_num; int pin_num;
ss >> pin_num; ss >> pin_num;
......
...@@ -61,7 +61,7 @@ void fftBin::doFFT() { ...@@ -61,7 +61,7 @@ void fftBin::doFFT() {
float wwy2 = wy_sq[j]; float wwy2 = wy_sq[j];
float density = electricDensity[i][j]; float density = electricDensity[i][j];
float phi = 000; float phi = 0;
float electroX = 0, electroY = 0; float electroX = 0, electroY = 0;
if (i == 0 && j == 0) { if (i == 0 && j == 0) {
phi = electroX = electroY = 0.0f; phi = electroX = electroY = 0.0f;
......
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