"tests/data/vscode:/vscode.git/clone" did not exist on "e21e61e05c88d30ec9d1f8af1d594959de390ae5"
Commit c0e26328 authored by Paul's avatar Paul
Browse files

Add precompile flag to build in parallel

parent 6ad936f1
import os, json, subprocess, tempfile, sys, argparse, contextlib import os, json, subprocess, tempfile, sys, argparse, contextlib, multiprocessing, multiprocessing.dummy
@contextlib.contextmanager @contextlib.contextmanager
...@@ -46,21 +46,23 @@ def get_device_time(s): ...@@ -46,21 +46,23 @@ def get_device_time(s):
fields = s.split(',') fields = s.split(',')
return convert_to_float(fields[-1].strip()) return convert_to_float(fields[-1].strip())
def run_driver_ck(config, tuning, iterations):
b = {
'settings': {
'iterations': iterations
},
'compile_op': {
'name': 'ck_gemm',
'check': True,
'tuning_val': tuning,
'inputs': config
}
}
return run_driver(b)
def benchmark_ck(config, tuning): def benchmark_ck(config, tuning):
try: try:
b = { for line in run_driver_ck(config, tuning, 100):
'settings': {
'iterations': 100
},
'compile_op': {
'name': 'ck_gemm',
'check': True,
'tuning_val': tuning,
'inputs': config
}
}
for line in run_driver(b):
dtime = get_device_time(line) dtime = get_device_time(line)
print(dtime) print(dtime)
return float(dtime) return float(dtime)
...@@ -69,7 +71,6 @@ def benchmark_ck(config, tuning): ...@@ -69,7 +71,6 @@ def benchmark_ck(config, tuning):
except: except:
return sys.float_info.max return sys.float_info.max
def benchmark(config, size): def benchmark(config, size):
times = [benchmark_ck(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))
...@@ -84,6 +85,16 @@ def parse_log(f): ...@@ -84,6 +85,16 @@ def parse_log(f):
config = json.loads(line) config = json.loads(line)
yield config yield config
def precompile(x):
try:
list(run_driver_ck(x[0], x[1], 0))
except:
pass
def precompile_log(f, n):
solutions = ((config, i) for config in parse_log(f) for i in range(n))
with multiprocessing.Pool(24) as p:
list(p.imap(precompile, solutions))
def benchmark_log(f, n): def benchmark_log(f, n):
result = [] result = []
...@@ -106,12 +117,18 @@ def parse_args(): ...@@ -106,12 +117,18 @@ def parse_args():
type=str, type=str,
metavar='file', metavar='file',
help='Output json file to save tunings') help='Output json file to save tunings')
parser.add_argument('--precompile',
'-p',
action='store_true',
help='Precompile kernels first in parallel')
parser.add_argument('-n', type=int, help='Number of instances to tune') parser.add_argument('-n', type=int, help='Number of instances to tune')
args = parser.parse_args() args = parser.parse_args()
return args return args
def run(args): def run(args):
if(args.precompile):
precompile_log(args.log, args.n)
tuned = benchmark_log(args.log, args.n) tuned = benchmark_log(args.log, args.n)
json.dump(tuned, open(args.out, 'w+')) json.dump(tuned, open(args.out, 'w+'))
......
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