...
 
Commits (53)
This diff is collapsed.
This diff is collapsed.
SIZE 8X8X8
LAYER 1
2,35,35,35,15,19,17,9
7,35,37,37,15,15,17,11
7,35,37,39,0,0,0,11
7,35,37,39,0,0,0,11
0,35,37,39,0,0,0,11
0,35,37,39,0,11,11,11
0,11,11,11,11,11,3,4
1,0,0,0,0,0,3,4
LAYER 2
2,33,31,0,43,19,41,9
25,0,31,0,43,15,17,11
25,0,31,0,43,15,17,13
7,7,7,7,0,15,17,13
27,27,27,7,0,15,17,13
0,0,0,7,0,15,17,13
25,25,0,7,0,17,17,0
1,25,0,7,7,7,3,4
LAYER 3
2,33,0,0,41,19,41,9
41,41,41,41,41,19,0,9
25,0,31,0,0,19,0,9
25,31,31,0,19,19,0,9
27,31,27,27,27,27,27,9
25,31,30,30,30,15,9,9
25,31,30,0,19,9,9,0
1,25,25,19,19,9,3,4
LAYER 4
2,33,0,0,41,41,41,21
0,33,47,23,48,48,0,45
0,33,47,23,0,48,0,45
25,33,47,23,19,48,0,45
25,33,0,23,19,48,0,45
25,33,0,23,19,15,0,45
0,30,30,23,19,15,0,45
1,1,1,21,21,15,4,4
LAYER 5
2,6,16,22,22,0,0,21
46,6,16,22,24,29,29,21
46,16,16,22,24,29,34,21
46,16,47,22,24,0,34,21
46,16,47,22,24,48,34,21
46,22,47,22,24,48,34,21
46,22,47,47,24,48,21,21
22,22,1,0,21,21,21,0
LAYER 6
2,5,10,20,20,26,26,26
6,6,10,20,0,32,32,26
10,10,10,29,29,29,0,26
10,28,28,28,28,28,28,28
10,16,16,16,0,0,0,0
10,22,22,22,0,0,34,0
10,42,42,42,42,42,42,42
10,42,1,1,1,1,1,1
LAYER 7
2,5,8,8,8,8,8,0
6,5,18,20,0,32,8,0
14,18,18,20,0,32,8,26
14,18,20,20,0,32,8,8
14,18,20,16,0,32,0,8
14,18,20,44,0,32,34,8
12,18,20,44,0,32,34,8
10,42,20,44,0,32,34,1
LAYER 8
2,2,2,2,2,2,2,2
6,5,0,12,12,12,12,0
12,12,12,12,40,38,36,0
12,0,0,0,40,38,36,0
12,0,0,16,40,38,36,0
12,0,0,16,40,38,36,0
12,18,0,16,38,38,36,8
10,18,20,16,36,36,36,1
SIZE 72X72X8
LINE_NUM 14
LINE_NUM 22
LINE#1 (36,71,8) (36,71,2)
LINE#2 (37,71,5) (38,71,5)
......
This diff is collapsed.
# ADC2018
---
A cooperative system using multiple FPGAs for a simple 3D-Numberlink puzzle solver
## Environments
実際のソルバで使用している環境.
+ デバイス
- Raspberry Pi 3 B+
- PYNQ
- ZU3EG
+ ソフトウェア
- Python >= 3.5 (通信プログラム)
* Flask
* gevent
* gevent-websocket
- Vivado (Web Pack) >= 18.1 (FPGAの合成)
## Setups
[Wiki](https://www.togawa.cs.waseda.ac.jp/gitlab/adc2018/adc2018-system/wikis/home)も参照されたい.
各端末でこのリポジトリをCloneする.
```
cd ~
git clone https://www.togawa.cs.waseda.ac.jp/gitlab/adc2018/adc2018-system.git
```
## System
+ サーバ
- [通信用スクリプト](comm/server)
+ ソルバ
- [通信用スクリプト](comm/client)
- [高位合成用プログラム](hls)
+ リゾルバ
- [通信用スクリプト](comm/resolver)
## Our previous works
* [pynq-router](https://github.com/kotarot/pynq-router)
* [nl-solver](https://github.com/kotarot/nl-solver)
## License
This software is released under GPL v3 License, see [LICENSE](LICENSE).
# DAS2017 ADC RaspberryPi・PYNQ間HTTP通信プログラム
# DAS2018 ADC RaspberryPi, ソルバ, リゾルバ HTTP通信プログラム
# 概要
DAS2017アルゴリズムデザインコンテストに向けた,端末間通信プラグラム.
親となるRaspberry Piから,子となる複数のPYNQに対し問題を配信し,結果を受け取る.
DAS2018アルゴリズムデザインコンテストに向けた,端末間通信プラグラム.
親となるRaspberry Piから,子となる複数のソルバ,リゾルバに対し問題を配信し,結果を受け取る.
# 構成
+ server: Raspberry Pi上で実行するためのサーバプラグラム.問題をクライアントに配信し,結果を受け取る.
+ client: PYNQ上で実行するためのクライアントプログラム.問題をサーバから受け取り,問題を解いて回答をサーバに返す.
+ server: Raspberry Pi上で実行するためのサーバプラグラム.問題をソルバに配信し,結果を受け取る.
+ client: ソルバをFPGA上で実行するためのクライアントプログラム.問題をサーバから受け取り,問題を解いて解けたら結果をリゾルバに送り,解けなかったら結果をサーバに報告する.
+ resolver: ソルバから初期解を受け取り,リゾルバでより良い解に整形する.
+ README.md: このファイル.
# Requirements
......
DAS2017 ADC クライアントプログラム
DAS2018 ADC クライアントプログラム
===
DAS2017 アルゴリズムデザインコンテスト用クライアントプログラム
DAS2018 アルゴリズムデザインコンテスト用クライアントプログラム
## Description
問題データをサーバから受信し,結果をサーバへ返すプログラム.
問題データをサーバから受信し,結果をリゾルバやサーバへ送るプログラム.
## Requirements
......@@ -22,7 +22,7 @@ python3 main.py [--port XXXX] [--host XXXX]
<dl>
<dt>-H, --host</dt>
<dd>サーバホストのアドレス (デフォルト:192.168.4.1:5000)</dd>
<dd>サーバホストのアドレス (デフォルト:192.168.5.1:5000)</dd>
<dt>-p, --port</dt>
<dd>使用するポート (デフォルト:5000)</dd>
......
......@@ -22,7 +22,11 @@ python3 main.py [--question XXXX] [--port XXXX] [--clients XXXX]
<dl>
<dt>-c, --client</dt>
<dd>クライアントを定義したテキストファイル.1行ずつホスト名を記述する(必要ならばポート番号も記述する),必須</dd>
<dd>
クライアントを定義したテキストファイル.1行ずつアドレスと役割を記述する(必要ならばポート番号も記述する),必須.
ホスト名と対応するアイコン画像もオプションで指定できる.<br />
`アドレス 役割 [名前] [画像ファイルへのパス]`
</dd>
<dt>-q, --question</dt>
<dd>問題ファイルのパス (デフォルト:./)</dd>
......@@ -32,8 +36,14 @@ python3 main.py [--question XXXX] [--port XXXX] [--clients XXXX]
<dt>-p, --port</dt>
<dd>サーバのポート (デフォルト:5000)</dd>
<dt>-a, --adccli</dt>
<dd>
ADC自動運営システムへのログイン情報を記録したjsonファイルへのパス.
`{"url": XXX, "username": YYY, "password": ZZZ}`の形式で保存する.
</dd>
</dl>
## Comments
This project uses some libraries: jQuery, Bootstrap
This project uses some libraries: jQuery, Bootstrap, and three.js.
#include <stdio.h>
#include <stdlib.h>
#define STRLEN 65536
int main(void){
char q[STRLEN], command[STRLEN];
char dir[64] = "../lines256_length128";
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;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -17,6 +17,7 @@
#include "router.hpp"
#define PRINT_SOLUTION
int main(int argc, char *argv[]) {
using namespace std;
......@@ -50,9 +51,11 @@ int main(int argc, char *argv[]) {
seed = atoi(argv[2]);
}
#ifdef PRINT_SOLUTION
int size_x = (boardstr[1] - '0') * 10 + (boardstr[2] - '0');
int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0');
int size_z = (boardstr[7] - '0');
#endif
// ソルバ実行
ap_int<32> status;
......@@ -68,6 +71,7 @@ int main(int argc, char *argv[]) {
cout << "status = " << (int)status << endl;
cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl;
#ifdef PRINT_SOLUTION
// 解表示
cout << "SOLUTION" << endl;
cout << "========" << endl;
......@@ -80,12 +84,13 @@ int main(int argc, char *argv[]) {
cout << ",";
}
int i = ((x * MAX_WIDTH + y) << BITWIDTH_Z) | z;
//cout << setfill('0') << setw(2) << right << (unsigned int)(unsigned char)(boardstr[i]);
cout << (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 << endl;
}
}
#endif
return 0;
}
......@@ -244,6 +244,7 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *stat
ap_uint<8> last_target = 255;
// [Step 2] Rip-up 再ルーティング
cout << "Rip-up Routing" << endl;
ROUTING:
for (ap_uint<16> round = 1; round <= 32768 /* = (2048 * 16) */; round++) {
#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
#pragma HLS LOOP_TRIPCOUNT min=1 max=255 avg=50
weights[paths[target][j]] = 1;
}
// 対象ラインのスタートの重みも一旦リセット あとで (*) で戻す
weights[starts[target]] = 1;
// (2) 重みを更新
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
}
}
}
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
cout << "LINE #" << (int)(target + 1) << endl;
cout << "(round: " << round << ")" << "LINE #" << (int)(target + 1) << endl;
#endif
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
ap_uint<16> t = prev[goal];
#ifdef DEBUG_PRINT
int dbg_start_xy = start >> BITWIDTH_Z;
int dbg_start_x = dbg_start_xy / MAX_WIDTH;
int dbg_start_y = dbg_start_xy % MAX_WIDTH;
int dbg_start_z = start & BITMASK_Z;
int dbg_goal_xy = goal >> BITWIDTH_Z;
int dbg_goal_x = dbg_goal_xy / MAX_WIDTH;
int dbg_goal_y = dbg_goal_xy % MAX_WIDTH;
int dbg_goal_z = goal & BITMASK_Z;
cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> "
<< "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl;
//int dbg_start_xy = start >> BITWIDTH_Z;
//int dbg_start_x = dbg_start_xy / MAX_WIDTH;
//int dbg_start_y = dbg_start_xy % MAX_WIDTH;
//int dbg_start_z = start & BITMASK_Z;
//int dbg_goal_xy = goal >> BITWIDTH_Z;
//int dbg_goal_x = dbg_goal_xy / MAX_WIDTH;
//int dbg_goal_y = dbg_goal_xy % MAX_WIDTH;
//int dbg_goal_z = goal & BITMASK_Z;
//cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> "
// << "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl;
#endif
// バックトラック
......@@ -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
#ifdef DEBUG_PRINT
int t_xy = prev[t] >> BITWIDTH_Z;
int t_x = t_xy / MAX_WIDTH;
int t_y = t_xy % MAX_WIDTH;
int t_z = prev[t] & BITMASK_Z;
cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl;
//int t_xy = prev[t] >> BITWIDTH_Z;
//int t_x = t_xy / MAX_WIDTH;
//int t_y = t_xy % MAX_WIDTH;
//int t_z = prev[t] & BITMASK_Z;
//cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl;
#endif
path[p] = t; // 記録
......@@ -648,8 +655,8 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start
*path_size = p;
#ifdef DEBUG_PRINT
cout << "max_path_len = " << p << endl;
cout << "max_pq_len = " << max_pq_len << endl;
//cout << "max_path_len = " << p << endl;
//cout << "max_pq_len = " << max_pq_len << endl;
#endif
}
......@@ -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
(*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> p = (*pq_len) >> 1; // i.e., (*pq_len) / 2; // 親
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
ap_uint<16> last_priority = (ap_uint<16>)(pq_nodes[*pq_len] & PQ_PRIORITY_MASK); // 末尾ノードの優先度
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 PIPELINE
//#pragma HLS UNROLL factor=2
......
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -Wall -Wno-unknown-pragmas -Wno-unused-label -DSOFTWARE -DCALCTIME
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -O3 -Wl,--stack,16777216 -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
This diff is collapsed.
......@@ -17,6 +17,7 @@
#include "router.hpp"
#define PRINT_SOLUTION
int main(int argc, char *argv[]) {
using namespace std;
......@@ -50,9 +51,11 @@ int main(int argc, char *argv[]) {
seed = atoi(argv[2]);
}
#ifdef PRINT_SOLUTION
int size_x = (boardstr[1] - '0') * 10 + (boardstr[2] - '0');
int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0');
int size_z = (boardstr[7] - '0');
#endif
// ソルバ実行
ap_int<32> status;
......@@ -68,6 +71,7 @@ int main(int argc, char *argv[]) {
cout << "status = " << (int)status << endl;
cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl;
#ifdef PRINT_SOLUTION
// 解表示
cout << "SOLUTION" << endl;
cout << "========" << endl;
......@@ -80,12 +84,13 @@ int main(int argc, char *argv[]) {
cout << ",";
}
int i = ((x * MAX_WIDTH + y) << BITWIDTH_Z) | z;
//cout << setfill('0') << setw(2) << right << (unsigned int)(unsigned char)(boardstr[i]);
cout << (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 << endl;
}
}
#endif
return 0;
}
......@@ -210,7 +210,6 @@ bool pynqrouter_256x128(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<3
FIRST_ROUTING:
for (ap_uint<9> i = 0; i < (ap_uint<9>)(line_num); i++) {
#pragma HLS LOOP_TRIPCOUNT min=2 max=255 avg=50
//#pragma HLS LOOP_TRIPCOUNT min=2 max=127 avg=50
//#pragma HLS PIPELINE
//#pragma HLS UNROLL factor=2
......@@ -245,6 +244,7 @@ bool pynqrouter_256x128(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<3
ap_uint<8> last_target = 255;
// [Step 2] Rip-up 再ルーティング
cout << "Rip-up Routing" << endl;
ROUTING:
for (ap_uint<16> round = 1; round <= 32768 /* = (2048 * 16) */; round++) {
#pragma HLS LOOP_TRIPCOUNT min=1 max=4000 avg=50
......@@ -285,8 +285,6 @@ bool pynqrouter_256x128(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<3
#pragma HLS LOOP_TRIPCOUNT min=1 max=255 avg=50
weights[paths[target][j]] = 1;
}
// 対象ラインのスタートの重みも一旦リセット あとで (*) で戻す
weights[starts[target]] = 1;
// (2) 重みを更新
ap_uint<8> current_round_weight = new_weight(round);
......@@ -304,10 +302,18 @@ bool pynqrouter_256x128(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<3
}
}
}
WEIGHT_TERMINAL:
for (ap_uint<9> i = 0; i < (ap_uint<9>)(line_num); i++) {
#pragma HLS LOOP_TRIPCOUNT min=2 max=255 avg=50
weights[starts[i]] = MAX_WEIGHT;
weights[goals[i]] = MAX_WEIGHT;
}
// 対象ラインのスタートの重みも一旦リセット あとで (*) で戻す
weights[starts[target]] = 1;
// 経路探索
#ifdef DEBUG_PRINT
cout << "LINE #" << (int)(target + 1) << endl;
cout << "(round: " << round << ")" << "LINE #" << (int)(target + 1) << endl;
#endif
search(&(paths_size[target]), paths[target], starts[target], goals[target], weights);
......@@ -612,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];
#ifdef DEBUG_PRINT
int dbg_start_xy = start >> BITWIDTH_Z;
int dbg_start_x = dbg_start_xy / MAX_WIDTH;
int dbg_start_y = dbg_start_xy % MAX_WIDTH;
int dbg_start_z = start & BITMASK_Z;
int dbg_goal_xy = goal >> BITWIDTH_Z;
int dbg_goal_x = dbg_goal_xy / MAX_WIDTH;
int dbg_goal_y = dbg_goal_xy % MAX_WIDTH;
int dbg_goal_z = goal & BITMASK_Z;
cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> "
<< "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl;
//int dbg_start_xy = start >> BITWIDTH_Z;
//int dbg_start_x = dbg_start_xy / MAX_WIDTH;
//int dbg_start_y = dbg_start_xy % MAX_WIDTH;
//int dbg_start_z = start & BITMASK_Z;
//int dbg_goal_xy = goal >> BITWIDTH_Z;
//int dbg_goal_x = dbg_goal_xy / MAX_WIDTH;
//int dbg_goal_y = dbg_goal_xy % MAX_WIDTH;
//int dbg_goal_z = goal & BITMASK_Z;
//cout << "(" << dbg_start_x << ", " << dbg_start_y << ", " << dbg_start_z << ") #" << start << " -> "
// << "(" << dbg_goal_x << ", " << dbg_goal_y << ", " << dbg_goal_z << ") #" << goal << endl;
#endif
// バックトラック
......@@ -634,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
#ifdef DEBUG_PRINT
int t_xy = prev[t] >> BITWIDTH_Z;
int t_x = t_xy / MAX_WIDTH;
int t_y = t_xy % MAX_WIDTH;
int t_z = prev[t] & BITMASK_Z;
cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl;
//int t_xy = prev[t] >> BITWIDTH_Z;
//int t_x = t_xy / MAX_WIDTH;
//int t_y = t_xy % MAX_WIDTH;
//int t_z = prev[t] & BITMASK_Z;
//cout << " via " << "(" << t_x << ", " << t_y << ", " << t_z << ") #" << prev[t] << " dist=" << dist[t] << endl;
#endif
path[p] = t; // 記録
......@@ -649,8 +655,8 @@ void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start
*path_size = p;
#ifdef DEBUG_PRINT
cout << "max_path_len = " << p << endl;
cout << "max_pq_len = " << max_pq_len << endl;
//cout << "max_path_len = " << p << endl;
//cout << "max_pq_len = " << max_pq_len << endl;
#endif
}
......@@ -676,6 +682,7 @@ void pq_push(ap_uint<16> priority, ap_uint<16> data, ap_uint<13> *pq_len, ap_uin
#pragma HLS INLINE
(*pq_len)++;
if ((*pq_len) == 0) { (*pq_len)--; } // Queue is full -> Last element is automatically removed
ap_uint<13> i = (*pq_len); // target
ap_uint<13> p = (*pq_len) >> 1; // i.e., (*pq_len) / 2; // 親
PQ_PUSH_LOOP:
......@@ -708,7 +715,7 @@ void pq_pop(ap_uint<16> *ret_priority, ap_uint<16> *ret_data, ap_uint<13> *pq_le
ap_uint<16> last_priority = (ap_uint<16>)(pq_nodes[*pq_len] & PQ_PRIORITY_MASK); // 末尾ノードの優先度
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 PIPELINE
//#pragma HLS UNROLL factor=2
......
# pynq-router (sw)
PYNQ-router for Vivado-HLS (2018 ver.)
## Types of router
|Name|Operation name|Description|
|:---|:---|:---|
|01|TBD|*Line-number-free* router for "PYNQ-Z1". Priority queue is implemented with circular array(non-parallel)|
|02|TBD|*Line-number-free* router for "PYNQ-Z1". Priority queue is implemented with circular array(parallel)|
|03|TBD|*Line-number-free* router for "PYNQ-Z1". Priority queue is implemented with heap(size:$`2^{15}`$)|
|04|TBD|*Line-number-free* router for "AVNET-Ultra96". Priority queue is implemented with heap(size:$`2^{16}`$)|
|05|TBD|*Low-memory-usage* router. No BRAMs are used for storing route information of each line.|
## Memo
* Vivado HLS 2018.2
* Vivado 2018.2
Options:
* Part: xc7z020clg400-1 (PYNQ-Z1), xczu3eg-sbva484-1-e (AVNET-Ultra96)
* Clock Period: 10.0 ns
* Clock Uncertainty: 3.0 ns (--> 3.25 ns)
* Synthesis strategy: ~~Vivado Synthesis Defaults~~ Flow_PerfOptimized_high
* Implementation strategy: ~~Vivado Implementation Defaults~~ Performance_ExplorePostRoutePhysOpt
## I/O
* Input/Output: boardstr(8bit\*41472), seed(32bit), &status(32bit), return(1bit)
## Results
|Q|heap(seed:0)|c-array(seed:0)|OR|
|:---|:---|:---|:---|
|01|1|1|1|
|02|1|1|1|
|03|1|1|1|
|04|1|1|1|
|05|1|1|1|
|06|1|1|1|
|07|1|1|1|
|08|0|1|1|
|09|1|1|1|
|10|1|1|1|
|11|1|1|1|
|12|1|1|1|
|13|1|1|1|
|14|0|1|1|
|15|1|1|1|
|16|1|1|1|
|17|0|0|0|
|18|1|1|1|
|19|0|0|0|
|20|1|1|1|
|21|0|0|0|
|22|1|1|1|
|23|1|0|1|
|24|0|0|0|
|25|0|0|0|
|26|1|1|1|
|27|1|0|1|
|28|1|1|1|
|29|0|0|0|
|30|0|0|0|
|31|0|0|0|
|32|1|1|1|
|33|0|0|0|
|34|0|0|0|
|Total|22|22|24|
#include <stdio.h>
#include <stdlib.h>
#define STRLEN 65536
int main(void){
char q[STRLEN], command[STRLEN];
char dir[64] = "../router_02_boardstr";
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;
}
This diff is collapsed.
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -Wall -Wno-unknown-pragmas -Wno-unused-label -DSOFTWARE -DCALCTIME
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -O3 -o $@ $(OBJS)
run:
python3 ../NLGenerator.py -x 20 -y 20 -z 6 -l 100;\
python3 ./gen_boardstr.py Q-20x20x5_100_10.txt |\
./$(TARGET) -
clean:
rm *.o
rm $(TARGET)
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -Wall -Wno-unknown-pragmas -Wno-unused-label -DSOFTWARE -DCALCTIME
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -O3 -Wl,--stack,33554432 -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* main.cpp
*
* for Vivado HLS
*/
#ifdef SOFTWARE
#include "ap_int.h"
#else
#include <ap_int.h>
#endif
#ifdef CALCTIME
#include <stdio.h>
#include <time.h>
#endif
#include "router.hpp"
#define PRINT_SOLUTION
int main(int argc, char *argv[]) {
using namespace std;
// Test data //
// NL_Q00.txt
//char boardstr[BOARDSTR_SIZE] = "X10Y05Z3L0000107041L0004107002L0102102021L0900100003";
// NL_Q06.txt
char boardstr[BOARDSTR_SIZE] = "X10Y18Z2L0900109002L0901105012L0902103052L0903103062L0904100102L0905106012L0906109022L0717109102L0808109112L0017209172L0401200072L0912208152L0009201092L0709209092L0901206052L0309204092L0701209072L0101201022L0011202152L0016202162";
// NL_Q08.txt
//char boardstr[BOARDSTR_SIZE] = "X17Y20Z2L0000103022L1603115052L0916107032L0302108012L1104111042L1002100002L0919116162L1616113182L1001115012L0500201182L1603213152L0600210022";
// Read boardstr from command line
if (1 < argc) {
// From stdin
if(argv[1][0]!='X')
{
char* c_p=fgets(boardstr, BOARDSTR_SIZE, stdin);
int length=strlen(c_p);
boardstr[length-1]=0;
}
else
{
strcpy(boardstr, argv[1]);
}
}
// Seed value
int seed = 12345;
if (2 < argc) {
seed = atoi(argv[2]);
}
#ifdef PRINT_SOLUTION
int size_x = (boardstr[1] - '0') * 10 + (boardstr[2] - '0');
int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0');
int size_z = (boardstr[7] - '0');
#endif
// Solver
ap_int<32> status;
clock_t clock_start, clock_done;
clock_start = clock();
bool result = pynqrouter(boardstr, seed, &status);
clock_done = clock();
if (result) {
cout << endl << "Test Passed!" << endl;
} else {
cout << endl << "Test Failed!" << endl;
}
cout << "status = " << (int)status << endl;
cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl;
#ifdef PRINT_SOLUTION
cout << "SOLUTION" << endl;
cout << "========" << endl;
cout << "SIZE " << size_x << "X" << size_y << "X" << size_z << endl;
for (int z = 0; z < size_z; z++) {
cout << "LAYER " << (z + 1) << endl;
for (int y = 0; y < size_y; y++) {
for (int x = 0; x < size_x; x++) {
if (x != 0) {
cout << ",";
}
int i = ((x * MAX_WIDTH + y) << BITWIDTH_Z) | z;
cout << setfill('0') << setw(3) << right << (unsigned int)(unsigned char)(boardstr[i]);
//cout << (unsigned int)(unsigned char)(boardstr[i]);
}
cout << endl;
}
}
#endif
return 0;
}
This diff is collapsed.
/**
* router.hpp
*
* for Vivado HLS
*/
#ifndef __ROUTER_HPP__
#define __ROUTER_HPP__
#ifdef SOFTWARE
#include "ap_int.h"
#else
#include <ap_int.h>
#endif
//#define DEBUG_PRINT // for debug
#ifdef DEBUG_PRINT
using namespace std;
#endif
// Parameters
#define MAX_WIDTH 72 // Max of X, Y
#define BITWIDTH_XY 13
#define BITMASK_XY 65528 // 1111 1111 1111 1000
#define MAX_LAYER 8 // Max of Z
#define BITWIDTH_Z 3
#define BITMASK_Z 7 // 0000 0000 0000 0111
#define MAX_CELLS 41472 // Max #cells (16bit)
#define MAX_LINES 1024 // Max #lines (10bit)
#define MAX_PQ 8192 // Queue size (13bit)
#define MAX_BUFFER 16384 // Line buffer size (14bit)
#define CELL_BIT 16
#define LINE_BIT 10
#define PQ_BIT 13
#define BUFF_BIT 14
#define PQ_PRIORITY_WIDTH 16
#define PQ_PRIORITY_MASK 65535 // 0000 0000 0000 0000 1111 1111 1111 1111
#define PQ_DATA_WIDTH 16
#define PQ_DATA_MASK 4294901760 // 1111 1111 1111 1111 0000 0000 0000 0000
#define MAX_WEIGHT 255 // Max weight
#define BOARDSTR_SIZE 41472 // Size of I/O
ap_uint<8> new_weight(ap_uint<16> x);
bool pynqrouter(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *status);
ap_uint<7> abs_uint7(ap_uint<7> a, ap_uint<7> b);
ap_uint<3> abs_uint3(ap_uint<3> a, ap_uint<3> b);
ap_uint<BUFF_BIT> search(ap_uint<BUFF_BIT> idx, ap_uint<CELL_BIT> paths[MAX_BUFFER], ap_uint<CELL_BIT> start, ap_uint<CELL_BIT> goal, ap_uint<8> w[MAX_WEIGHT]);
void pq_push(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> priority, ap_uint<16> data, ap_uint<PQ_BIT> *top, ap_uint<PQ_BIT> *bottom, bool *is_empty);
void pq_pop(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> *ret_priority, ap_uint<16> *ret_data, ap_uint<PQ_BIT> *top, ap_uint<PQ_BIT> *bottom, bool *is_empty);
#endif /* __ROUTER_HPP__ */
This diff is collapsed.
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -Wall -Wno-unknown-pragmas -Wno-unused-label -DSOFTWARE -DCALCTIME
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -O3 -Wl,--stack,33554432 -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.