Skip to content

Commit be4bc6d

Browse files
authored
Merge pull request #680 from os-fpga/pin_c_better_debug_print_for_EDA2774_sync_pln
pin_c: better debug print for EDA-2774 (sync w pln)
2 parents d5c767d + ea59d4f commit be4bc6d

File tree

5 files changed

+284
-58
lines changed

5 files changed

+284
-58
lines changed

pin_c/src/file_readers/pinc_csv_reader.cpp

Lines changed: 120 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ static inline bool ends_with_gpio(const char* z, size_t len) noexcept {
7878

7979
static inline bool starts_with_A2F(const char* z) noexcept {
8080
assert(z);
81+
if (!z[0])
82+
return false;
83+
assert(::strlen(z) >= 3);
8184
return z[0] == 'A' and z[1] == '2' and z[2] == 'F';
8285
}
8386

8487
static inline bool starts_with_F2A(const char* z) noexcept {
8588
assert(z);
89+
if (!z[0])
90+
return false;
91+
assert(::strlen(z) >= 3);
8692
return z[0] == 'F' and z[1] == '2' and z[2] == 'A';
8793
}
8894

@@ -160,9 +166,9 @@ Pin* RapidCsvReader::BCD::annotatePin(const string& udes_pn,
160166

161167
const char* RapidCsvReader::str_Mode_dir(BCD::ModeDir t) noexcept {
162168
// enum ModeDir
163-
// { No_dir, Input_dir, Output_dir, HasBoth_dir, AllEnabled_dir };
169+
// { No_dir, Input_dir, Output_dir, HasBoth_dir, AllEnabled_dir };
164170
static const char* enumS[] =
165-
{"No_dir", "Input_dir", "Output_dir", "HasBoth_dir", "AllEnabled_dir"};
171+
{ "No_dir", "Input_dir", "Output_dir", "HasBoth_dir", "AllEnabled_dir" };
166172
constexpr size_t n = sizeof(enumS) / sizeof(enumS[0]);
167173
static_assert(n == BCD::AllEnabled_dir + 1);
168174
uint i = uint(t);
@@ -172,7 +178,7 @@ const char* RapidCsvReader::str_Mode_dir(BCD::ModeDir t) noexcept {
172178

173179
std::ostream& operator<<(std::ostream& os, const RapidCsvReader::BCD& b) {
174180
os << "(bcd-" << b.row_ << ' '
175-
<< " grp:" << b.groupA_ << " " << b.bump_ << " " << b.customer_ << " "
181+
<< " grp:" << b.groupA_ << " " << b.bump_B_ << " " << b.customer_ << " "
176182
<< b.ball_ID_ << " ITP: " << b.IO_tile_pin_ << " XYZ: " << b.xyz_
177183
<< " colM:" << b.col_M_ << " fc:" << b.fullchipName_
178184
<< " ci:" << b.customerInternal() << " axi:" << int(b.is_axi_)
@@ -218,7 +224,7 @@ string RapidCsvReader::Tile::key2() const noexcept {
218224
}
219225

220226
// returns spreadsheet column label ("A", "B", "BC", etc) for column index 'i'
221-
static inline string label_column(int i) noexcept {
227+
string RapidCsvReader::label_of_column(int i) noexcept {
222228
assert(i >= 0 && i < 1000);
223229
string label;
224230

@@ -277,7 +283,10 @@ static bool get_row_modes(const fio::CSV_Reader& crd, uint rowNum,
277283

278284
const string* R = crd.getRow(rowNum);
279285
if (!R) {
280-
lout() << "\nERROR reading csv: failed row: " << rowNum << endl;
286+
flush_out(true);
287+
err_puts();
288+
lprintf2("[Error] pin_c: ERROR reading csv: failed row: %u\n", rowNum+2);
289+
flush_out(true);
281290
return false;
282291
}
283292

@@ -293,7 +302,7 @@ static bool get_row_modes(const fio::CSV_Reader& crd, uint rowNum,
293302
}
294303

295304
if (ltrace() >= 8) {
296-
lout() << "ROW-" << rowNum;
305+
lout() << "ROW-" << rowNum+2;
297306
for (uint c = 0; c < nc; c++) lout() << " | " << R[c];
298307
lputs(" |");
299308
}
@@ -344,7 +353,7 @@ bool RapidCsvReader::initCols(const fio::CSV_Reader& crd) {
344353
<< col_headers_.front() << " ... " << col_headers_.back() << ']' << endl;
345354
if (tr >= 5) {
346355
for (uint i = 0; i < nc; i++) {
347-
string col_label = label_column(i);
356+
string col_label = label_of_column(i);
348357
const string& hdr_i = col_headers_[i];
349358
ls << "--- " << i << '-' << col_label << " hdr_i= " << hdr_i << endl;
350359
}
@@ -582,14 +591,14 @@ bool RapidCsvReader::createTiles(bool uniq_XY) {
582591
// 2. add tiles_ avoiding duplicates if possible
583592
tPool.emplace_back(bcd_good_[first_valid_k]->xyz_,
584593
bcd_good_[first_valid_k]->groupA_,
585-
bcd_good_[first_valid_k]->bump_,
594+
bcd_good_[first_valid_k]->bump_B_,
586595
first_valid_k);
587596
for (uint k = first_valid_k + 1; k < sz_bcd_good; k++) {
588597
const BCD& bcd = *bcd_good_[k];
589598
const XY& loc = bcd.xyz_;
590-
if (tPool.back().eq(loc, bcd.bump_))
599+
if (tPool.back().eq(loc, bcd.bump_B_))
591600
continue;
592-
tPool.emplace_back(loc, bcd.groupA_, bcd.bump_, k);
601+
tPool.emplace_back(loc, bcd.groupA_, bcd.bump_B_, k);
593602
}
594603

595604
uint sz = tPool.size();
@@ -885,7 +894,7 @@ bool RapidCsvReader::read_csv(const string& fn, uint num_udes_pins) {
885894
mode_names_.reserve(col_headers_.size());
886895
start_MODE_col_ = 0;
887896
for (uint col = 0; col < col_headers_.size(); col++) {
888-
string col_label = label_column(col);
897+
string col_label = label_of_column(col);
889898
const string& orig_hdr_i = col_headers_[col]; // before case conversion
890899
hdr_i = orig_hdr_i;
891900

@@ -1114,15 +1123,15 @@ bool RapidCsvReader::read_csv(const string& fn, uint num_udes_pins) {
11141123

11151124
for (uint i = 0; i < num_rows; i++) {
11161125
BCD& bcd = *bcd_[i];
1117-
bcd.bump_ = bump_pin_name[i];
1118-
if (bcd.bump_.empty()) {
1126+
bcd.bump_B_ = bump_pin_name[i];
1127+
if (bcd.bump_B_.empty()) {
11191128
if (bcd.customerInternal().empty() && tr >= 4) {
1120-
lprintf(" (WW) both bcd.bump_ and bcd.customerInternal_ are empty on row# %u\n", i);
1129+
lprintf(" (WW) both bcd.bump_B_ and bcd.customerInternal_ are empty on row# %u\n", i);
11211130
// assert(0);
11221131
}
11231132
}
11241133
bcd.normalize();
1125-
// assert(!bcd.bump_.empty()); // no-assert, could be clock: colM = F2CLK
1134+
// assert(!bcd.bump_B_.empty()); // no-assert, could be clock: colM = F2CLK
11261135
}
11271136

11281137
flush_out(false);
@@ -1225,15 +1234,25 @@ bool RapidCsvReader::read_csv(const string& fn, uint num_udes_pins) {
12251234
}
12261235
}
12271236

1237+
bool always_print = ::getenv("pinc_always_print_csv");
1238+
bool write_debug = (tr >= 8 or ::getenv("pinc_write_debug_csv"));
1239+
12281240
if (tr >= 6) {
12291241
flush_out(false);
12301242
print_bcd_stats(lout());
12311243
flush_out(true);
12321244
print_axi_bcd(lout());
12331245
flush_out(false);
1234-
print_csv();
1246+
if (tr >= 7 or always_print) {
1247+
print_csv();
1248+
}
1249+
} else if (always_print) {
1250+
print_csv();
12351251
}
12361252

1253+
if (write_debug)
1254+
write_debug_csv();
1255+
12371256
flush_out(false);
12381257
return true;
12391258
}
@@ -1336,13 +1355,15 @@ uint RapidCsvReader::print_axi_bcd(std::ostream& os) const noexcept {
13361355
}
13371356

13381357
void RapidCsvReader::print_csv() const {
1339-
flush_out(false);
1358+
flush_out(true);
13401359
lputs("print_csv()");
13411360
auto& ls = lout();
13421361
ls << "#row\tBump/Pin Name \t Customer Name \t Ball ID "
1343-
<< "\t IO_tile_pin\t IO_tile_pin_x\tIO_tile_pin_y\tIO_tile_pin_z"
1362+
<< " IO_tile_pin\t X Y Z"
1363+
<< " \t column-M"
1364+
<< " rxtx_dir"
13441365
<< " \t Customer Internal Name" << endl;
1345-
string dash = str::sReplicate('-', 139u);
1366+
string dash = str::sReplicate('-', 131u);
13461367
ls << dash << endl;
13471368

13481369
uint num_rows = numRows();
@@ -1351,17 +1372,93 @@ void RapidCsvReader::print_csv() const {
13511372
const BCD& b = *bcd_[i];
13521373
const XYZ& p = b.xyz_;
13531374
lprintf("%-5u ", i + 2);
1354-
lprintf(" %12s ", b.bump_.c_str());
1375+
lprintf(" %12s ", b.bump_B_.c_str());
13551376
lprintf(" %22s ", b.customer_.c_str());
13561377
lprintf(" %6s ", b.ball_ID_.c_str());
13571378
ls << "\t " << b.IO_tile_pin_ << "\t " << p.x_ << " " << p.y_ << " "
1358-
<< p.z_;
1379+
<< p.z_ << " ";
1380+
lprintf(" %10s ", b.col_M_.c_str());
1381+
lprintf(" %16s ", str_Mode_dir(b.rxtx_dir_));
1382+
if (b.dirContradiction()) {
1383+
ls << " DIR_CONTRADICTION ";
1384+
}
13591385
lprintf(" %22s ", b.customerInternal().c_str());
13601386
ls << endl;
13611387
}
13621388

13631389
ls << dash << endl;
1364-
ls << "Total Records: " << num_rows << endl;
1390+
lprintf("Total Records: %u\n", num_rows);
1391+
flush_out(true);
1392+
}
1393+
1394+
void RapidCsvReader::write_debug_csv() const {
1395+
flush_out(true);
1396+
string cwd = get_CWD();
1397+
lprintf("write_debug_csv() in work_dir = %s\n", cwd.c_str());
1398+
1399+
CStr fn = "DEBUG_PINC_PT.csv";
1400+
std::ofstream fos(fn);
1401+
if (not fos.is_open()) {
1402+
flush_out(true);
1403+
lprintf2("ERROR write_debug_csv() could not open file for writing: %s\n", fn);
1404+
flush_out(true);
1405+
return;
1406+
}
1407+
1408+
lprintf(" writing %s ...\n", fn);
1409+
1410+
fos << "#row\tBump/Pin Name \t Customer Name \t Ball ID "
1411+
<< " IO_tile_pin\t X Y Z"
1412+
<< " \t column-M"
1413+
<< " rxtx_dir"
1414+
<< " \t Customer Internal Name" << endl;
1415+
string dash = str::sReplicate('-', 131u);
1416+
fos << dash << endl;
1417+
1418+
uint num_rows = numRows();
1419+
assert(bcd_.size() == num_rows);
1420+
for (uint i = 0; i < num_rows; i++) {
1421+
const BCD& b = *bcd_[i];
1422+
const XYZ& p = b.xyz_;
1423+
os_printf(fos, "%-5u ", i + 2);
1424+
os_printf(fos, " %12s ", b.bump_B_.c_str());
1425+
os_printf(fos, " %22s ", b.customer_.c_str());
1426+
os_printf(fos, " %6s ", b.ball_ID_.c_str());
1427+
fos << "\t " << b.IO_tile_pin_ << "\t " << p.x_ << " " << p.y_ << " "
1428+
<< p.z_ << " ";
1429+
os_printf(fos, " %10s ", b.col_M_.c_str());
1430+
os_printf(fos, " %16s ", str_Mode_dir(b.rxtx_dir_));
1431+
if (b.dirContradiction()) {
1432+
os_printf(fos, " DIR_CONTRADICTION ");
1433+
}
1434+
os_printf(fos, " %22s ", b.customerInternal().c_str());
1435+
fos << endl;
1436+
}
1437+
1438+
fos << dash << endl;
1439+
1440+
lprintf(" wrote %s\n", fn);
1441+
flush_out(true);
1442+
}
1443+
1444+
vector<uint> RapidCsvReader::get_enabled_rows_for_mode(const string& mode) const noexcept {
1445+
if (mode.empty())
1446+
return {};
1447+
uint col_idx = getModeCol(mode);
1448+
if (!col_idx)
1449+
return {};
1450+
vector<string> col = crd_->getColumn(mode);
1451+
if (col.empty())
1452+
return {};
1453+
1454+
vector<uint> result;
1455+
result.reserve(col.size());
1456+
for (uint r = 0; r < col.size(); r++) {
1457+
if (col[r] == "Y")
1458+
result.push_back(r);
1459+
}
1460+
1461+
return result;
13651462
}
13661463

13671464
XYZ RapidCsvReader::get_axi_xyz_by_name(const string& axi_name,
@@ -1589,7 +1686,7 @@ string RapidCsvReader::bumpName2CustomerName(
15891686
// tmp linear search
15901687
for (uint i = 0; i < num_rows; i++) {
15911688
const BCD& bcd = *bcd_[i];
1592-
if (bcd.bump_ == bump_nm) return bcd.customer_;
1689+
if (bcd.bump_B_ == bump_nm) return bcd.customer_;
15931690
}
15941691

15951692
return {};

pin_c/src/file_readers/pinc_csv_reader.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class RapidCsvReader {
5353
// --- 12-M EFPGA_PIN
5454
// --- 13-N Fullchip_NAME
5555
// --- 72-BU Customer Internal Name
56-
string bump_, // 1-B
56+
string bump_B_, // 1-B
5757
customer_, // 2-C Customer Name
5858
ball_ID_; // 3-D
5959

@@ -105,8 +105,8 @@ class RapidCsvReader {
105105
void normalize() noexcept {
106106
if (customerInternal_.empty())
107107
return;
108-
if (bump_.empty())
109-
bump_ = customerInternal_;
108+
if (bump_B_.empty())
109+
bump_B_ = customerInternal_;
110110
if (customer_.empty())
111111
customer_ = customerInternal_;
112112
}
@@ -117,6 +117,16 @@ class RapidCsvReader {
117117
bool isNotBidiRxTx() const noexcept { return rxtx_dir_ != HasBoth_dir and rxtx_dir_ != AllEnabled_dir; }
118118
bool allModesEnabledRxTx() const noexcept { return rxtx_dir_ == AllEnabled_dir; }
119119

120+
bool dirContradiction() const noexcept {
121+
if (isBidiRxTx())
122+
return false;
123+
if (isA2F() and isOutputRxTx())
124+
return true;
125+
if (isF2A() and isInputRxTx())
126+
return true;
127+
return false;
128+
}
129+
120130
std::bitset<MAX_PT_COLS> getRxModes() const noexcept;
121131
std::bitset<MAX_PT_COLS> getTxModes() const noexcept;
122132
std::bitset<MAX_PT_COLS> getGpioModes() const noexcept;
@@ -159,7 +169,7 @@ class RapidCsvReader {
159169
bool operator==(const Tile& t) const noexcept { return loc_ == t.loc_ && colB_ == t.colB_; }
160170
bool operator!=(const Tile& t) const noexcept { return not operator==(t); }
161171
bool eq(const XY& loc, const string& colb) const noexcept { return loc_ == loc && colB_ == colb; }
162-
bool eq(const BCD& bcd) const noexcept { return eq(bcd.xyz_, bcd.bump_); }
172+
bool eq(const BCD& bcd) const noexcept { return eq(bcd.xyz_, bcd.bump_B_); }
163173

164174
BCD* bestInputSite() noexcept;
165175
BCD* bestOutputSite() noexcept;
@@ -206,6 +216,9 @@ class RapidCsvReader {
206216
bool write_csv(const string& fn, uint minRow, uint maxRow) const;
207217

208218
void print_csv() const;
219+
void write_debug_csv() const;
220+
221+
vector<uint> get_enabled_rows_for_mode(const string& mode) const noexcept;
209222

210223
uint countBidiRows() const noexcept;
211224

@@ -244,7 +257,7 @@ class RapidCsvReader {
244257

245258
const string& bumpPinName(uint row) const noexcept {
246259
assert(row < bcd_.size());
247-
return bcd_[row]->bump_;
260+
return bcd_[row]->bump_B_;
248261
}
249262

250263
const string& customerPinName(uint row) const noexcept {
@@ -298,6 +311,8 @@ class RapidCsvReader {
298311

299312
static const char* str_Mode_dir(BCD::ModeDir t) noexcept;
300313

314+
static string label_of_column(int i) noexcept;
315+
301316
private:
302317

303318
bool initCols(const fio::CSV_Reader& crd);

0 commit comments

Comments
 (0)