Commit efbe9607 authored by Paul's avatar Paul
Browse files

Refactor tuning script

parent 746291a8
...@@ -17,18 +17,7 @@ def tmp_file(dump=None): ...@@ -17,18 +17,7 @@ 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):
def benchmark_one(config, tuning):
b = {
'settings': {
'iterations': 100
},
'compile_op': {
'name': 'ck_gemm',
'tuning_val': tuning,
'inputs': config
}
}
print(b) print(b)
with tmp_file(lambda tf: json.dump(b, tf)) as tf: with tmp_file(lambda tf: json.dump(b, tf)) as tf:
cp = subprocess.run('./bin/gpu-driver {}'.format(tf), cp = subprocess.run('./bin/gpu-driver {}'.format(tf),
...@@ -38,28 +27,52 @@ def benchmark_one(config, tuning): ...@@ -38,28 +27,52 @@ def benchmark_one(config, tuning):
s = line.strip() s = line.strip()
if not s: if not s:
continue continue
if not ',' in s: if not ']: ' in s:
continue continue
yield s.split(']: ')[1].strip()
def convert_to_float(s):
return s[:-2]
def get_device_time(s):
fields = s.split(',') fields = s.split(',')
dtime = fields[-1].strip() return convert_to_float(fields[-1].strip())
def benchmark_ck(config, tuning):
b = {
'settings': {
'iterations': 100
},
'compile_op': {
'name': 'ck_gemm',
'tuning_val': tuning,
'inputs': config
}
}
for line in run_driver(b):
dtime = get_device_time(line)
print(dtime) print(dtime)
return float(dtime[:-2]) return dtime
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