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

Upload files

parent 99f85c83
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.
...@@ -164,13 +164,15 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[BOARDSTR_SIZE], ...@@ -164,13 +164,15 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[BOARDSTR_SIZE],
cout << "Rip-up Routing ..." << endl; cout << "Rip-up Routing ..." << endl;
#endif #endif
ap_uint<LINE_BIT> target = line_num - 1, next_target;
ROUTING: ROUTING:
for (ap_uint<16> round = 0; round < 32768 /* = (2048 * 16) */; round++) { for (ap_uint<16> round = 0; round < 32768 /* = (2048 * 16) */; round++) {
#pragma HLS LOOP_TRIPCOUNT min=1 max=32768 #pragma HLS LOOP_TRIPCOUNT min=1 max=32768
// Target line // Target line
ap_uint<LINE_BIT> target = round % line_num; target = round % line_num;
ap_uint<LINE_BIT> next_target = target + 1; next_target = target + 1;
if (next_target == line_num) next_target = 0; if (next_target == line_num) next_target = 0;
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
...@@ -310,7 +312,7 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[BOARDSTR_SIZE], ...@@ -310,7 +312,7 @@ bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[BOARDSTR_SIZE],
else { else {
p2 = s_idx[i+1]; p2 = s_idx[i+1];
} }
if ((ap_uint<BUFF_BIT>)(p2 - p1) > 8192){ if (i == target) {
p2 = pointer; p2 = pointer;
} }
OUTPUT_LINE_PATH: OUTPUT_LINE_PATH:
...@@ -474,7 +476,7 @@ void pq_push(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> priority, ap_uint<16> dat ...@@ -474,7 +476,7 @@ void pq_push(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> priority, ap_uint<16> dat
ap_uint<PQ_BIT> p = (*pq_len) >> 1; // parent node ap_uint<PQ_BIT> p = (*pq_len) >> 1; // parent node
PQ_PUSH_LOOP: PQ_PUSH_LOOP:
while (i > 1 && (ap_uint<16>)(pq_nodes[p] & PQ_PRIORITY_MASK) >= priority) { while (i > 1 && (ap_uint<16>)(pq_nodes[p] & PQ_PRIORITY_MASK) >= priority) {
#pragma HLS LOOP_TRIPCOUNT min=0 max=15 #pragma HLS LOOP_TRIPCOUNT min=0 max=16
/** Set!: min=0 max=PQ_BIT **/ /** Set!: min=0 max=PQ_BIT **/
pq_nodes[i] = pq_nodes[p]; pq_nodes[i] = pq_nodes[p];
i = p; i = p;
...@@ -497,7 +499,7 @@ void pq_pop(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> *ret_priority, ap_uint<16> ...@@ -497,7 +499,7 @@ void pq_pop(ap_uint<32> pq_nodes[MAX_PQ], ap_uint<16> *ret_priority, ap_uint<16>
PQ_POP_LOOP: PQ_POP_LOOP:
while (!(i >> (PQ_BIT-1))) { // (2018.08.24) Loop condition fixed while (!(i >> (PQ_BIT-1))) { // (2018.08.24) Loop condition fixed
#pragma HLS LOOP_TRIPCOUNT min=1 max=15 #pragma HLS LOOP_TRIPCOUNT min=1 max=16
/** Set!: min=0 max=PQ_BIT **/ /** Set!: min=0 max=PQ_BIT **/
ap_uint<PQ_BIT> c1 = i << 1; // child node(left) ap_uint<PQ_BIT> c1 = i << 1; // child node(left)
ap_uint<PQ_BIT> c2 = c1 + 1; // child node(right) ap_uint<PQ_BIT> c2 = c1 + 1; // child node(right)
......
...@@ -28,13 +28,13 @@ using namespace std; ...@@ -28,13 +28,13 @@ using namespace std;
#define BITMASK_Z 7 // 0000 0000 0000 0111 #define BITMASK_Z 7 // 0000 0000 0000 0111
#define MAX_CELLS 41472 // Max #cells (16bit) #define MAX_CELLS 41472 // Max #cells (16bit)
#define MAX_LINES 1024 // Max #lines (10bit) #define MAX_LINES 2048 // Max #lines (11bit)
#define MAX_PQ 65536 // Queue size (16bit) #define MAX_PQ 65536 // Queue size (16bit)
#define MAX_BUFFER 16384 // Line buffer size (14bit) #define MAX_BUFFER 32768 // Line buffer size (15bit)
#define CELL_BIT 16 #define CELL_BIT 16
#define LINE_BIT 10 #define LINE_BIT 11
#define PQ_BIT 16 #define PQ_BIT 16
#define BUFF_BIT 14 #define BUFF_BIT 15
#define PQ_PRIORITY_WIDTH 16 #define PQ_PRIORITY_WIDTH 16
#define PQ_PRIORITY_MASK 65535 // 0000 0000 0000 0000 1111 1111 1111 1111 #define PQ_PRIORITY_MASK 65535 // 0000 0000 0000 0000 1111 1111 1111 1111
......
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.
/**
* 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(5) << right << num;
//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 32768 // Max #lines (15bit)
#define MAX_PQ 16384 // Queue size (14bit)
#define MAX_BUFFER 16384 // Line buffer size (14bit)
#define CELL_BIT 16
#define LINE_BIT 15
#define PQ_BIT 14
#define BUFF_BIT 14
#define BOARDSTR_SIZE 41472 // Size of I/O
// For random num generation
void lfsr_random_init(ap_uint<32> seed);
ap_uint<32> lfsr_random();
bool pynqrouter(char boardstr[BOARDSTR_SIZE], char boardstr_high[BOARDSTR_SIZE], ap_uint<32> seed, ap_int<32> *status);
bool inside_board(ap_uint<CELL_BIT> cell_id);
bool connectable(ap_int<LINE_BIT+1> board[MAX_CELLS], ap_uint<LINE_BIT> target, ap_uint<LINE_BIT> rip_up);
void remove_line(ap_int<LINE_BIT+1> board[MAX_CELLS], ap_uint<LINE_BIT> rip_up);
bool available(ap_uint<2> avail[MAX_CELLS], ap_uint<CELL_BIT> prev[MAX_CELLS], ap_uint<CELL_BIT> start_id, ap_uint<CELL_BIT> goal_id);
void qu_push(ap_uint<CELL_BIT> qu_nodes[MAX_PQ], ap_uint<CELL_BIT> id, ap_uint<PQ_BIT> *top, ap_uint<PQ_BIT> *bottom, bool *is_empty);
void qu_pop(ap_uint<CELL_BIT> qu_nodes[MAX_PQ], ap_uint<CELL_BIT> *id, ap_uint<PQ_BIT> *top, ap_uint<PQ_BIT> *bottom, bool *is_empty);
#endif /* __ROUTER_HPP__ */
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