Commit 940a7e2c authored by kazushi.kawamura's avatar kazushi.kawamura

upload hardware design

parent 0d5842fb
This source diff could not be displayed because it is too large. You can view the blob instead.
set_property PACKAGE_PIN R14 [get_ports {led[0]}]
set_property PACKAGE_PIN P14 [get_ports {led[1]}]
set_property PACKAGE_PIN N16 [get_ports {led[2]}]
set_property PACKAGE_PIN M14 [get_ports {led[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {led[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {led[2]}]
set_property IOSTANDARD LVCMOS33 [get_ports {led[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {led[0]}]
This diff is collapsed.
#ifndef __PARAM_HPP__
#define __PARAM_HPP__
#define MAX_BLOCKS 128
#define MAX_LINES 256
#define MAX_PATH 128
#define MAX_CELLS 16384 // 128x128
#define MAX_SIZE 128
#define MAX_SIZE_BIT 7
#define SLOT_MAX_SIZE 64
#define ROUND_LIMIT 4096 //32768 // Max=65534(=2^16-2)
//#define PRINT_BOARD
//#define PRINT_SEARCH // for router debug
#define PQ_BIT 12
#define MAX_PQ 4096
#define PRIO_BIT 16
#define DATA_BIT 16
#define ELEM_BIT 32 // ELEM_BIT = PRIO_BIT + DATA_BIT
#define DATA_MASK 65535 // 0000 FFFF
#define DATA_MAX 65535 // FFFF
#define PRIO_MAX 65535 // FFFF
#define LE 1
#define TO 2
#define RI 3
#define BO 4
#define SA_O 1000
#define SA_I 100000
#define TEMP_S 500
#define TEMP_E 0.1
#define INTER_BLOCK_MARGIN 2
#define LOOP 50
#define TRY_LIMIT 500
#define NO_MOVE 10
#define LFSR_RAND_MAX 4294967295
#endif /* __PARAM_HPP__ */
This diff is collapsed.
#ifndef __SOLVER_HPP__
#define __SOLVER_HPP__
//#define DEBUG_PRINT
#include <iostream>
#include "param.hpp"
#include <ap_int.h>
#include <hls_stream.h>
#ifdef DEBUG_PRINT
#include "tools.hpp"
#endif
using namespace std;
bool solver(hls::stream<ap_uint<4> >& state, unsigned int seed[3], short int *pbnum, short int *plnum, short int block_info[MAX_BLOCKS+1][5][3], short int *pwi, short int *phi, short int block_place_global[MAX_BLOCKS+1][2], short int opt_result[MAX_CELLS]);
bool local_placement_1(short int line_num, short int blocks, short int *pwi, short int *phi, short int block_info[MAX_BLOCKS+1][5][3], short int block_place_global[MAX_BLOCKS+1][2], short int opt_result[MAX_CELLS]);
bool local_placement_2(short int line_num, short int blocks, short int *pwi, short int *phi, short int block_info[MAX_BLOCKS+1][5][3], short int opt_result[MAX_CELLS]);
int router(short int size_x, short int size_y, short int line_num, short int board_str[MAX_CELLS]);
int search(short int size_x, short int size_y, short int *path_size, unsigned short int path[MAX_PATH], unsigned short int start, unsigned short int goal, unsigned short int w[MAX_CELLS]);
void enqueue(unsigned int pq_nodes[MAX_PQ], unsigned short int queue_priority, unsigned short int queue_data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
void dequeue(unsigned int pq_nodes[MAX_PQ], unsigned short int *ret_priority, unsigned short int *ret_data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
#endif /* __SOLVER_HPP__ */
This diff is collapsed.
#ifndef __IO_HPP__
#define __IO_HPP__
#include <iostream>
#include <sstream> // for istringstream
#include <algorithm> // for replace
#include <math.h>
#include "param.hpp"
using namespace std;
void read_problem(short int *W, short int *H, short int *blocks, short int *line_num, short int block_info[][5][3], short int line_info[][2][5]);
void extract_line_info(short int line_num, short int blocks, short int block_info[][5][3], short int line_info[][2][5]);
float calcPlaceCost(short int line_num, short int line_info[MAX_LINES+1][2][5], pair<short int,short int> block_place_global[MAX_BLOCKS+1]);
void global_placement(unsigned int seed[3], short int W, short int H, short int line_num, short int blocks, short int block_info[MAX_BLOCKS+1][5][3], short int line_info[MAX_LINES+1][2][5], short int block_place_global[MAX_BLOCKS+1][2]);
#endif /* __IO_HPP__ */
#include <iostream>
#include <getopt.h>
#include "param.hpp"
#include "io.hpp"
#include "solver.hpp"
#include "tools.hpp"
using namespace std;
void usage() {
cout << "Usage: ./sim.exe [--output output-file] [--seed seed-value] < input-file" << endl;
exit(-1);
}
int main(int argc, char *argv[]) {
char *out_filename = NULL;
uint32_t seed_v = 214;
// Get options
struct option longopts[] = {
{"output", required_argument, NULL, 'o'},
{"seed", required_argument, NULL, 's'},
{0, 0, 0, 0}
};
int opt, optidx;
while((opt = getopt_long(argc, argv, "o:s:", longopts, &optidx)) != -1) {
switch(opt) {
case 'o':
out_filename = optarg;
break;
case 's':
sscanf(optarg, "%u", &seed_v);
break;
default:
usage();
}
}
// Init seed value
uint32_t seed[3];
srand(seed_v);
seed[0] = rand();
seed[1] = rand();
seed[2] = rand();
// W: Max width of a board (specified in a problem file)
// H: Max height of a board (specified in a problem file)
// blocks: # of blocks (specified in a problem file)
short int W, H, blocks, line_num;
// W_ext: Width of a current solution
// H_ext: Height of a current solution
short int W_ext, H_ext;
// block data
short int block_info[MAX_BLOCKS+1][5][3];
// line data
short int line_info[MAX_LINES+1][2][5];
// block positions on slot matrix
short int block_place_global[MAX_BLOCKS+1][2];
// An opt. result will be stored in the array
short int opt_result[MAX_CELLS];
// Check problem
read_problem(&W, &H, &blocks, &line_num, block_info, line_info);
extract_line_info(line_num, blocks, block_info, line_info);
// Solver body
global_placement(seed, W, H, line_num, blocks, block_info, line_info, block_place_global);
hls::stream<ap_uint<4> > state;
bool solved = solver(state, seed, &blocks, &line_num, block_info, &W_ext, &H_ext, block_place_global, opt_result);
// Check answer
if(!solved) {
cout << "Fail re-routing" << endl;
}
else {
cout << "== Answer ==" << endl;
cout << "SIZE " << W_ext << "X" << H_ext << endl;
show_result(line_num, blocks, W_ext, H_ext, opt_result);
}
if(W_ext > W || H_ext > H) {
cout << "Fail satisfying constraint T_T" << endl;
}
else {
cout << "Satisfy constraint ^_^" << endl;
if(out_filename == NULL) return 0;
cout << "Output to " << out_filename << endl;
short int block_place_basis[MAX_BLOCKS+1][2];
for(int i = 1; i <= blocks; i++) {
block_place_basis[i][0] = block_info[i][0][0];
block_place_basis[i][1] = block_info[i][0][1];
}
output_to_file(out_filename, line_num, blocks, W_ext, H_ext, opt_result, block_place_basis);
}
return 0;
}
SIZE 10X10
BLOCK_NUM 8
BLOCK#1 1X4
1
+
8
7
BLOCK#2 3X2
0,8,0
7,6,+
BLOCK#3 2X3
10,0
+,0
3,9
BLOCK#4 2X2
1,2
4,+
BLOCK#5 3X2
11,+,+
0,0,3
BLOCK#6 3X2
0, +,2
5,11,0
BLOCK#7 3X2
0,10,6
9, 5,0
BLOCK#8 3X2
+,+,0
0,+,4
\ No newline at end of file
#include "tools.hpp"
void output_to_file(char *f_name, short int line_num, short int blocks, short int wi, short int hi, short int board[], short int block_place[][2]) {
ofstream outputfile(f_name);
outputfile << "SIZE " << wi << "X" << hi << endl;
for(short int q = 0; q < hi; q++) {
for(short int p = 0; p < wi; p++) {
short int n = board[q*MAX_SIZE+p];
if(n == 0) { outputfile << 0; }
else if(n == -1) { outputfile << 0; }
else{ outputfile << n; }
if(p != wi-1) { outputfile << ", "; }
}
outputfile << endl;
}
outputfile << setfill(' ');
outputfile << dec;
for(int i = 1; i <= blocks; i++) {
outputfile << "BLOCK#" << i << " @(" << block_place[i][0] << "," << block_place[i][1] << ")" << endl;
}
outputfile.close();
}
void show_result(short int line_num, short int blocks, short int wi, short int hi, short int board[]) {
// This shows a number from 1 to 255
for(short int q = 0; q < hi; q++) {
for(short int p = 0; p < wi; p++) {
short int n = board[q*MAX_SIZE+p];
if(n == 0) { cout << "--"; }
else if(n == -1) { cout << "XX"; }
else{ cout << setfill('0') << setw(2) << hex << n; }
if(p != wi-1) { cout << " "; }
}
cout << endl;
}
cout << setfill(' ');
cout << dec;
}
#ifndef __TOOLS_HPP__
#define __TOOLS_HPP__
using namespace std;
#include <iostream>
#include <iomanip> // for setw
#include <fstream>
#include "param.hpp"
void usage();
void output_to_file(char *f_name, short int line_num, short int blocks, short int wi, short int hi, short int board[], short int block_place[][2]);
void show_result(short int line_num, short int blocks, short int wi, short int hi, short int board[]);
#endif /* __TOOLS_HPP__ */
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