Trying a new mutation operator
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#will save the archive into /tmp/name-of-operation.dat
|
||||
tmp-folder = /tmp/
|
||||
|
||||
[vector-axpy]
|
||||
devices = 0
|
||||
precision = all
|
||||
size = 10000000
|
||||
#~ [vector-axpy]
|
||||
#~ devices = 0
|
||||
#~ precision = all
|
||||
#~ size = 10000000
|
||||
|
||||
#~ [matrix-axpy]
|
||||
#~ devices = 0
|
||||
@@ -19,6 +19,6 @@ size = 10000000
|
||||
|
||||
[matrix-product]
|
||||
devices = 0
|
||||
precision = all
|
||||
precision = single
|
||||
layout = NT
|
||||
size = 1536, 1536, 1536
|
||||
|
@@ -71,7 +71,7 @@ def do_tuning(config_fname, spec_fname, viennacl_root):
|
||||
p = config[operation]
|
||||
confdevices = p['devices']
|
||||
devices = utils.DEVICES_PRESETS[confdevices] if confdevices in utils.DEVICES_PRESETS else [utils.all_devices[int(i)] for i in confdevices]
|
||||
precisions = ['single', 'double'] if 'all' in p['precision'] else p['precision']
|
||||
precisions = map_to_list((str, p['precision']))
|
||||
datatypes = [DATATYPES[k] for k in precisions]
|
||||
s = map_to_list((int, p['size']))
|
||||
|
||||
|
@@ -53,10 +53,13 @@ class GeneticOperators(object):
|
||||
return (new_x, new_y)
|
||||
|
||||
def repair(self,func):
|
||||
|
||||
def repair_impl(child):
|
||||
D = odict(zip(self.parameter_names, child))
|
||||
dummy_template = self.build_template(self.ParameterType(*D.values()))
|
||||
FetchingPolicy = vcl.atidlas.FetchingPolicy;
|
||||
D['local-size-0'] = max(1, D['local-size-0'])
|
||||
D['local-size-1'] = max(1, D['local-size-1'])
|
||||
if 'local-size-1' not in D:
|
||||
D['local-size-0'] = min(D['local-size-0'], self.device.max_work_group_size)
|
||||
elif D['local-size-0']*D['local-size-1'] > self.device.max_work_group_size:
|
||||
@@ -67,11 +70,13 @@ class GeneticOperators(object):
|
||||
if self.ParameterType is vcl.atidlas.MatrixProductTemplate.Parameters:
|
||||
if dummy_template.A_trans != 'N' and dummy_template.B_trans != 'T':
|
||||
D['simd-width'] = 1
|
||||
|
||||
D['mS'] = max(D['mS'], D['simd-width'])
|
||||
D['mS'] = D['mS'] - D['mS']%D['simd-width']
|
||||
|
||||
D['kL'] = max(1, D['kL'])
|
||||
D['kS'] = max(1, D['kS'])
|
||||
|
||||
D['mS'] = max(D['mS'], D['simd-width'])
|
||||
D['nS'] = max(D['nS'], D['simd-width'])
|
||||
D['mS'] = D['mS'] - D['mS']%D['simd-width']
|
||||
D['nS'] = D['nS'] - D['nS']%D['simd-width']
|
||||
|
||||
|
||||
@@ -100,16 +105,48 @@ class GeneticOperators(object):
|
||||
for i in range(len(child)):
|
||||
if child[i] != new_child[i]:
|
||||
child[i] = new_child[i]
|
||||
|
||||
return offspring
|
||||
return wrappper
|
||||
|
||||
def mutate(self, individual, indpb):
|
||||
for i in range(len(individual)):
|
||||
if random.random() < indpb:
|
||||
j = self.parameters[i].index(individual[i])
|
||||
j = max(0,min(random.randint(j-2, j+2),len(self.parameters[i])-1))
|
||||
individual[i] = self.parameters[i][j]
|
||||
def mutate(self, individual):
|
||||
p = random.random()
|
||||
coef = random.choice([2, 4])
|
||||
multiply_or_divide = random.choice([lambda x:x/coef, lambda x:x*coef])
|
||||
if p < 0.1 :
|
||||
individual[0] = random.choice(self.parameters[0])
|
||||
elif p < 0.2:
|
||||
idx = random.choice([1, 4])
|
||||
nidx = 4 if idx==1 else 1
|
||||
individual[idx] = individual[idx]*coef
|
||||
individual[nidx] = individual[nidx]/coef
|
||||
elif p < 0.3:
|
||||
idx = random.choice([1, 4])
|
||||
individual[idx] = multiply_or_divide(individual[idx])
|
||||
if idx==1:
|
||||
individual[9] = multiply_or_divide(individual[9])
|
||||
elif p < 0.4:
|
||||
idx = random.choice([3, 6])
|
||||
nidx = 6 if idx==3 else 3
|
||||
individual[idx] = individual[idx]*coef
|
||||
individual[nidx] = individual[nidx]/coef
|
||||
elif p < 0.5:
|
||||
idx = random.choice([3, 6])
|
||||
individual[idx] = multiply_or_divide(individual[idx])
|
||||
if idx==3:
|
||||
individual[10] = multiply_or_divide(individual[10])
|
||||
elif p < 0.6:
|
||||
individual[2] = multiply_or_divide(individual[2])
|
||||
elif p < 0.7:
|
||||
individual[4] = multiply_or_divide(individual[4])
|
||||
elif p < 0.8:
|
||||
individual[7] = random.choice([x for x in self.parameters[7] if x!=individual[7]])
|
||||
elif p < 0.9:
|
||||
individual[8] = random.choice([x for x in self.parameters[8] if x!=individual[8]])
|
||||
elif p < 1:
|
||||
idx = random.choice([9, 10])
|
||||
nidx = 10 if idx==9 else 9
|
||||
individual[idx] = individual[idx]*coef
|
||||
individual[nidx] = individual[nidx]/coef
|
||||
return individual,
|
||||
|
||||
def evaluate(self, individual):
|
||||
|
@@ -60,15 +60,14 @@ def genetic(statement, context, TemplateType, build_template, parameter_names, a
|
||||
toolbox = base.Toolbox()
|
||||
toolbox.register("individual", tools.initIterate, creator.Individual, gen.init)
|
||||
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
|
||||
toolbox.decorate("population", gen.repair)
|
||||
toolbox.register("evaluate", gen.evaluate)
|
||||
toolbox.register("mate", tools.cxUniform, indpb=0.1)
|
||||
toolbox.register("mate", tools.cxTwoPoint)
|
||||
toolbox.decorate("mate", gen.repair)
|
||||
toolbox.register("mutate", gen.mutate, indpb=0.1)
|
||||
toolbox.register("mutate", gen.mutate)
|
||||
toolbox.decorate("mutate", gen.repair)
|
||||
toolbox.register("select", tools.selNSGA2)
|
||||
|
||||
pop = toolbox.population(n=70)
|
||||
pop = toolbox.population(n=30)
|
||||
hof = tools.HallOfFame(1)
|
||||
|
||||
best_performer = lambda x: max([compute_perf(hof[0].fitness.values[0]) for t in x])
|
||||
@@ -81,4 +80,4 @@ def genetic(statement, context, TemplateType, build_template, parameter_names, a
|
||||
stats.register("max (" + perf_metric + ")", lambda x: max([compute_perf(hof[0].fitness.values[0]) for t in x]))
|
||||
stats.register("profile ", lambda x: '(%s)'%','.join(map(str,hof[0])))
|
||||
|
||||
pop = eaMuPlusLambda(pop, toolbox, 70, 100, cxpb=0.1, mutpb=0.1, maxtime='5m0s', maxgen=1000, halloffame=hof, compute_perf=compute_perf, perf_metric=perf_metric)
|
||||
pop = eaMuPlusLambda(pop, toolbox, 30, 50, cxpb=0.2, mutpb=0.3, maxtime='5m0s', maxgen=200, halloffame=hof, compute_perf=compute_perf, perf_metric=perf_metric)
|
||||
|
Reference in New Issue
Block a user