Commit efbe9607 authored by Paul's avatar Paul
Browse files

Refactor tuning script

parent 746291a8
...@@ -17,8 +17,28 @@ def tmp_file(dump=None): ...@@ -17,8 +17,28 @@ def tmp_file(dump=None):
def pretty_print(obj): def pretty_print(obj):
print(json.dumps(obj, indent=2)) print(json.dumps(obj, indent=2))
def run_driver(b):
print(b)
with tmp_file(lambda tf: json.dump(b, tf)) as tf:
cp = subprocess.run('./bin/gpu-driver {}'.format(tf),
capture_output=True,
shell=True)
for line in cp.stdout.decode().split("\n"):
s = line.strip()
if not s:
continue
if not ']: ' in s:
continue
yield s.split(']: ')[1].strip()
def convert_to_float(s):
return s[:-2]
def benchmark_one(config, tuning): def get_device_time(s):
fields = s.split(',')
return convert_to_float(fields[-1].strip())
def benchmark_ck(config, tuning):
b = { b = {
'settings': { 'settings': {
'iterations': 100 'iterations': 100
...@@ -29,37 +49,30 @@ def benchmark_one(config, tuning): ...@@ -29,37 +49,30 @@ def benchmark_one(config, tuning):
'inputs': config 'inputs': config
} }
} }
print(b) for line in run_driver(b):
with tmp_file(lambda tf: json.dump(b, tf)) as tf: dtime = get_device_time(line)
cp = subprocess.run('./bin/gpu-driver {}'.format(tf), print(dtime)
capture_output=True, return dtime
shell=True)
for line in cp.stdout.decode().split("\n"):
s = line.strip()
if not s:
continue
if not ',' in s:
continue
fields = s.split(',')
dtime = fields[-1].strip()
print(dtime)
return float(dtime[:-2])
return sys.float_info.max return sys.float_info.max
def benchmark(config, size): def benchmark(config, size):
times = [benchmark_one(config, i) for i in range(size)] times = [benchmark_ck(config, i) for i in range(size)]
return times.index(min(times)) return times.index(min(times))
def benchmark_log(f): def parse_log(f):
result = []
for line in open(f).readlines(): for line in open(f).readlines():
line = line.strip() line = line.strip()
if not line.startswith('ck_gemm:'): if not line.startswith('ck_gemm:'):
continue continue
line = line[len('ck_gemm:'):].strip() line = line[len('ck_gemm:'):].strip()
config = json.loads(line) config = json.loads(line)
yield config
def benchmark_log(f):
result = []
for config in parse_log(f):
tuned = benchmark(config, 13) tuned = benchmark(config, 13)
result.append([config, tuned]) result.append([config, tuned])
return result return result
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment