Commit f2bdebe1 authored by Kento HASEGAWA's avatar Kento HASEGAWA

Merge branch 'hls' into 'master'

Add a solver (maximum 256 lines and 128 length version)

See merge request adc2018/adc2018-system!2
parents 106f9d68 d0759cb2
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)
# pynq-router (sw)
Vivado HLS 用 pynq-router
## メモ
* Vivado HLS 2016.1
* Vivado 2016.1
高位合成オプション:
* Part: xc7z020clg400-1
* Clock Period: 10.0 ns
* Clock Uncertainty: 3.0 ns, 3.5 ns // 2017/08/04
論理合成・配置配線のオプション:
* Synthesis strategy: ~~Vivado Synthesis Defaults~~ Flow_PerfOptimized_high
* Implementation strategy: ~~Vivado Implementation Defaults~~ Performance_Explore
最適化記録:
* 2017/08/04: クリティカルパス遅延の最適化
* (3.0) Estimated clock: 6.78, Max latency: 1,667,151,745 (1.00)
* (3.5) Estimated clock: 6.38, Max latency: 1,692,438,002 (1.00)
* 2017/08/05: キューpop処理の動作改善
* (3.0) Estimated clock: 6.78, Max latency: 1,530,952,491 (0.92)
* (3.5) Estimated clock: 6.38, Max latency: 1,556,238,748 (0.92)
* 2017/08/07: 剰余演算の書き換え,隣接ノードの探索ループ展開
* (3.0) Estimated clock: 6.78, Max latency: 1,423,592,713 (0.85)
* (3.5) Estimated clock: 6.38, Max latency: 1,428,235,716 (0.84)
* 2017/08/07: 高位合成パラメータの調整
* (3.0) Estimated clock: 6.78, Max latency: 1,284,364,290 (0.77)
* (3.5) Estimated clock: 6.38, Max latency: 1,289,003,291 (0.76)
* 2017/08/11: 隣接ノードの探索ループ展開を戻した (そうしないと論理合成・配置配線でタイミング満たさない)
* (3.0) Estimated clock: 6.78, Max latency: 1,329,761,290 (0.80)
* (3.5) Estimated clock: 6.38, Max latency: 1,355,035,291 (0.80)
* 2017/08/11: starts と goals を FF パーティションした
* (3.0) Estimated clock: 6.78, Max latency: 1,329,245,034 (0.797)
* (3.5) Estimated clock: 6.45, Max latency: 1,354,519,035 (0.800)
* 2017/08/16: MAX_LINES を 256 に増やした
* (3.0) Estimated clock: 6.78, Max latency: 1,905,588,970 (1.143)
* (3.5) Estimated clock: 6.38, Max latency: 1,933,166,972 (1.142)
* 2017/08/16: MAX_LINES を 128 に戻した (そうしないと論理合成・配置配線でタイミング満たさない)
* (3.0) Estimated clock: 6.78, Max latency: 1,329,245,034 (0.797)
* (3.5) Estimated clock: 6.45, Max latency: 1,354,519,035 (0.800)
* 2017/08/16: コスト関数の波形をのこぎり型にした
* (3.0) Estimated clock: 6.78, Max latency: 1,329,245,034 (13.29 sec) (0.797)
* (3.25) Estimated clock: 6.52, Max latency: 1,329,249,035 (13.29 sec)
* (3.5) Estimated clock: 6.45, Max latency: 1,354,519,035 (13.55 sec) (0.800)
* 2017/08/18: 対象ライン選択に剰余演算を用いない方法を試してみた ※あまり変わらないからこれはやらずに元に戻す
* (3.0) Estimated clock: 6.52, Max latency: 1,329,101,007 (13.29 sec) (0.797)
* (3.5) Estimated clock: 6.45, Max latency: 1,354,371,007 (13.54 sec) (0.800)
* 2017/08/18: 対象ラインが連続して同じだったらルーティングスキップする
* (3.0) Estimated clock: 6.78, Max latency: 1,329,245,034 (13.29 sec)
* (3.25) Estimated clock: 6.52, Max latency: 1,329,249,035 (13.29 sec) **←今これ**
* (3.5) Estimated clock: 6.45, Max latency: 1,354,519,035 (13.55 sec)
## 入出力
入力は boardstr という問題ファイルをコンパクトに記述したようなワンラインの文字列。
出力は char 型の配列で、各要素に解答ファイルに相当する数値が入っている。
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"
int main(int argc, char *argv[]) {
using namespace std;
// テストデータ (文字列形式)
// NL_Q00.txt
//char boardstr[BOARDSTR_SIZE] = "X10Y05Z3L0000107041L0004107002L0102102021L0900100003";
// NL_Q06.txt
char boardstr[BOARDSTR_SIZE] = "X10Y18Z2L0900109002L0901105012L0902103052L0903103062L0904100102L0905106012L0906109022L0717109102L0808109112L0017209172L0401200072L0912208152L0009201092L0709209092L0901206052L0309204092L0701209072L0101201022L0011202152L0016202162";
// NL_Q08.txt
//char boardstr[BOARDSTR_SIZE] = "X17Y20Z2L0000103022L1603115052L0916107032L0302108012L1104111042L1002100002L0919116162L1616113182L1001115012L0500201182L1603213152L0600210022";
// 指定されてればコマンドラインから問題文字列を読み込む
if (1 < argc) {
//先頭がXではないならば標準入力から読み込む
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]);
}
}
// 指定されてればシード値を読み込む
int seed = 12345;
if (2 < argc) {
seed = atoi(argv[2]);
}
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');
// ソルバ実行
ap_int<32> status;
clock_t clock_start, clock_done;
clock_start = clock();
bool result = pynqrouter_zu3eg_test(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;
// 解表示
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(2) << right << (unsigned int)(unsigned char)(boardstr[i]);
cout << (unsigned int)(unsigned char)(boardstr[i]);
}
cout << endl;
}
}
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 // いろいろ表示する
#define USE_ASTAR // A* 探索を使う
#define USE_MOD_CALC // ターゲットラインの選択に剰余演算を用いる
using namespace std;
// 各種設定値
#define MAX_WIDTH 72 // X, Y の最大値 (7ビットで収まる)
#define BITWIDTH_XY 13
#define BITMASK_XY 65528 // 1111 1111 1111 1000
#define MAX_LAYER 8 // Z の最大値 (3ビット)
#define BITWIDTH_Z 3
#define BITMASK_Z 7 // 0000 0000 0000 0111
#define MAX_CELLS 41472 // セルの総数 =72*72*8 (16ビットで収まる)
#define MAX_LINES 1024 // ライン数の最大値 (7ビット)
#define MAX_PATH 256 // 1つのラインが対応するセル数の最大値 (8ビット)
#define MAX_PQ 4096 // 探索時のプライオリティ・キューの最大サイズ (12ビット) 足りないかも?
#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 // 重みの最大値 (8ビットで収まる)
#define BOARDSTR_SIZE 41472 // ボードストリングの最大文字数 (セル数 72*72*8 あれば良い)
void lfsr_random_init(ap_uint<32> seed);
ap_uint<32> lfsr_random();
//ap_uint<32> lfsr_random_uint32(ap_uint<32> a, ap_uint<32> b);
//ap_uint<32> lfsr_random_uint32_0(ap_uint<32> b);
ap_uint<8> new_weight(ap_uint<16> x);
bool pynqrouter_zu3eg_test(char boardstr[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *status);
#ifdef USE_ASTAR
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);
#endif
void search(ap_uint<8> *path_size, ap_uint<16> path[MAX_PATH], ap_uint<16> start, ap_uint<16> goal, ap_uint<8> w[MAX_WEIGHT]);
void pq_push(ap_uint<16> priority, ap_uint<16> data, ap_uint<12> *pq_len, ap_uint<32> pq_nodes[MAX_PQ]);
void pq_pop(ap_uint<16> *ret_priority, ap_uint<16> *ret_data, ap_uint<12> *pq_len, ap_uint<32> pq_nodes[MAX_PQ]);
#endif /* __ROUTER_HPP__ */
......@@ -21,7 +21,7 @@
int main(int argc, char *argv[]) {
using namespace std;
// テストデータ (文字列形式)
// テストデータ (文字列形式)
// NL_Q00.txt
//char boardstr[BOARDSTR_SIZE] = "X10Y05Z3L0000107041L0004107002L0102102021L0900100003";
// NL_Q06.txt
......@@ -29,9 +29,9 @@ int main(int argc, char *argv[]) {
// NL_Q08.txt
//char boardstr[BOARDSTR_SIZE] = "X17Y20Z2L0000103022L1603115052L0916107032L0302108012L1104111042L1002100002L0919116162L1616113182L1001115012L0500201182L1603213152L0600210022";
// 指定されてればコマンドラインから問題文字列を読み込む
// 指定されてればコマンドラインから問題文字列を読み込む
if (1 < argc) {
//先頭がXではないならば標準入力から読み込む
//先頭がXではないならば標準入力から読み込む
if(argv[1][0]!='X')
{
char* c_p=fgets(boardstr, BOARDSTR_SIZE, stdin);
......@@ -44,7 +44,7 @@ int main(int argc, char *argv[]) {
}
}
// 指定されてればシード値を読み込む
// 指定されてればシード値を読み込む
int seed = 12345;
if (2 < argc) {
seed = atoi(argv[2]);
......@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
int size_y = (boardstr[4] - '0') * 10 + (boardstr[5] - '0');
int size_z = (boardstr[7] - '0');
// ソルバ実行
// ソルバ実行
ap_int<32> status;
clock_t clock_start, clock_done;
clock_start = clock();
......@@ -68,7 +68,7 @@ int main(int argc, char *argv[]) {
cout << "status = " << (int)status << endl;
cout << "elapsed = " << ((double)(clock_done - clock_start) / CLOCKS_PER_SEC) << endl << endl;
// 解表示
// 解表示
cout << "SOLUTION" << endl;
cout << "========" << endl;
cout << "SIZE " << size_x << "X" << size_y << "X" << size_z << endl;
......
This diff is collapsed.
......@@ -13,33 +13,33 @@
#include <ap_int.h>
#endif
//#define DEBUG_PRINT // いろいろ表示する
#define USE_ASTAR // A* 探索を使う
#define USE_MOD_CALC // ターゲットラインの選択に剰余演算を用いる
//#define DEBUG_PRINT // いろいろ表示する
#define USE_ASTAR // A* 探索を使う
#define USE_MOD_CALC // ターゲットラインの選択に剰余演算を用いる
using namespace std;
// 各種設定値
#define MAX_WIDTH 72 // X, Y の最大値 (7ビットで収まる)
// 各種設定値
#define MAX_WIDTH 72 // X, Y の最大値 (7ビットで収まる)
#define BITWIDTH_XY 13
#define BITMASK_XY 65528 // 1111 1111 1111 1000
#define MAX_LAYER 8 // Z の最大値 (3ビット)
#define MAX_LAYER 8 // Z の最大値 (3ビット)
#define BITWIDTH_Z 3
#define BITMASK_Z 7 // 0000 0000 0000 0111
#define MAX_CELLS 41472 // セルの総数 =72*72*8 (16ビットで収まる)
#define MAX_LINES 128 // ライン数の最大値 (7ビット)
#define MAX_PATH 256 // 1つのラインが対応するセル数の最大値 (8ビット)
#define MAX_PQ 4096 // 探索時のプライオリティ・キューの最大サイズ (12ビット) 足りないかも?
#define MAX_CELLS 41472 // セルの総数 =72*72*8 (16ビットで収まる)
#define MAX_LINES 128 // ライン数の最大値 (7ビット)
#define MAX_PATH 256 // 1つのラインが対応するセル数の最大値 (8ビット)
#define MAX_PQ 4096 // 探索時のプライオリティ・キューの最大サイズ (12ビット) 足りないかも?
#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 // 重みの最大値 (8ビットで収まる)
#define BOARDSTR_SIZE 41472 // ボードストリングの最大文字数 (セル数 72*72*8 あれば良い)
#define MAX_WEIGHT 255 // 重みの最大値 (8ビットで収まる)
#define BOARDSTR_SIZE 41472 // ボードストリングの最大文字数 (セル数 72*72*8 あれば良い)
void lfsr_random_init(ap_uint<32> seed);
......
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)
# pynq-router (sw)
Vivado HLS 用 pynq-router
+ LINE数
- 128
+ 長さ/Line
- 256
## メモ
* Vivado HLS 2016.1
* Vivado 2016.1
高位合成オプション:
* Part: xc7z020clg400-1
* Clock Period: 10.0 ns
* Clock Uncertainty: 3.0 ns, 3.5 ns // 2017/08/04
論理合成・配置配線のオプション:
* Synthesis strategy: ~~Vivado Synthesis Defaults~~ Flow_PerfOptimized_high
* Implementation strategy: ~~Vivado Implementation Defaults~~ Performance_Explore
最適化記録:
## 入出力
入力は boardstr という問題ファイルをコンパクトに記述したようなワンラインの文字列。
出力は char 型の配列で、各要素に解答ファイルに相当する数値が入っている。
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.
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