Commit 0fe383bb authored by kazushi.kawamura's avatar kazushi.kawamura

Merge branch 'hls_2018'

Merge hls_2018 to master
parents 88f47819 f7c0353d
#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_01";
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__ */
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)
# 並列度の変更 (変更箇所)
優先度キューに要素を挿入する際,要素の移動を並列して実行できる
コードにいくつかの変更を加えることで並列度を変更可能
## router.hpp
以下の2箇所を変更する
* #define PP **32** <-- 並列度
* #define LOG_PP **5** <-- 並列度のlog2
## router.cpp
以下の5箇所を変更する
* (in search func.) #pragma HLS ARRAY_PARTITION variable=pq_nodes cyclic factor=**32** dim=1 <-- 並列度
* (in pq_push func.) #pragma HLS LOOP_TRIPCOUNT min=0 max=**31** <-- 並列度-1 (計3箇所)
* (in pq_push func.) #pragma HLS LOOP_TRIPCOUNT min=0 max=**255** <-- キューの最大要素数/並列度-1
This diff is collapsed.
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
#define PP 32 // Parameter for Parallel shifting in queue push
#define LOG_PP 5 // LOG_PP is log2(PP)
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__ */
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)
# 並列度の変更 (変更箇所)
優先度キューに要素を挿入する際,要素の移動を並列して実行できる
コードにいくつかの変更を加えることで並列度を変更可能
## router.hpp
以下の2箇所を変更する
* #define PP **32** <-- 並列度
* #define LOG_PP **5** <-- 並列度のlog2
## router.cpp
以下の5箇所を変更する
* (in search func.) #pragma HLS ARRAY_PARTITION variable=pq_nodes cyclic factor=**32** dim=1 <-- 並列度
* (in pq_push func.) #pragma HLS LOOP_TRIPCOUNT min=0 max=**31** <-- 並列度-1 (計3箇所)
* (in pq_push func.) #pragma HLS LOOP_TRIPCOUNT min=0 max=**255** <-- キューの最大要素数/並列度-1
This diff is collapsed.
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";
char boardstr_high[BOARDSTR_SIZE] = {};
// 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, boardstr_high, 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;
unsigned int num = (unsigned char)(boardstr[i]) + ((unsigned char)(boardstr_high[i]) << 8);
cout << setfill('0') << setw(3) << right << num;
//cout << num;
}
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
#define PP 32 // Parameter for Parallel shifting in queue push
#define LOG_PP 5 // LOG_PP is log2(PP)
ap_uint<8> new_weight(ap_uint<16> x);
bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[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<BUFF_BIT> *n_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.
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.
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