From d286795ac5d5a9df23cbce8df5feff30b44833ad Mon Sep 17 00:00:00 2001 From: Sitao Huang Date: Wed, 13 Jun 2018 16:40:57 -0500 Subject: [PATCH] moving Python host code to a folder --- triangle_counting_host/graph_parser.py | 37 ---- triangle_counting_host/intersect_host.py | 52 ------ triangle_counting_host/tc_host.py | 101 ----------- triangle_counting_host/tc_host_opt_4.py | 162 ----------------- triangle_counting_host/tc_host_opt_7.py | 210 ----------------------- 5 files changed, 562 deletions(-) delete mode 100644 triangle_counting_host/graph_parser.py delete mode 100644 triangle_counting_host/intersect_host.py delete mode 100644 triangle_counting_host/tc_host.py delete mode 100644 triangle_counting_host/tc_host_opt_4.py delete mode 100644 triangle_counting_host/tc_host_opt_7.py diff --git a/triangle_counting_host/graph_parser.py b/triangle_counting_host/graph_parser.py deleted file mode 100644 index 5a42a09..0000000 --- a/triangle_counting_host/graph_parser.py +++ /dev/null @@ -1,37 +0,0 @@ - -neighbor_list = [] -offset_list = [0] -edge_list = [] - -graph_file = open("graph/test.tsv") -lines = graph_file.readlines() - -degree_count = 0 -prev_node = 0 - -for line in lines: - node_a, node_b, _ = map(int, line.split()) - if prev_node != node_b: - offset_list.append(degree_count) - - prev_node = node_b - if node_a < node_b: - edge_list.extend([node_b, node_a]) - else: - neighbor_list.append(node_a) - degree_count += 1 - -offset_list.append(degree_count) - -graph_file.close() - -print("neighbor_list size = ", len(neighbor_list)) -print("offset_list size = ", len(offset_list)) -print("edge_list size = ", len(edge_list)) - -f = open("test_parsed.tsv", "w") -f.write("%d %d %d\n" % (len(neighbor_list), len(offset_list), len(edge_list))) -f.write(" ".join(str(e) for e in neighbor_list) + "\n") -f.write(" ".join(str(e) for e in offset_list) + "\n") -f.write(" ".join(str(e) for e in edge_list) + "\n") -f.close() diff --git a/triangle_counting_host/intersect_host.py b/triangle_counting_host/intersect_host.py deleted file mode 100644 index b9afa3a..0000000 --- a/triangle_counting_host/intersect_host.py +++ /dev/null @@ -1,52 +0,0 @@ -# coding: utf-8 - -import sys -import numpy as np -import os -import time -from datetime import datetime -from pynq import Xlnk -from pynq import Overlay - -# load our design overlay -overlay = Overlay('intersect_hw.bit') -print("intersect_hw.bit loaded") - -myIP = overlay.intersect_0 - -xlnk = Xlnk() - -t1 = time.time() - -input_a = xlnk.cma_array(shape=(4096,), dtype=np.int32) -input_b = xlnk.cma_array(shape=(4096,), dtype=np.int32) - -for i in range(4096): - input_a[i] = i - input_b[i] = i + 1 - -myIP.write(0x18, input_a.physical_address) -myIP.write(0x20, input_b.physical_address) - -myIP.write(0x28, 2) -myIP.write(0x30, 2) - - -t2 = time.time() -t = t2 - t1 -print("Preparing input data time: ", str(t)) - -isready = 0; -myIP.write(0x00, 1) - -while( isready != 6 ): - isready = myIP.read(0x00) - -t3 = time.time() -t = t3 - t2 -#tbatch = tbatch + t -#print("Computation finished") -print("PL Time: ", str(t)) - -print("Return value: ", myIP.read(0x10)) - diff --git a/triangle_counting_host/tc_host.py b/triangle_counting_host/tc_host.py deleted file mode 100644 index 046f90d..0000000 --- a/triangle_counting_host/tc_host.py +++ /dev/null @@ -1,101 +0,0 @@ -# coding: utf-8 - -import sys -import numpy as np -import os -import time -from datetime import datetime -from pynq import Xlnk -from pynq import Overlay - -# load our design overlay -overlay = Overlay('triangle_counting.bit') -print("triangle_counting.bit loaded") - -myIP = overlay.triangle_counting_0 - -t0 = time.time() - -neighbor_list = [] -offset_list = [0] -edge_list = [] - -graph_file = open("graph/soc-Epinions1_adj.tsv") -# graph_file = open("graph/test.tsv") -lines = graph_file.readlines() - -degree_count = 0 -prev_node = 0 - -for line in lines: - node_a, node_b, _ = map(int, line.split()) - if prev_node != node_b: - offset_list.append(degree_count) - - prev_node = node_b - if node_a < node_b: - edge_list.extend([node_b, node_a]) - else: - neighbor_list.append(node_a) - degree_count += 1 - -offset_list.append(degree_count) - -print("neighbor_list size= ", len(neighbor_list)) -print("offset_list size= ", len(offset_list)) -print("edge_list size= ", len(edge_list)) - -t1 = time.time() - -print("Finished reading graph file. ") -t = t1 - t0 -print("Reading input file time: ", str(t)) - -xlnk = Xlnk() - -neighbor = xlnk.cma_array(shape=(len(neighbor_list),), dtype=np.int32) -offset = xlnk.cma_array(shape=(len(offset_list),), dtype=np.int32) -edge = xlnk.cma_array(shape=(len(edge_list),), dtype=np.int32) -progress = xlnk.cma_array(shape=(5,), dtype=np.int32) - -neighbor[:] = neighbor_list -offset[:] = offset_list -edge[:] = edge_list - -# neighbor[:] = [2, 4, 5, 3, 4, 5, 4, 5, 5] -# offset[:] = [0, 0, 3, 6, 8, 9, 9] -# edge[:] = [5, 4, 5, 3, 5, 2, 5, 1, 4, 3, 4, 2, 4, 1, 3, 2, 2, 1] - -myIP.write(0x18, neighbor.physical_address) -myIP.write(0x20, offset.physical_address) -myIP.write(0x28, edge.physical_address) -myIP.write(0x30, len(edge_list)) -myIP.write(0x38, progress.physical_address) - -# for i in range(neighbor.size): -# print("neighbor[%d] = %d" % (i, neighbor[i])) - -# for i in range(offset.size): -# print("offset[%d] = %d" % (i, offset[i])) - -# for i in range(edge.size): -# print("edge[%d] = %d" % (i, edge[i])) - -t2 = time.time() -t = t2 - t1 -print("Preparing input data time: ", str(t)) - -isready = 0; -myIP.write(0x00, 1) - -while( isready != 6 ): -# print(progress[0], progress[1], progress[2], progress[3], progress[4]) - isready = myIP.read(0x00) - -t3 = time.time() -t = t3 - t2 -#tbatch = tbatch + t -#print("Computation finished") -print("PL Time: ", str(t)) - -print("Return value: ", myIP.read(0x10)) diff --git a/triangle_counting_host/tc_host_opt_4.py b/triangle_counting_host/tc_host_opt_4.py deleted file mode 100644 index 9e295d2..0000000 --- a/triangle_counting_host/tc_host_opt_4.py +++ /dev/null @@ -1,162 +0,0 @@ -# coding: utf-8 - -import sys -import numpy as np -import os -import time -import math -from datetime import datetime -from pynq import Xlnk -from pynq import Overlay - -# load our design overlay -overlay = Overlay('tc_opt_4.bit') -print("tc_opt_4.bit loaded") - -acc0 = overlay.triangle_counting_0 -acc1 = overlay.triangle_counting_1 -acc2 = overlay.triangle_counting_2 -acc3 = overlay.triangle_counting_3 - -t0 = time.time() - -neighbor_list = [] -offset_list = [0] -edge_list = [] - -graph_file = open("../../graph/soc-Epinions1_adj.tsv") -# graph_file = open("graph/test.tsv") -lines = graph_file.readlines() - -degree_count = 0 -prev_node = 0 - -for line in lines: - node_a, node_b, _ = map(int, line.split()) - if prev_node != node_b: - offset_list.append(degree_count) - - prev_node = node_b - if node_a < node_b: - edge_list.extend([node_b, node_a]) - else: - neighbor_list.append(node_a) - degree_count += 1 - -offset_list.append(degree_count) - -print("neighbor_list size= ", len(neighbor_list)) -print("offset_list size= ", len(offset_list)) -print("edge_list size= ", len(edge_list)) - -t1 = time.time() - -print("Finished reading graph file. ") -t = t1 - t0 -print("Reading input file time: ", str(t)) - -xlnk = Xlnk() - -num_edge = int(len(edge_list) / 2) -num_batch = 4 -num_edge_batch = int(math.floor(float(num_edge) / num_batch)) -num_edge_last_batch = num_edge - (num_batch-1)*num_edge_batch - -print(num_edge) -print(num_batch) -print(num_edge_batch) -print(num_edge_last_batch) - -neighbor = xlnk.cma_array(shape=(len(neighbor_list),), dtype=np.int32) -offset = xlnk.cma_array(shape=(len(offset_list),), dtype=np.int32) -edge1 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge2 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge3 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge4 = xlnk.cma_array(shape=(2*num_edge_last_batch,), dtype=np.int32) -progress = xlnk.cma_array(shape=(5,), dtype=np.int32) - -neighbor[:] = neighbor_list -offset[:] = offset_list -edge1[:] = edge_list[0:2*num_edge_batch] -edge2[:] = edge_list[2*num_edge_batch:4*num_edge_batch] -edge3[:] = edge_list[4*num_edge_batch:6*num_edge_batch] -edge4[:] = edge_list[6*num_edge_batch:] - -# neighbor[:] = [2, 4, 5, 3, 4, 5, 4, 5, 5] -# offset[:] = [0, 0, 3, 6, 8, 9, 9] -# edge[:] = [5, 4, 5, 3, 5, 2, 5, 1, 4, 3, 4, 2, 4, 1, 3, 2, 2, 1] - -acc0.write(0x00018, neighbor.physical_address) -acc0.write(0x00020, offset.physical_address) -acc0.write(0x00028, edge1.physical_address) -acc0.write(0x00030, 2*num_edge_batch) -acc0.write(0x00038, progress.physical_address) - -acc1.write(0x00018, neighbor.physical_address) -acc1.write(0x00020, offset.physical_address) -acc1.write(0x00028, edge2.physical_address) -acc1.write(0x00030, 2*num_edge_batch) -acc1.write(0x00038, progress.physical_address) - -acc2.write(0x00018, neighbor.physical_address) -acc2.write(0x00020, offset.physical_address) -acc2.write(0x00028, edge3.physical_address) -acc2.write(0x00030, 2*num_edge_batch) -acc2.write(0x00038, progress.physical_address) - -acc3.write(0x00018, neighbor.physical_address) -acc3.write(0x00020, offset.physical_address) -acc3.write(0x00028, edge4.physical_address) -acc3.write(0x00030, 2*num_edge_last_batch) -acc3.write(0x00038, progress.physical_address) - -# for i in range(neighbor.size): -# print("neighbor[%d] = %d" % (i, neighbor[i])) - -# for i in range(offset.size): -# print("offset[%d] = %d" % (i, offset[i])) - -# for i in range(edge.size): -# print("edge[%d] = %d" % (i, edge[i])) - -t2 = time.time() -t = t2 - t1 -print("Preparing input data time: ", str(t)) - -acc0.write(0x00000, 1) -acc1.write(0x00000, 1) -acc2.write(0x00000, 1) -acc3.write(0x00000, 1) - -isready = 0; -while( isready != 6 ): - isready = acc0.read(0x00000) - -isready = 0; -while( isready != 6 ): - isready = acc1.read(0x00000) - -isready = 0; -while( isready != 6 ): - isready = acc2.read(0x00000) - -isready = 0; -while( isready != 6 ): - isready = acc3.read(0x00000) - -t3 = time.time() -t = t3 - t2 -#tbatch = tbatch + t -#print("Computation finished") -print("PL Time: ", str(t)) - -result1 = acc0.read(0x00010) -result2 = acc1.read(0x00010) -result3 = acc2.read(0x00010) -result4 = acc3.read(0x00010) - -print("Return value 1: ", result1) -print("Return value 2: ", result2) -print("Return value 3: ", result3) -print("Return value 4: ", result4) -print("Number of triangles: ", result1+result2+result3+result4) diff --git a/triangle_counting_host/tc_host_opt_7.py b/triangle_counting_host/tc_host_opt_7.py deleted file mode 100644 index 22df986..0000000 --- a/triangle_counting_host/tc_host_opt_7.py +++ /dev/null @@ -1,210 +0,0 @@ -# coding: utf-8 - -import sys -import numpy as np -import os -import time -import math -from datetime import datetime -from pynq import Xlnk -from pynq import Overlay - -# load our design overlay -overlay = Overlay('tc_opt.bit') -print("tc_opt.bit loaded") - -acc0 = overlay.triangle_counting_0 -acc1 = overlay.triangle_counting_1 -acc2 = overlay.triangle_counting_2 -acc3 = overlay.triangle_counting_3 -acc4 = overlay.triangle_counting_4 -acc5 = overlay.triangle_counting_5 -acc6 = overlay.triangle_counting_6 - -t0 = time.time() - -neighbor_list = [] -offset_list = [0] -edge_list = [] - -graph_file = open("graph/soc-Epinions1_adj.tsv") -# graph_file = open("graph/test.tsv") -lines = graph_file.readlines() - -degree_count = 0 -prev_node = 0 - -for line in lines: - node_a, node_b, _ = map(int, line.split()) - if prev_node != node_b: - offset_list.append(degree_count) - - prev_node = node_b - if node_a < node_b: - edge_list.extend([node_b, node_a]) - else: - neighbor_list.append(node_a) - degree_count += 1 - -offset_list.append(degree_count) - -print("neighbor_list size= ", len(neighbor_list)) -print("offset_list size= ", len(offset_list)) -print("edge_list size= ", len(edge_list)) - -t1 = time.time() - -print("Finished reading graph file. ") -t = t1 - t0 -print("Reading input file time: ", str(t)) - -xlnk = Xlnk() - -num_edge = int(len(edge_list) / 2) -num_batch = 7 -num_edge_batch = int(math.floor(float(num_edge) / num_batch)) -num_edge_last_batch = num_edge - (num_batch-1)*num_edge_batch - -print(num_edge) -print(num_batch) -print(num_edge_batch) -print(num_edge_last_batch) - -neighbor = xlnk.cma_array(shape=(len(neighbor_list),), dtype=np.int32) -offset = xlnk.cma_array(shape=(len(offset_list),), dtype=np.int32) -edge1 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge2 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge3 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge4 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge5 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge6 = xlnk.cma_array(shape=(2*num_edge_batch,), dtype=np.int32) -edge7 = xlnk.cma_array(shape=(2*num_edge_last_batch,), dtype=np.int32) -progress = xlnk.cma_array(shape=(5,), dtype=np.int32) - -neighbor[:] = neighbor_list -offset[:] = offset_list -edge1[:] = edge_list[0:2*num_edge_batch] -edge2[:] = edge_list[2*num_edge_batch:4*num_edge_batch] -edge3[:] = edge_list[4*num_edge_batch:6*num_edge_batch] -edge4[:] = edge_list[6*num_edge_batch:8*num_edge_batch] -edge5[:] = edge_list[8*num_edge_batch:10*num_edge_batch] -edge6[:] = edge_list[10*num_edge_batch:12*num_edge_batch] -edge7[:] = edge_list[12*num_edge_batch:] - -# neighbor[:] = [2, 4, 5, 3, 4, 5, 4, 5, 5] -# offset[:] = [0, 0, 3, 6, 8, 9, 9] -# edge[:] = [5, 4, 5, 3, 5, 2, 5, 1, 4, 3, 4, 2, 4, 1, 3, 2, 2, 1] - -acc0.write(0x18, neighbor.physical_address) -acc0.write(0x20, offset.physical_address) -acc0.write(0x28, edge1.physical_address) -acc0.write(0x30, 2*num_edge_batch) -acc0.write(0x38, progress.physical_address) - -acc1.write(0x18, neighbor.physical_address) -acc1.write(0x20, offset.physical_address) -acc1.write(0x28, edge2.physical_address) -acc1.write(0x30, 2*num_edge_batch) -acc1.write(0x38, progress.physical_address) - -acc2.write(0x18, neighbor.physical_address) -acc2.write(0x20, offset.physical_address) -acc2.write(0x28, edge3.physical_address) -acc2.write(0x30, 2*num_edge_batch) -acc2.write(0x38, progress.physical_address) - -acc3.write(0x18, neighbor.physical_address) -acc3.write(0x20, offset.physical_address) -acc3.write(0x28, edge4.physical_address) -acc3.write(0x30, 2*num_edge_batch) -acc3.write(0x38, progress.physical_address) - -acc4.write(0x18, neighbor.physical_address) -acc4.write(0x20, offset.physical_address) -acc4.write(0x28, edge5.physical_address) -acc4.write(0x30, 2*num_edge_batch) -acc4.write(0x38, progress.physical_address) - -acc5.write(0x18, neighbor.physical_address) -acc5.write(0x20, offset.physical_address) -acc5.write(0x28, edge6.physical_address) -acc5.write(0x30, 2*num_edge_batch) -acc5.write(0x38, progress.physical_address) - -acc6.write(0x18, neighbor.physical_address) -acc6.write(0x20, offset.physical_address) -acc6.write(0x28, edge7.physical_address) -acc6.write(0x30, 2*num_edge_last_batch) -acc6.write(0x38, progress.physical_address) - -# for i in range(neighbor.size): -# print("neighbor[%d] = %d" % (i, neighbor[i])) - -# for i in range(offset.size): -# print("offset[%d] = %d" % (i, offset[i])) - -# for i in range(edge.size): -# print("edge[%d] = %d" % (i, edge[i])) - -t2 = time.time() -t = t2 - t1 -print("Preparing input data time: ", str(t)) - -acc0.write(0x00, 1) -acc1.write(0x00, 1) -acc2.write(0x00, 1) -acc3.write(0x00, 1) -acc4.write(0x00, 1) -acc5.write(0x00, 1) -acc6.write(0x00, 1) - -isready = 0; -while( isready != 6 ): - isready = acc0.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc1.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc2.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc3.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc4.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc5.read(0x00) - -isready = 0; -while( isready != 6 ): - isready = acc6.read(0x00) - -t3 = time.time() -t = t3 - t2 -#tbatch = tbatch + t -#print("Computation finished") -print("PL Time: ", str(t)) - -result1 = acc0.read(0x10) -result2 = acc1.read(0x10) -result3 = acc2.read(0x10) -result4 = acc3.read(0x10) -result5 = acc4.read(0x10) -result6 = acc5.read(0x10) -result7 = acc6.read(0x10) - -print("Return value 1: ", result1) -print("Return value 2: ", result2) -print("Return value 3: ", result3) -print("Return value 4: ", result4) -print("Return value 5: ", result5) -print("Return value 6: ", result6) -print("Return value 7: ", result7) -print("Number of triangles: ", result1+result2+result3+result4+result5+result6+result7)