Better UI
This commit is contained in:
@@ -33,11 +33,10 @@ TYPES = { 'vector-axpy': {'template':atd.VectorAxpyTemplate,
|
|||||||
|
|
||||||
|
|
||||||
def do_tuning(args):
|
def do_tuning(args):
|
||||||
device = args['device']
|
device = args.device
|
||||||
dname = misc_tools.sanitize_string(device.name)
|
|
||||||
|
|
||||||
if os.path.isfile(args['json-file']):
|
if os.path.isfile(args.json_file):
|
||||||
json_out = json.load(open(args['json-file'], 'r'))
|
json_out = json.load(open(args.json_file, 'r'))
|
||||||
else:
|
else:
|
||||||
json_out = {}
|
json_out = {}
|
||||||
json_out["version"] = "1.0"
|
json_out["version"] = "1.0"
|
||||||
@@ -45,16 +44,16 @@ def do_tuning(args):
|
|||||||
def map_to_list(T, x):
|
def map_to_list(T, x):
|
||||||
return list(map(T, x if isinstance(x, list) else [x]))
|
return list(map(T, x if isinstance(x, list) else [x]))
|
||||||
|
|
||||||
if(args['method']=='simple'):
|
if(args.method=='simple'):
|
||||||
default_tuning_sizes = {'vector-axpy': args['blas1-sizes'], 'reduction': args['blas1-sizes'],
|
default_tuning_sizes = {'vector-axpy': args.blas1_size, 'reduction': args.blas1_size,
|
||||||
'matrix-axpy' : args['blas2-sizes'], 'row-wise-reduction' : args['blas2-sizes'],
|
'matrix-axpy' : args.blas2_size, 'row-wise-reduction' : args.blas2_size,
|
||||||
'matrix-product': args['blas3-sizes']}
|
'matrix-product': args.blas3_size}
|
||||||
|
|
||||||
for operation in ['vector-axpy', 'reduction', 'matrix-axpy', 'row-wise-reduction', 'matrix-product']:
|
for operation in ['vector-axpy', 'reduction', 'matrix-axpy', 'row-wise-reduction', 'matrix-product']:
|
||||||
|
|
||||||
for datatype in [vcl.float32, vcl.float64]:
|
for datatype in [vcl.float32, vcl.float64]:
|
||||||
|
|
||||||
if any(x in args['exclude-operations'] for x in [operation, operation + '-' + datatype.__name__]):
|
if any(x in args.exclude_operations for x in [operation, operation + '-' + datatype.__name__]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ctx = cl.Context([device])
|
ctx = cl.Context([device])
|
||||||
@@ -100,15 +99,15 @@ def do_tuning(args):
|
|||||||
json_out[full_operation][datatype.__name__] = {}
|
json_out[full_operation][datatype.__name__] = {}
|
||||||
D = json_out[full_operation][datatype.__name__]
|
D = json_out[full_operation][datatype.__name__]
|
||||||
|
|
||||||
if args['method'] == 'simple':
|
if args.method == 'simple':
|
||||||
print default_tuning_sizes[operation]
|
print default_tuning_sizes[operation]
|
||||||
profiles = [execution_handler(map(int,default_tuning_sizes[operation]))]
|
profiles = [execution_handler(map(int,default_tuning_sizes[operation]))]
|
||||||
else:
|
else:
|
||||||
def compute_perf(x, t):
|
def compute_perf(x, t):
|
||||||
return TYPES[operation]['perf-index']([datatype().itemsize, x, t])
|
return TYPES[operation]['perf-index']([datatype().itemsize, x, t])
|
||||||
profiles_generator = log_space_gen_product(a, b, args['sample-size'], dimsample)
|
profiles_generator = log_space_gen_product(a, b, args.sample_size, dimsample)
|
||||||
profiles = dataset.sample_profiles(execution_handler, profiles_generator)
|
profiles = dataset.sample_profiles(execution_handler, profiles_generator)
|
||||||
if args['build-model']:
|
if args.build_model:
|
||||||
dataset_generator = log_space_gen_product(a, b, 1000, dimsample)
|
dataset_generator = log_space_gen_product(a, b, 1000, dimsample)
|
||||||
X, Y, profiles = dataset.sample_dataset(os.path.join(full_operation,datatype.__name__), profiles, execution_handler, dataset_generator)
|
X, Y, profiles = dataset.sample_dataset(os.path.join(full_operation,datatype.__name__), profiles, execution_handler, dataset_generator)
|
||||||
clf = train_model(X, Y, profiles, TYPES[operation]['perf-measure'])
|
clf = train_model(X, Y, profiles, TYPES[operation]['perf-measure'])
|
||||||
@@ -117,8 +116,8 @@ def do_tuning(args):
|
|||||||
'threshold': e.tree_.threshold.astype('float64').tolist(),
|
'threshold': e.tree_.threshold.astype('float64').tolist(),
|
||||||
'feature': e.tree_.feature.astype('float64').tolist(),
|
'feature': e.tree_.feature.astype('float64').tolist(),
|
||||||
'value': e.tree_.value[:,:,0].astype('float64').tolist()} for e in clf.estimators_]
|
'value': e.tree_.value[:,:,0].astype('float64').tolist()} for e in clf.estimators_]
|
||||||
if args['viennacl-src-path']:
|
if args.viennacl_src_path:
|
||||||
misc_tools.update_viennacl_headers(args['viennacl-src-path'],device,datatype,operation,additional_parameters,profiles[0])
|
misc_tools.update_viennacl_headers(args.viennacl_src_path, device,datatype,operation,additional_parameters,profiles[0])
|
||||||
D['profiles'] = [map(int, x) for x in profiles]
|
D['profiles'] = [map(int, x) for x in profiles]
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +145,7 @@ def do_tuning(args):
|
|||||||
tune(execution_handler, 100, 4000, 2, ())
|
tune(execution_handler, 100, 4000, 2, ())
|
||||||
#Row-wise reduction
|
#Row-wise reduction
|
||||||
if operation=='row-wise-reduction':
|
if operation=='row-wise-reduction':
|
||||||
for A_trans in args['gemv-layouts']:
|
for A_trans in args.gemv_layouts:
|
||||||
def execution_handler(sizes, fname=os.devnull, parameters=None):
|
def execution_handler(sizes, fname=os.devnull, parameters=None):
|
||||||
A = vcl.Matrix(sizes if A_trans=='N' else sizes[::-1], context=ctx, dtype=datatype, layout=vcl.COL_MAJOR)
|
A = vcl.Matrix(sizes if A_trans=='N' else sizes[::-1], context=ctx, dtype=datatype, layout=vcl.COL_MAJOR)
|
||||||
x = vcl.Vector(sizes[1], context=ctx, dtype=datatype)
|
x = vcl.Vector(sizes[1], context=ctx, dtype=datatype)
|
||||||
@@ -156,7 +155,7 @@ def do_tuning(args):
|
|||||||
tune(execution_handler, 100, 4000, 2, (A_trans,))
|
tune(execution_handler, 100, 4000, 2, (A_trans,))
|
||||||
#Matrix Product
|
#Matrix Product
|
||||||
if operation=='matrix-product':
|
if operation=='matrix-product':
|
||||||
for L in args['gemm-layouts']:
|
for L in args.gemm_layouts:
|
||||||
A_trans = L[0]
|
A_trans = L[0]
|
||||||
B_trans = L[1]
|
B_trans = L[1]
|
||||||
def execution_handler(sizes, fname=os.devnull, parameters=None):
|
def execution_handler(sizes, fname=os.devnull, parameters=None):
|
||||||
@@ -170,14 +169,73 @@ def do_tuning(args):
|
|||||||
return execute(device, vcl.Assign(C,LHS*RHS*alpha + C*beta),(A_trans,B_trans), sizes, fname, parameters)
|
return execute(device, vcl.Assign(C,LHS*RHS*alpha + C*beta),(A_trans,B_trans), sizes, fname, parameters)
|
||||||
tune(execution_handler, 100, 2000, 3,(A_trans,B_trans))
|
tune(execution_handler, 100, 2000, 3,(A_trans,B_trans))
|
||||||
|
|
||||||
json.dump(json_out, open(args['json-file'],'w'))
|
json.dump(json_out, open(args.json_file,'w'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ArgumentsHandler:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
#Command line arguments
|
||||||
|
parent_parser = argparse.ArgumentParser('parent', add_help=False)
|
||||||
|
parent_parser.add_argument('--version', action='version', version='%(prog)s 2.0')
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(parents=[parent_parser])
|
||||||
|
subparsers = parser.add_subparsers(dest='action')
|
||||||
|
print_devices_parser = subparsers.add_parser('list-devices', help='List the devices available', parents=[parent_parser])
|
||||||
|
tune_parser = subparsers.add_parser('tune', help='Auto-tuning', parents=[parent_parser])
|
||||||
|
tune_parser.add_argument("--device", default=0, type=int)
|
||||||
|
tune_parser.add_argument("--exclude-operations", default = '', type=str)
|
||||||
|
tune_parser.add_argument("--gemm-layouts", default='NN,NT,TN,TT', type=str)
|
||||||
|
tune_parser.add_argument("--gemv-layouts", default='N,T', type=str)
|
||||||
|
tune_parser.add_argument("--json-file", default='', type=str)
|
||||||
|
tune_parser.add_argument("--viennacl-src-path", default='', type=str)
|
||||||
|
|
||||||
|
tune_subparsers = tune_parser.add_subparsers(dest='method')
|
||||||
|
simple_parser = tune_subparsers.add_parser('simple', help = 'Tune each operation for unique sizes')
|
||||||
|
|
||||||
|
simple_parser.add_argument("--blas1-size", default = 10e6, type=int)
|
||||||
|
simple_parser.add_argument("--blas2-size", nargs=2, default=[2560,2560], type=int)
|
||||||
|
simple_parser.add_argument("--blas3-size", nargs=3, default=[1536,1536,1536],type=int)
|
||||||
|
|
||||||
|
full_parser = tune_subparsers.add_parser('full', help = 'Tune each operation for randomly chosen sizes')
|
||||||
|
full_parser.add_argument("--build-model", default=False, type=bool)
|
||||||
|
full_parser.add_argument("--sample-size", default=30, type=int)
|
||||||
|
|
||||||
|
args = parent_parser.parse_args()
|
||||||
|
self.__dict__ = args.__dict__.copy()
|
||||||
|
|
||||||
|
#No action argument -> interactive tuning
|
||||||
|
if 'action' not in vars(args):
|
||||||
|
def add_input(help, default):
|
||||||
|
return raw_input(help + "[" + default + "] : ") or default
|
||||||
|
|
||||||
|
self.device = add_input('Device to tune for','0')
|
||||||
|
self.exclude_operations = add_input('Operations to exclude','vector-axpy,matrix-axpy,reduction,row-wise-reduction,matrix-product-float64').split(',')
|
||||||
|
self.gemm_layouts = '' if 'matrix-product' in self.exclude_operations else add_input('GEMV Layouts', 'NN,NT,TN,TT')
|
||||||
|
self.gemv_layouts = '' if 'row-wise-reduction' in self.exclude_operations else add_input('GEMV Layouts', 'N,T')
|
||||||
|
self.json_file = add_input('JSON File', misc_tools.sanitize_string(devices[int(self.device)].name) + '.json')
|
||||||
|
self.method = add_input('Tuning type', 'simple')
|
||||||
|
if self.method == 'simple':
|
||||||
|
self.blas1_size = add_input('BLAS1 size', '10e6')
|
||||||
|
self.blas2_size = add_input('BLAS2 sizes (M,N)', '2560,2560').split(',')
|
||||||
|
self.blas3_size = add_input('BLAS3 sizes (M,N,K)', '1024,1024,1024').split(',')
|
||||||
|
self.build_model = True
|
||||||
|
self.sample_size = 30
|
||||||
|
|
||||||
|
#Retypes
|
||||||
|
self.device = devices[int(self.device)]
|
||||||
|
self.gemm_layouts = self.gemm_layouts.split(',')
|
||||||
|
self.gemv_layouts = self.gemv_layouts.split(',')
|
||||||
|
if self.method == 'simple':
|
||||||
|
self.blas1_size = [int(float(self.blas1_size))]
|
||||||
|
self.blas2_size = map(int, self.blas2_size)
|
||||||
|
self.blas3_size = map(int, self.blas3_size)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
devices = [d for platform in cl.get_platforms() for d in platform.get_devices()]
|
devices = [d for platform in cl.get_platforms() for d in platform.get_devices()]
|
||||||
print("----------------")
|
print("----------------")
|
||||||
print("Devices available:")
|
print("Devices available:")
|
||||||
@@ -186,29 +244,10 @@ if __name__ == "__main__":
|
|||||||
print 'Device', i, '|', cl.device_type.to_string(d.type), '|', d.name, 'on', d.platform.name
|
print 'Device', i, '|', cl.device_type.to_string(d.type), '|', d.name, 'on', d.platform.name
|
||||||
print("----------------")
|
print("----------------")
|
||||||
|
|
||||||
args = {}
|
args = ArgumentsHandler()
|
||||||
|
|
||||||
def add_input(help, default):
|
|
||||||
return raw_input(help + "[" + default + "] : ") or default
|
|
||||||
|
|
||||||
args['device'] = devices[int(add_input('Device to tune for','0'))]
|
|
||||||
args['exclude-operations'] = add_input('Operations to exclude','vector-axpy,matrix-axpy,reduction,row-wise-reduction,matrix-product-float64').split(',')
|
|
||||||
if not 'matrix-product' in args['exclude-operations']:
|
|
||||||
args['gemm-layouts'] = add_input('GEMM Layouts', 'NN,NT,TN,TT').split(',')
|
|
||||||
if not 'row-wise-reduction' in args['exclude-operations']:
|
|
||||||
args['gemv-layouts'] = add_input('GEMV Layouts', 'N,T').split(',')
|
|
||||||
args['json-file'] = add_input('JSON File', misc_tools.sanitize_string(args['device'].name) + '.json')
|
|
||||||
args['method'] = add_input('Tuning type', 'simple')
|
|
||||||
if args['method'] == 'simple':
|
|
||||||
args['blas1-sizes'] = [int(float(add_input('BLAS1 size', '10e6')))]
|
|
||||||
args['blas2-sizes'] = map(int, add_input('BLAS2 sizes (M,N)', '2560,2560').split(','))
|
|
||||||
args['blas3-sizes'] = map(int, add_input('BLAS3 sizes (M,N,K)', '1024,1024,1024').split(','))
|
|
||||||
args['build-model'] = True
|
|
||||||
args['sample-size'] = 30
|
|
||||||
args['viennacl-src-path'] = ''
|
|
||||||
|
|
||||||
|
|
||||||
print("------")
|
print("------")
|
||||||
print("Auto-tuning")
|
print("Auto-tuning")
|
||||||
print("------")
|
print("------")
|
||||||
|
|
||||||
do_tuning(args)
|
do_tuning(args)
|
||||||
|
@@ -187,7 +187,7 @@ class GeneticOperators(object):
|
|||||||
gen = gen + 1
|
gen = gen + 1
|
||||||
best_profile = '(%s)'%','.join(map(str,self.decode(hof[0])))
|
best_profile = '(%s)'%','.join(map(str,self.decode(hof[0])))
|
||||||
best_performance = compute_perf(hof[0].fitness.values[0])
|
best_performance = compute_perf(hof[0].fitness.values[0])
|
||||||
sys.stdout.write('Generation %d | Time %d | Best %d %s [ for %s ]\n'%(gen, time.time() - start_time, best_performance, perf_metric, best_profile))
|
sys.stdout.write('Generation %d | Time %d | Best %d %s [ for %s ]\r'%(gen, time.time() - start_time, best_performance, perf_metric, best_profile))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
return self.decode(hof[0])
|
return self.decode(hof[0])
|
||||||
|
Reference in New Issue
Block a user