-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdriver_gunrock.py
77 lines (66 loc) · 3.4 KB
/
driver_gunrock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import subprocess
import driver
import config
import dataset
__all__ = [
"DriverGunrock"
]
class DriverGunrock(driver.Driver):
def __init__(self):
super().__init__()
self.exec_dir = config.DEPS / "gunrock" / "build" / "bin"
self.bfs = "bfs"
self.sssp = "sssp"
self.pr = "pr"
self.tc = "tc"
# type of the graph file, market (mtx) by default
self.type = "market"
# Device for evaluations
self.device = 0
# Type of graph
self.undirected = 0
def name(self) -> str:
return "gunrock"
def run_bfs(self, graph: dataset.Graph, source_vertex, num_iterations) -> driver.ExecutionResult:
output = subprocess.check_output([str(self.exec_dir / self.bfs),
f"--src={source_vertex}",
f"--num-runs={num_iterations + 1}",
f"--undirected={self.undirected}",
f"--graph-file={graph.path()}",
f"--graph-type={self.type}",
f"--device={self.device}"])
return DriverGunrock._parse_output(output)
def run_sssp(self, graph: dataset.Graph, source_vertex, num_iterations) -> driver.ExecutionResult:
output = subprocess.check_output([str(self.exec_dir / self.sssp),
f"--src={source_vertex}",
f"--num-runs={num_iterations + 1}",
f"--undirected={self.undirected}",
f"--graph-file={graph.path()}",
f"--graph-type={self.type}",
f"--device={self.device}"])
return DriverGunrock._parse_output(output)
def run_pr(self, graph: dataset.Graph, num_iterations) -> driver.ExecutionResult:
output = subprocess.check_output([str(self.exec_dir / self.pr),
f"--num-runs={num_iterations + 1}",
f"--undirected={self.undirected}",
f"--graph-file={graph.path()}",
f"--graph-type={self.type}",
f"--device={self.device}"])
return DriverGunrock._parse_output(output)
def run_tc(self, graph: dataset.Graph, num_iterations) -> driver.ExecutionResult:
output = subprocess.check_output([str(self.exec_dir / self.sssp),
f"--num-runs={num_iterations + 1}",
f"--undirected=1",
f"--graph-file={graph.path()}",
f"--graph-type={self.type}",
f"--device={self.device}"])
return DriverGunrock._parse_output(output)
@staticmethod
def _parse_output(output):
lines = output.decode("ASCII").replace("\r", "").split("\n")
runs = []
for line in lines:
if line.startswith("Run ") and not line.startswith("Run CPU"):
runs.append(float(line.split(" ")[3]))
# First one is warm-up (we add it implicitly)
return driver.ExecutionResult(runs[0], runs[1:])