forked from ChrisCummins/paper-end2end-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·123 lines (101 loc) · 3.46 KB
/
configure
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
#
# Copyright 2016, 2017 Chris Cummins <[email protected]>.
#
# This file is part of CLgen.
#
# CLgen is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CLgen is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CLgen. If not, see <http://www.gnu.org/licenses/>.
#
import json
import sys
from argparse import ArgumentParser
def yes_no(question, default="no"):
"""Ask a yes/no question and return user's answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is True for "yes" or False for "no".
"""
valid = {"yes": True, "y": True, "ye": True,
"no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
sys.stdout.write(question + prompt)
if sys.version_info >= (3, 0):
choice = input().lower()
else:
choice = raw_input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "
"(or 'y' or 'n').\n")
def to_make(val):
return str(int(val))
def to_python(val):
return "True" if val else "False"
def to_text(val):
return "yes" if val else "no"
def main():
parser = ArgumentParser(description="Configure build.")
parser.add_argument("-r", "--reconfigure", action="store_true",
help="re-run configuraiton using previous settings")
parser.add_argument("-b", "--batch", action="store_true",
help="defaults all options to 'no'. Override with:")
parser.add_argument("--with-cuda", action="store_true")
args = parser.parse_args()
if args.reconfigure:
args.batch = True
try:
with open(".config.json") as infile:
cfg = json.loads(infile.read())
except FileNotFoundError:
print("you must run ./configure first", file=sys.stderr)
sys.exit(1)
else:
cfg = {
"cuda": args.with_cuda,
}
# get input from user
if not args.batch:
if not cfg["cuda"]:
cfg["cuda"] = yes_no(
"Enable CUDA support? (requires NVIDIA GPU with CUDA 8.0 and cuDNN)")
# generate JSON config file
with open(".config.json", "w") as outfile:
json.dump(cfg, outfile)
# generate make config file
with open(".config.make", "w") as outfile:
print("USE_CUDA := " + to_make(cfg["cuda"]), file=outfile)
# generate python config file
with open(".config.py", "w") as outfile:
print("USE_CUDA = " + to_python(cfg["cuda"]), file=outfile)
print()
print("You may now run 'make'.")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\naborting without writing changes", file=sys.stderr)
sys.exit(1)