Commit a8cb464b authored by kazushi.kawamura's avatar kazushi.kawamura

Fix bugs and debug comments

parent de0cef62
#include <stdio.h>
#include <stdlib.h>
#define STRLEN 65536
int main(void){
char q[STRLEN], command[STRLEN];
char dir[64] = "../lines128_length256";
FILE *fp;
fp = fopen("q.txt", "r");
if(fp == NULL){
printf("File does not exist.\n");
exit(1);
}
int counter = 1;
while(1){
if(fscanf(fp, "%s", q) == EOF) break;
printf("Q. %d\n", counter++);
sprintf(command, "./%s/sim.exe %s", dir, q);
//printf("(command) %s\n", command);
int ret = system(command);
printf("ret: %d\n", ret);
}
fclose(fp);
return 0;
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "router.hpp" #include "router.hpp"
#define PRINT_SOLUTION
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
using namespace std; using namespace std;
...@@ -50,9 +51,11 @@ int main(int argc, char *argv[]) { ...@@ -50,9 +51,11 @@ int main(int argc, char *argv[]) {
seed = atoi(argv[2]); seed = atoi(argv[2]);
} }
#ifdef PRINT_SOLUTION
int size_x = (boardstr[1] - '0') * 10 + (boardstr[2] - '0'); int size_x = (boardstr[1] - '0') * 10 + (boardstr[2] - '0');
int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0'); int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0');
int size_z = (boardstr[7] - '0'); int size_z = (boardstr[7] - '0');
#endif
// ソルバ実行 // ソルバ実行
ap_int<32> status; ap_int<32> status;
...@@ -68,6 +71,7 @@ int main(int argc, char *argv[]) { ...@@ -68,6 +71,7 @@ int main(int argc, char *argv[]) {
cout << "status = " << (int)status << endl; cout << "status = " << (int)status << endl;
cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl; cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl;
#ifdef PRINT_SOLUTION
// 解表示 // 解表示
cout << "SOLUTION" << endl; cout << "SOLUTION" << endl;
cout << "========" << endl; cout << "========" << endl;
...@@ -80,12 +84,13 @@ int main(int argc, char *argv[]) { ...@@ -80,12 +84,13 @@ int main(int argc, char *argv[]) {
cout << ","; cout << ",";
} }
int i = ((x * MAX_WIDTH + y) << BITWIDTH_Z) | z; int i = ((x * MAX_WIDTH + y) << BITWIDTH_Z) | z;
//cout << setfill('0') << setw(2) << right << (unsigned int)(unsigned char)(boardstr[i]); cout << setfill('0') << setw(3) << right << (unsigned int)(unsigned char)(boardstr[i]);
cout << (unsigned int)(unsigned char)(boardstr[i]); //cout << (unsigned int)(unsigned char)(boardstr[i]);
} }
cout << endl; cout << endl;
} }
} }
#endif
return 0; return 0;
} }
...@@ -244,6 +244,7 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat ...@@ -244,6 +244,7 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat
ap_uint<8> last_target = 255; ap_uint<8> last_target = 255;
// [Step 2] Rip-up 再ルーティング // [Step 2] Rip-up 再ルーティング
cout << "Rip-up Routing" << endl;
ROUTING: ROUTING:
for (ap_uint<16> round = 1; round <= 32768 /* = (2048 * 16) */; round++) { for (ap_uint<16> round = 1; round <= 32768 /* = (2048 * 16) */; round++) {
#pragma HLS LOOP_TRIPCOUNT min=1 max=4000 avg=50 #pragma HLS LOOP_TRIPCOUNT min=1 max=4000 avg=50
...@@ -284,8 +285,6 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat ...@@ -284,8 +285,6 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat
#pragma HLS LOOP_TRIPCOUNT min=1 max=255 avg=50 #pragma HLS LOOP_TRIPCOUNT min=1 max=255 avg=50
weights[paths[target][j]] = 1; weights[paths[target][j]] = 1;
} }
// 対象ラインのスタートの重みも一旦リセット あとで (*) で戻す
weights[starts[target]] = 1;
// (2) 重みを更新 // (2) 重みを更新
ap_uint<8> current_round_weight = new_weight(round); ap_uint<8> current_round_weight = new_weight(round);
...@@ -303,10 +302,18 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat ...@@ -303,10 +302,18 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat
} }
} }
} }
WEIGHT_TERMINAL:
for (ap_uint<8> i = 0; i < (ap_uint<8>)(line_num); i++) {
#pragma HLS LOOP_TRIPCOUNT min=2 max=127 avg=50
weights[starts[i]] = MAX_WEIGHT;
weights[goals[i]] = MAX_WEIGHT;
}
// 対象ラインのスタートの重みも一旦リセット あとで (*) で戻す
weights[starts[target]] = 1;
// 経路探索 // 経路探索
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
cout << "LINE #" << (int)(target + 1) << endl; cout << "(round: " << round << ")" << "LINE #" << (int)(target + 1) << endl;
#endif #endif
search(&(paths_size[target]), paths[target], starts[target], goals[target], weights); search(&(paths_size[target]), paths[target], starts[target], goals[target], weights);
...@@ -611,18 +618,18 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start ...@@ -611,18 +618,18 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start
ap_uint<16> t = prev[goal]; ap_uint<16> t = prev[goal];
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
int dbg_start_xy = start >> BITWIDTH_Z; //int dbg_start_xy = start >> BITWIDTH_Z;
int dbg_start_x = dbg_start_xy / MAX_WIDTH; //int dbg_start_x = dbg_start_xy / MAX_WIDTH;
int dbg_start_y = dbg_start_xy % MAX_WIDTH; //int dbg_start_y = dbg_start_xy % MAX_WIDTH;
int dbg_start_z = start & BITMASK_Z; //int dbg_start_z = start & BITMASK_Z;
int dbg_goal_xy = goal >> BITWIDTH_Z; //int dbg_goal_xy = goal >> BITWIDTH_Z;
int dbg_goal_x = dbg_goal_xy / MAX_WIDTH; //int dbg_goal_x = dbg_goal_xy / MAX_WIDTH;
int dbg_goal_y = dbg_goal_xy % MAX_WIDTH; //int dbg_goal_y = dbg_goal_xy % MAX_WIDTH;
int dbg_goal_z = goal & BITMASK_Z; //int dbg_goal_z = goal & BITMASK_Z;
cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> " //cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> "
<< "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl; // << "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl;
#endif #endif
// バックトラック // バックトラック
...@@ -633,11 +640,11 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start ...@@ -633,11 +640,11 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start
#pragma HLS PIPELINE II=2 #pragma HLS PIPELINE II=2
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
int t_xy = prev[t] >> BITWIDTH_Z; //int t_xy = prev[t] >> BITWIDTH_Z;
int t_x = t_xy / MAX_WIDTH; //int t_x = t_xy / MAX_WIDTH;
int t_y = t_xy % MAX_WIDTH; //int t_y = t_xy % MAX_WIDTH;
int t_z = prev[t] & BITMASK_Z; //int t_z = prev[t] & BITMASK_Z;
cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl; //cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl;
#endif #endif
path[p] = t; // 記録 path[p] = t; // 記録
...@@ -648,8 +655,8 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start ...@@ -648,8 +655,8 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start
*path_size = p; *path_size = p;
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
cout << "max_path_len = " << p << endl; //cout << "max_path_len = " << p << endl;
cout << "max_pq_len = " << max_pq_len << endl; //cout << "max_pq_len = " << max_pq_len << endl;
#endif #endif
} }
...@@ -675,6 +682,7 @@ void pq_push(ap_uint<16> priority, ap_uint<16> data, ap_uint<12> *pq_len, ap_uin ...@@ -675,6 +682,7 @@ void pq_push(ap_uint<16> priority, ap_uint<16> data, ap_uint<12> *pq_len, ap_uin
#pragma HLS INLINE #pragma HLS INLINE
(*pq_len)++; (*pq_len)++;
if ((*pq_len) == 0) { (*pq_len)--; } // Queue is full -> Last element is automatically removed
ap_uint<12> i = (*pq_len); // target ap_uint<12> i = (*pq_len); // target
ap_uint<12> p = (*pq_len) >> 1; // i.e., (*pq_len) / 2; // 親 ap_uint<12> p = (*pq_len) >> 1; // i.e., (*pq_len) / 2; // 親
PQ_PUSH_LOOP: PQ_PUSH_LOOP:
...@@ -707,7 +715,7 @@ void pq_pop(ap_uint<16> *ret_priority, ap_uint<16> *ret_data, ap_uint<12> *pq_le ...@@ -707,7 +715,7 @@ void pq_pop(ap_uint<16> *ret_priority, ap_uint<16> *ret_data, ap_uint<12> *pq_le
ap_uint<16> last_priority = (ap_uint<16>)(pq_nodes[*pq_len] & PQ_PRIORITY_MASK); // 末尾ノードの優先度 ap_uint<16> last_priority = (ap_uint<16>)(pq_nodes[*pq_len] & PQ_PRIORITY_MASK); // 末尾ノードの優先度
PQ_POP_LOOP: PQ_POP_LOOP:
while (1) { while (!(i >> 11)) { // (2018.08.25) Loop condition fixed
#pragma HLS LOOP_TRIPCOUNT min=1 max=8 avg=4 #pragma HLS LOOP_TRIPCOUNT min=1 max=8 avg=4
//#pragma HLS PIPELINE //#pragma HLS PIPELINE
//#pragma HLS UNROLL factor=2 //#pragma HLS UNROLL factor=2
......
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