Files
triton/autotune/python/optimize.py

54 lines
2.2 KiB
Python
Raw Normal View History

2014-09-02 22:03:20 -04:00
import array
import numpy as np
import random
2014-09-11 18:17:24 -04:00
import sys
2014-09-02 22:03:20 -04:00
2014-09-11 16:13:46 -04:00
import itertools
import tools
import deap.tools
2014-09-02 22:03:20 -04:00
2014-09-11 16:13:46 -04:00
from genetic import GeneticOperators
2014-09-27 20:54:17 -04:00
#~ def parameter_space(operation):
#~ simd = [1, 2, 4, 8]
#~ pow2_1D = [2**k for k in range(12)]
#~ pow2_2D = [2**i for i in range(8)]
#~ pow2_2D_unrolled = [2**i for i in range(8)]
#~ FetchingPolicy = vcl.atidlas.FetchingPolicy
#~ fetch = [FetchingPolicy.FETCH_FROM_LOCAL, FetchingPolicy.FETCH_FROM_GLOBAL_CONTIGUOUS, FetchingPolicy.FETCH_FROM_GLOBAL_STRIDED]
#~ if operation == 'vector-axpy': return [simd, pow2_1D, pow2_1D, fetch]
#~ if operation == 'reduction': return [simd, pow2_1D, pow2_1D, fetch]
#~ if operation == 'matrix-axpy': return [simd, pow2_2D, pow2_2D, pow2_2D, pow2_2D, fetch]
#~ if operation == 'row-wise-reduction': return [simd, pow2_2D, pow2_2D, pow2_1D, fetch]
#~ if operation == 'matrix-product': return [simd, pow2_2D, pow2_2D, pow2_2D, pow2_2D_unrolled, pow2_2D_unrolled, pow2_2D_unrolled, fetch, fetch, [0] + pow2_2D, [0] + pow2_2D]
2014-09-29 03:01:33 +02:00
#~
2014-09-27 20:54:17 -04:00
#~ def exhaustive(statement, context, TemplateType, build_template, parameter_names, all_parameters, compute_perf, perf_metric, out):
#~ device = context.devices[0]
#~ nvalid = 0
#~ current = 0
#~ minT = float('inf')
#~ for individual in itertools.product(*all_parameters):
#~ template = build_template(TemplateType.Parameters(*individual))
#~ if not tools.skip(template, statement, device):
#~ nvalid = nvalid + 1
#~ for individual in itertools.product(*all_parameters):
#~ template = build_template(TemplateType.Parameters(*individual))
#~ try:
#~ T = tools.benchmark(template,statement,device)
#~ current = current + 1
#~ if T < minT:
#~ minT = T
#~ best = individual
#~ sys.stdout.write('%d / %d , Best is %d %s for %s\r'%(current, nvalid, compute_perf(minT), perf_metric, best))
#~ sys.stdout.flush()
#~ except:
#~ pass
#~ sys.stdout.write('\n')
#~ sys.stdout.flush()
2014-09-29 03:01:33 +02:00
#~
2014-10-03 09:29:45 +02:00
def genetic(statement, device, TemplateType, build_template, compute_perf, perf_metric, out):
GA = GeneticOperators(device, statement, TemplateType, build_template, out)
2014-09-30 10:11:22 +02:00
return GA.optimize(maxtime='2m30s', maxgen=1000, compute_perf=compute_perf, perf_metric=perf_metric)