forked from idan-ben-ami/graph-measures
-
Notifications
You must be signed in to change notification settings - Fork 9
/
runMakefileACC.py
62 lines (50 loc) · 2.19 KB
/
runMakefileACC.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
import os
import subprocess
CONDA_PREFIX = os.environ.get("CONDA_PREFIX", None)
def makefile_command(gpu: bool):
if not gpu:
return ["conda run -n boost make -f Makefile-conda"]
return ["conda run -n boost make -f Makefile-conda", "conda run -n boost make -f Makefile-gpu"]
def run_makefile():
# if user use conda run makefile
if CONDA_PREFIX is not None:
print("Download version with accelerated calculation.")
# check if gpu exists
import torch
if not torch.cuda.is_available():
print("Does not support GPU.\nBuild accelerated features.")
gpu_available = False
# path = os.getcwd() + "/runMakefileCPU.py"
# path = "os.system('make -f Makefile-conda')"
else:
print("Support GPU.\nBuild accelerated features for GPU.")
gpu_available = True
# path = os.getcwd() + "/runMakefileGPU.py"
# path = "os.system('make -f Makefile-conda'); os.system('make -f Makefile-gpu')"
# build Makefile
os.chdir("graphMeasures/features_algorithms/accelerated_graph_features/src")
print("cd ed")
os.system("conda env create -f env.yml --force")
print("created conda env")
def conda_base():
split_path = list(os.path.split(CONDA_PREFIX))
while "conda" not in split_path[-1]:
split_path = list(os.path.split(split_path[0]))
return "/".join(split_path)
cmd = '. ' + conda_base() + '/etc/profile.d/conda.sh && conda activate boost'
print(cmd)
subprocess.call(cmd, shell=True, executable='/bin/bash')
print("did subprocess thingy")
for command in makefile_command(gpu_available):
process = subprocess.Popen(
command.split(), stdout=subprocess.PIPE)
print("another subprocessing")
output = process.stdout.read()
print(output)
output, error = process.communicate()
print(output)
print(error)
else:
print("Does not use Conda environment or Linux.\nDownload version without accelerated calculation.")
if __name__ == '__main__':
run_makefile()