Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import argparse
import logging
import opentuner
from opentuner.search.manipulator import (ConfigurationManipulator,
PermutationParameter)
from opentuner.search.objective import MinimizeTime
from opentuner.measurement import MeasurementInterface
from opentuner.measurement.inputmanager import FixedInputManager
from opentuner.tuningrunmain import TuningRunMain
parser = argparse.ArgumentParser(parents=opentuner.argparsers())
parser.add_argument('data', help='distance matrix file')
class TSP(MeasurementInterface):
def __init__(self, args):
super(TSP, self).__init__(args)
data = args.data
m = open(data).readlines()
self.distance = [[int(i) for i in l.split()] for l in m]
def run(self, desired_result, input, limit):
cfg = desired_result.configuration.data
p = cfg[0] # cheating: should use manipulator function
t = self.eval_path(p)
return opentuner.resultsdb.models.Result(time=t)
def eval_path(self, p):
""" Given permutation of cities as a list of indices,
return total path length """
out = sum(self.distance[p[i]][p[i+1]] for i in range(len(p)-1))
import logging
import json
import sjparameters
import configuration
import streamjit
import sys
import deps #fix sys.path
import opentuner
from opentuner.search.manipulator import (ConfigurationManipulator, IntegerParameter, FloatParameter)
from opentuner.measurement import MeasurementInterface
from opentuner.measurement.inputmanager import FixedInputManager
from opentuner.tuningrunmain import TuningRunMain
from opentuner.search.objective import MinimizeTime
class StreamJitMI(MeasurementInterface):
''' Measurement Interface for tunning a StreamJit application'''
def __init__(self, args, ss, manipulator, inputmanager, objective):
super(StreamJitMI, self).__init__(args = args, program_name = args.program, manipulator = manipulator, input_manager = inputmanager, objective = objective)
self.sdk = ss
self.trycount = 0
def run(self, desired_result, input, limit):
self.trycount = self.trycount + 1
cfg = desired_result.configuration.data
self.niceprint(cfg)
self.sdk.sendmsg("%s\n"%cfg)
msg = self.sdk.recvmsg()
exetime = float(msg)
if exetime < 0:
print "Error in execution"
return opentuner.resultsdb.models.Result(state='ERROR', time=float('inf'))
import logging
import json
import sjparameters
import configuration
import streamjit
import sys
import deps #fix sys.path
import opentuner
from opentuner.search.manipulator import (ConfigurationManipulator, IntegerParameter, FloatParameter)
from opentuner.measurement import MeasurementInterface
from opentuner.measurement.inputmanager import FixedInputManager
from opentuner.tuningrunmain import TuningRunMain
from opentuner.search.objective import MinimizeTime
class StreamJitMI(MeasurementInterface):
''' Measurement Interface for tunning a StreamJit application'''
def __init__(self, args, ss, manipulator, inputmanager, objective):
super(StreamJitMI, self).__init__(args = args, program_name = args.program, manipulator = manipulator, input_manager = inputmanager, objective = objective)
self.sdk = ss
self.trycount = 0
def run(self, desired_result, input, limit):
self.trycount = self.trycount + 1
print self.trycount
cfg = desired_result.configuration.data
#self.niceprint(cfg)
self.sdk.sendmsg("%s\n"%cfg)
msg = self.sdk.recvmsg()
if (msg == "exit\n"):
#data = raw_input ( "exit cmd received. Press Keyboard to exit..." )
self.sdk.close()
import subprocess
import tempfile
import os
import re
import time
import deps #fix sys.path
import opentuner
from opentuner.search.manipulator import (ConfigurationManipulator, IntegerParameter, FloatParameter)
from opentuner.measurement import MeasurementInterface
from opentuner.measurement.inputmanager import FixedInputManager
from opentuner.tuningrunmain import TuningRunMain
from opentuner.search.objective import MinimizeTime
from jvmparameters import *
class StreamJITMI(MeasurementInterface):
def __init__(self, args, configuration, jvm_options, manipulator, inputmanager, objective):
args.technique = ['StreamJITBandit']
super(StreamJITMI, self).__init__(args = args, program_name = args.program, manipulator = manipulator, input_manager = inputmanager, objective = objective)
self.program = args.program
self.timestamp = args.timestamp
self.config = configuration
self.config.put_extra_data("benchmark", self.program, "java.lang.String")
self.jvm_options = jvm_options
def run(self, desired_result, input, limit):
cfg_data = desired_result.configuration.data
for k in self.config.params:
self.config.getParameter(k).update_value_for_json(cfg_data)
jvm_args = self.jvm_args_to_list(cfg_data)
with tempfile.NamedTemporaryFile() as f:
pass
class Progress(FitnessFunction):
def __call__(self, won, x_pos, elapsed_frames):
return -float(x_pos)
class ProgressPlusTimeRemaining(FitnessFunction):
def __call__(self, won, x_pos, elapsed_frames):
"""x_pos plus 1 for each frame remaining on the timer on a win. This results in a large discontinuity at wins. This was the fitness function used for the OpenTuner paper, though the paper only discussed time-to-first-win."""
return -float(x_pos + 400*60 - elapsed_frames) if won else -float(x_pos)
class ProgressTimesAverageSpeed(FitnessFunction):
def __call__(self, won, x_pos, elapsed_frames):
return -x_pos * (old_div(float(x_pos),elapsed_frames))
class SMBMI(MeasurementInterface):
def __init__(self, args):
super(SMBMI, self).__init__(args)
self.parallel_compile = True
self.args = args
def manipulator(self):
return self.args.representation.manipulator()
def compile(self, cfg, id):
left, right, down, running, jumping = self.args.representation.interpret(cfg)
fm2 = fm2_smb(left, right, down, running, jumping)
try:
wl, x_pos, framecount = run_movie(fm2, self.args)
except ValueError:
return opentuner.resultsdb.models.Result(state='ERROR', time=float('inf'))
print(wl, x_pos, framecount)
from opentuner.measurement import MeasurementInterface
from opentuner.measurement.inputmanager import FixedInputManager
from opentuner.tuningrunmain import TuningRunMain
log = logging.getLogger(__name__)
parser = argparse.ArgumentParser(parents=opentuner.argparsers())
parser.add_argument('--size', type=int, default=800,
help='dimensions for the HPL matrix')
parser.add_argument('--nprocs', type=int, default=4,
help='number of processors for each HPL run (minimum=4)')
parser.add_argument('--xhpl', type=str, default="hpl-2.1/bin/OSX/xhpl",
help='location of xhpl binary')
class HPLinpack(MeasurementInterface):
def run(self, desired_result, input, limit):
self.output_hpl_datfile(desired_result.configuration.data)
import subprocess, os
binary = self.args.xhpl
subprocess.call(["mpirun", "-np", str(self.args.nprocs), binary])
val = self.get_time_from_hpl_output()
return opentuner.resultsdb.models.Result(time=val)
def manipulator(self):
#FIXME: should some of these be expressed as booleans or switch parameters?
#FIXME: how to express P and Q, given PxQ=nprocs, with nprocs being fixed?
#FIXME: how to express logscaled parameter with a particular base?
manipulator = ConfigurationManipulator()
manipulator.add_parameter(IntegerParameter("blocksize", 1, 64))
'fixed': generate_random_Ugoal_FIXED,
}
parser = argparse.ArgumentParser(parents=opentuner.argparsers())
parser.add_argument('--seq-len', type=int, default=10,
help='maximum length for generated sequence')
parser.add_argument('--goal-type', choices=list(generators.keys()), default='hard',
help='method used to generate goal')
parser.add_argument('--goal-n', type=int, default=100,
help='argument to ugoal generator')
parser.add_argument('--goal-alpha', type=float,
default=random.random() * math.pi,
help='argument to ugoal generator')
class Unitary(opentuner.measurement.MeasurementInterface):
def __init__(self, *pargs, **kwargs):
super(Unitary, self).__init__(*pargs, **kwargs)
self.op = cla_func.Op()
self.num_operators = len(self.op.M)
self.Ugoal = generators[args.goal_type](N=args.goal_n,
alpha=args.goal_alpha)
def run(self, desired_result, input, limit):
cfg = desired_result.configuration.data
sequence = [cfg[i] for i in range(self.args.seq_len)
if cfg[i] < self.num_operators]
# sequence can be shorter than self.args.seq_len with null operator
# '''
# cfg = self.manipulator.random()
# for k in cfg.keys():
# if re.match('.*_compute_level', k):
# cfg[k] = LoopLevel.INLINE
# return cfg
#
# technique.register(bandittechniques.AUCBanditMetaTechnique([
# HalideRandomConfig(),
# differentialevolution.DifferentialEvolutionAlt(),
# evolutionarytechniques.UniformGreedyMutation(),
# evolutionarytechniques.NormalGreedyMutation(mutation_rate=0.3),
# ], name = "HalideMetaTechnique"))
class HalideTuner(opentuner.measurement.MeasurementInterface):
def __init__(self, args):
# args.technique = ['HalideMetaTechnique']
super(HalideTuner, self).__init__(args, program_name=args.source)
timing_prefix = open(os.path.join(os.path.dirname(__file__),
'timing_prefix.h')).read()
self.template = timing_prefix + open(args.source).read()
self.min_collection_cost = float('inf')
if not args.settings_file:
args.settings_file = os.path.splitext(args.source)[0] + '.settings'
if not args.make_settings_file:
with open(args.settings_file) as fd:
self.settings = json.load(fd)
self.post_dominators = post_dominators(self.settings)
if not args.input_size:
args.input_size = self.settings['input_size']
else:
parser.add_argument('program',
help='PetaBricks binary program to autotune')
parser.add_argument('--program-cfg-default',
help="override default program config exemplar location")
parser.add_argument('--program-cfg-output',
help="location final autotuned configuration is written")
parser.add_argument('--program-settings',
help="override default program settings file location")
parser.add_argument('--program-input',
help="use only a given input for autotuning")
parser.add_argument('--upper-limit', type=float, default=30,
help="time limit to apply to initial test")
parser.add_argument('--test-config', action='store_true')
class PetaBricksInterface(MeasurementInterface):
def __init__(self, args):
self.program_settings = json.load(open(args.program_settings))
input_manager = FixedInputManager(size=self.program_settings['n'])
objective = ThresholdAccuracyMinimizeTime(self.program_settings['accuracy'])
# pass many settings to parent constructor
super(PetaBricksInterface, self).__init__(
args, program_name=args.program,
program_version=self.file_hash(args.program),
input_manager=input_manager, objective=objective)
def build_config(self, cfg):
r = dict()
# direct copy
for k, v in list(cfg.items()):
from opentuner.search.manipulator import ConfigurationManipulator
from opentuner.search.manipulator import FloatParameter
log = logging.getLogger(__name__)
parser = argparse.ArgumentParser(parents=opentuner.argparsers())
parser.add_argument('--dimensions', type=int, default=2,
help='dimensions for the Rosenbrock function')
parser.add_argument('--domain', type=float, default=1000,
help='bound for variables in each dimension')
parser.add_argument('--function', default='rosenbrock',
choices=('rosenbrock', 'sphere', 'beale'),
help='function to use')
class Rosenbrock(MeasurementInterface):
def run(self, desired_result, input, limit):
cfg = desired_result.configuration.data
val = 0.0
if self.args.function == 'rosenbrock':
# the actual rosenbrock function:
for d in range(self.args.dimensions - 1):
x0 = cfg[d]
x1 = cfg[d + 1]
val += 100.0 * (x1 - x0 ** 2) ** 2 + (x0 - 1) ** 2
elif self.args.function == 'sphere':
for d in range(self.args.dimensions):
xi = cfg[d]
val += xi ** 2
elif self.args.function == 'beale':
assert self.args.dimensions == 2
assert self.args.domain == 4.5