diff --git a/mem_test/mem_test.c b/mem_test/mem_test.c new file mode 100644 index 0000000..f325f9b --- /dev/null +++ b/mem_test/mem_test.c @@ -0,0 +1,21 @@ +#include +#define INPUT_LEN ((131072)) + +int mem_test(volatile unsigned int input[INPUT_LEN], int mem_done) +{ +#pragma HLS INTERFACE m_axi depth=4096 port=input offset=slave bundle=INPUT +#pragma HLS INTERFACE s_axilite register port=mem_done +#pragma HLS INTERFACE s_axilite register port=return + + unsigned int local_buf[INPUT_LEN]; + unsigned long long int result = 0; + + memcpy(local_buf, (const unsigned int*)input, INPUT_LEN*sizeof(unsigned int)); + mem_done = 1; + + for (int i = 0; i < INPUT_LEN; i++) +#pragma HLS pipeline + result += local_buf[i]; + return result; + +} diff --git a/set_intersection_hls/set_intersection.c b/set_intersection_hls/set_intersection.c new file mode 100644 index 0000000..694d60d --- /dev/null +++ b/set_intersection_hls/set_intersection.c @@ -0,0 +1,37 @@ +#include +#define INPUT_LEN 4096 + +int intersect(volatile unsigned int input_a[INPUT_LEN], volatile unsigned int input_b[INPUT_LEN], volatile unsigned int len_a, volatile unsigned int len_b) +{ +#pragma HLS INTERFACE m_axi depth=4096 port=input_a offset=slave bundle=INPUT_A +#pragma HLS INTERFACE m_axi depth=4096 port=input_b offset=slave bundle=INPUT_B +#pragma HLS INTERFACE s_axilite register port=len_a +#pragma HLS INTERFACE s_axilite register port=len_b +#pragma HLS INTERFACE s_axilite register port=return + + unsigned int local_a[INPUT_LEN]; + unsigned int local_b[INPUT_LEN]; + + memcpy(local_a, (const unsigned int*)input_a, len_a*sizeof(unsigned int)); + memcpy(local_b, (const unsigned int*)input_b, len_b*sizeof(unsigned int)); + + unsigned int count = 0; + unsigned int idx_a = 0; + unsigned int idx_b = 0; + + while (idx_a < len_a && idx_b < len_b) + { +#pragma HLS pipeline + if (local_a[idx_a] < local_b[idx_b]) + idx_a++; + else if (local_a[idx_a] > local_b[idx_b]) + idx_b++; + else + { + count++; + idx_a++; + idx_b++; + } + } + return count; +} diff --git a/set_intersection_hls/set_intersection_v0.1.c b/set_intersection_hls/set_intersection_v0.1.c new file mode 100644 index 0000000..24e771c --- /dev/null +++ b/set_intersection_hls/set_intersection_v0.1.c @@ -0,0 +1,35 @@ +#include +#define INPUT_LEN 4096 + +int intersect(volatile int input_a[INPUT_LEN], volatile int input_b[INPUT_LEN]) +{ +#pragma HLS INTERFACE m_axi depth=4096 port=input_a offset=slave bundle=INPUT_A +#pragma HLS INTERFACE m_axi depth=4096 port=input_b offset=slave bundle=INPUT_B +#pragma HLS INTERFACE s_axilite register port=return + + unsigned int local_a[INPUT_LEN]; + unsigned int local_b[INPUT_LEN]; + + memcpy(local_a, (const int*)input_a, INPUT_LEN*sizeof(int)); + memcpy(local_b, (const int*)input_b, INPUT_LEN*sizeof(int)); + + unsigned int count = 0; + unsigned int idx_a = 0; + unsigned int idx_b = 0; + + while (idx_a < INPUT_LEN && idx_b < INPUT_LEN) + { +#pragma HLS pipeline + if (local_a[idx_a] < local_b[idx_b]) + idx_a++; + else if (local_a[idx_a] > local_b[idx_b]) + idx_b++; + else + { + count++; + idx_a++; + idx_b++; + } + } + return count; +} diff --git a/triangle_counting_hls/triangle_counting.cc b/triangle_counting_hls/triangle_counting.cc new file mode 100644 index 0000000..a9ae7e5 --- /dev/null +++ b/triangle_counting_hls/triangle_counting.cc @@ -0,0 +1,81 @@ +#include +#include + +#define BUF_SIZE 4096 + +int cal_intersect(volatile unsigned int neighbor[9], + volatile unsigned int offset_a, + volatile unsigned int offset_b, + volatile unsigned int len_a, + volatile unsigned int len_b) +{ + unsigned int local_a[BUF_SIZE]; + unsigned int local_b[BUF_SIZE]; + + memcpy(local_a, (const unsigned int*)&(neighbor[offset_a]), len_a*sizeof(unsigned int)); + memcpy(local_b, (const unsigned int*)&(neighbor[offset_b]), len_b*sizeof(unsigned int)); + + unsigned int count = 0; + unsigned int idx_a = 0; + unsigned int idx_b = 0; + + while (idx_a < len_a && idx_b < len_b) + { +#pragma HLS pipeline + if (local_a[idx_a] < local_b[idx_b]) + idx_a++; + else if (local_a[idx_a] > local_b[idx_b]) + idx_b++; + else + { + count++; + idx_a++; + idx_b++; + } + } + return count; +} + + +int triangle_counting(volatile unsigned int neighbor[9], + volatile unsigned int offset[7], + volatile unsigned int edge[18], + unsigned int num_edges, + unsigned int progress[5]) +{ +#pragma HLS INTERFACE m_axi port=neighbor depth = 32 offset=slave bundle=NEIGHBOR +#pragma HLS INTERFACE m_axi port=offset depth = 32 offset=slave bundle=OFFSET +#pragma HLS INTERFACE m_axi port=edge depth = 32 offset=slave bundle=EDGE +#pragma HLS INTERFACE m_axi port=progress depth = 32 offset=slave bundle=PROGRESS +#pragma HLS INTERFACE s_axilite register port=num_edges +#pragma HLS INTERFACE s_axilite register port=return + + unsigned int count = 0; + unsigned int i = 0; + unsigned int node_a, node_b; + unsigned int offset_a, offset_b; + unsigned int len_a, len_b; + + for (i = 0; i < num_edges; i+=2) + { +#pragma HLS pipeline + progress[0] = i; + node_a = edge[i]; + node_b = edge[i+1]; + offset_a = offset[node_a]; + len_a = offset[node_a + 1] - offset_a; + + offset_b = offset[node_b]; + len_b = offset[node_b + 1] - offset_b; +// count += neighbor[offset_a] + neighbor[offset_b]; +// count += offset_a + offset_b + len_a + len_b; + printf("calling intersect: offset_a = %d, offset_b = %d, len_a = %d, len_b = %d\n", offset_a, offset_b, len_a, len_b); + progress[1] = offset_a; + progress[2] = offset_b; + progress[3] = len_a; + progress[4] = len_b; + + count += cal_intersect(neighbor, offset_a, offset_b, len_a, len_b); + } + return count; +} diff --git a/triangle_counting_hls/triangle_counting_tb.cc b/triangle_counting_hls/triangle_counting_tb.cc new file mode 100644 index 0000000..92a1efb --- /dev/null +++ b/triangle_counting_hls/triangle_counting_tb.cc @@ -0,0 +1,45 @@ +#include +#include +#include + +int triangle_counting(volatile unsigned int neighbor[9], + volatile unsigned int offset[7], + volatile unsigned int edge[18], + unsigned int num_edges, + unsigned int progress[5]); + +int main() +{ + std::ifstream fin("test_parsed.tsv", std::ifstream::in); + std::string len_neighbor, len_offset, len_edge; + fin >> len_neighbor; + fin >> len_offset; + fin >> len_edge; + + std::cout << len_neighbor << " " << len_offset << " " << len_edge; + return 0; + +/* + unsigned int *neighbor = new unsigned int[len_neighbor]; + unsigned int *offset = new unsigned int[len_offset]; + unsigned int *edge = new unsigned int[len_edge]; + + for (int i = 0; i < len_neighbor; i++) + fin >> neighbor[i]; + for (int i = 0; i < len_offset; i++) + fin >> offset[i]; + for (int i = 0; i < len_edge; i++) + fin >> edge[i]; + + fin.close(); +*/ + +/* unsigned int neighbor[] = {2, 4, 5, 3, 4, 5, 4, 5, 5}; + unsigned int offset[] = {0, 0, 3, 6, 8, 9, 9}; + unsigned int edge[] = {5, 4, 5, 3, 5, 2, 5, 1, 4, 3, 4, 2, 4, 1, 3, 2, 2, 1}; + */ +/* unsigned int progress[5]; + int result = triangle_counting(neighbor, offset, edge, len_edge, progress); + printf("result = %d", result); + return 0;*/ +} diff --git a/triangle_counting_ku3_hls/triangle_counting.cc b/triangle_counting_ku3_hls/triangle_counting.cc new file mode 100644 index 0000000..29c427b --- /dev/null +++ b/triangle_counting_ku3_hls/triangle_counting.cc @@ -0,0 +1,94 @@ +#include +#include + +inline +int cal_intersect(volatile unsigned int neighbor[524288], + volatile unsigned int offset_a, + volatile unsigned int offset_b, + volatile unsigned int len_a, + volatile unsigned int len_b) +{ +#pragma HLS INLINE + volatile unsigned int *local_a = &(neighbor[offset_a]); + volatile unsigned int *local_b = &(neighbor[offset_b]); + +/* memcpy(local_a, (const unsigned int*)&(neighbor[offset_a]), len_a*sizeof(unsigned int)); + memcpy(local_b, (const unsigned int*)&(neighbor[offset_b]), len_b*sizeof(unsigned int));*/ + + unsigned int count = 0; + unsigned int idx_a = 0; + unsigned int idx_b = 0; + + while (idx_a < len_a && idx_b < len_b) + { +#pragma HLS pipeline + if (local_a[idx_a] < local_b[idx_b]) + idx_a++; + else if (local_a[idx_a] > local_b[idx_b]) + idx_b++; + else + { + count++; + idx_a++; + idx_b++; + } + } + return count; +} + +int triangle_counting(volatile const unsigned int neighbor_list[524288], + volatile const unsigned int offset_list[131072], + volatile const unsigned int edge_list[1048576], + unsigned int num_edges) +{ +#pragma HLS INTERFACE ap_fifo port=neighbor_list depth=524288 offset=slave bundle=NEIGHBOR +#pragma HLS INTERFACE ap_fifo port=offset_list depth=131072 offset=slave bundle=OFFSET +#pragma HLS INTERFACE ap_fifo port=edge_list depth=1048576 offset=slave bundle=EDGE_LIST +/* +#pragma HLS INTERFACE m_axi port=neighbor_list depth=524288 offset=slave bundle=NEIGHBOR +#pragma HLS INTERFACE m_axi port=offset_list depth=131072 offset=slave bundle=OFFSET +#pragma HLS INTERFACE m_axi port=edge_list depth=1048576 offset=slave bundle=EDGE_LIST +*/ +#pragma HLS INTERFACE ap_none register port=num_edges +#pragma HLS INTERFACE ap_ctrl_hs register port=return + + unsigned int neighbor[524288]; + unsigned int offset[131072]; +// unsigned int edge[1048576]; +#pragma HLS ARRAY_PARTITION variable=neighbor dim=1 block factor=32 +#pragma HLS ARRAY_PARTITION variable=offset dim=1 block factor=32 + + unsigned int count = 0; + unsigned int i = 0; + unsigned int node_a, node_b; + unsigned int offset_a, offset_b; + unsigned int len_a, len_b; + +/* memcpy(neighbor, (const unsigned int*)&(neighbor_list[0]), 524288*sizeof(unsigned int)); + memcpy(offset, (const unsigned int*)&(offset_list[0]), 131072*sizeof(unsigned int));*/ +// memcpy(edge, (const unsigned int*)&(edge_list[0]), 1048576*sizeof(unsigned int)); + + for (i = 0; i < 524288; i++) +#pragma HLS pipeline + neighbor[i] = neighbor_list[i]; + + for (i = 0; i < 131072; i++) +#pragma HLS pipeline + offset[i] = offset_list[i]; + + + for (i = 0; i < num_edges; i+=2) + { +#pragma HLS unroll factor=32 + node_a = edge_list[i]; + node_b = edge_list[i+1]; + offset_a = offset[node_a]; + len_a = offset[node_a + 1] - offset_a; + + offset_b = offset[node_b]; + len_b = offset[node_b + 1] - offset_b; + + count += cal_intersect(neighbor, offset_a, offset_b, len_a, len_b); + } + return count; +}