示例#1
0
 def __init__(self, cfg, mlog=list()):
   self.config         = ConfigFile(cfg)
   self.startconfig    = ConfigFile(deepcopy(self.config))
   self.metrics        = [ResultsDB(x) for x in config.metrics]
   self.cid            = Candidate.nextCandidateId
   self.outputdir      = storagedirs.candidate(self.cid)
   self.mutationlog    = list(mlog)
   Candidate.nextCandidateId += 1
示例#2
0
 def test(self, count):
   '''test each member of the pop count times'''
   if self.best is not None:
       print '------------------------------------------------'
       print 'Best schedule:'
       print self.hl_cfg.str(HalideConfigAccessor(ConfigFile(self.best.cfgfile())))
       print '------------------------------------------------'
   
   self.failed=set()
   tests = []
   for z in xrange(count):
     tests.extend(self.members)
   random.shuffle(tests)
   for m in tests:
     sgatuner.check_timeout()
     if m not in self.failed and m.numTests(self.inputSize())<config.max_trials:
       try:
         self.testers[-1].test(m)
       except candidatetester.CrashException, e:
         if m.numTotalTests()==0:
           warnings.warn(InitialProgramCrash(e))
         else:
           warnings.warn(ExistingProgramCrash(e))
         self.failed.add(m)
         self.members.remove(m)
示例#3
0
def main(benchmark, n, filename):
    if os.path.isdir(filename):
        filename = os.path.join(filename, 'stats/candidatelog.csv')
    f = open(filename)
    infoxml = TrainingInfo(pbutil.benchmarkToInfo(benchmark))
    main = mainname([pbutil.benchmarkToBin(benchmark)])
    infoxml = infoxml.transform(main)
    binpath = pbutil.benchmarkToBin(benchmark)
    tester = CandidateTester(benchmark, n)
    root = os.path.dirname(filename)

    def findconfig(c):
        if c[0] == '/':
            c = c[1:]
        if os.path.isfile(os.path.join(root, c)):
            return os.path.join(root, c)
        if os.path.isfile(os.path.join(root, '..', c)):
            return os.path.join(root, '..', c)
        return None

    rows = list(csv.DictReader(f))
    for i, row in enumerate(rows):
        if options.onlyrounds \
            and i+1<len(rows) \
            and row.has_key('round_number') \
            and rows[i+1]['round_number']==row['round_number']:
            continue
        config = findconfig(row['config_path'])
        row['tests'] = int(row['tests_complete']) + int(
            row['tests_timeout']) + int(row['tests_crashed'])
        candidate = Candidate(ConfigFile(config), infoxml)
        while candidate.numTests(n) < options.trials:
            try:
                tester.testN(candidate, options.trials, options.timeout)
            except candidatetester.CrashException, e:
                print >> sys.stderr, e
        try:
            row['minperf'] = candidate.metrics[0][n].min()
            row['perf_on_%d' % n], row['perf_on_%d_ci' %
                                       n] = candidate.metrics[0][n].interval(
                                           options.confidence)
            row['invperf'] = 1.0 / row['perf_on_%d' % n]
        except Exception, e:
            row['minperf'] = -1
            row['perf_on_%d' % n] = -1
            print >> sys.stderr, e
示例#4
0
 def test(self, candidate, limit=None):
     try:
         limit = TIMELIMIT
         
         self.testCount += 1
         cfgfile = candidate.cfgfile()
         testNumber = candidate.numTests(self.n)
         if testNumber>=config.max_trials:
             warnings.warn(tunerwarnings.TooManyTrials(testNumber+1))
 #    cmd = list(self.cmd)
 #    cmd.append("--config="+cfgfile)
 #    cmd.extend(timers.inputgen.wrap(lambda:self.getInputArg(testNumber)))
 #    if limit is not None:
 #      cmd.append("--max-sec=%f"%limit)
 #    cmd.extend(getMemoryLimitArgs())
         cfg = HalideConfigAccessor(ConfigFile(cfgfile))
         try:
             #results = timers.testing.wrap(lambda: runCommand(self.app, cfg, self.hl_cfg, limit))
             #for i,result in enumerate(results):
             #    if result is not None:
             #        v=result['average']
             #        if numpy.isnan(v) or numpy.isinf(v):
             #            warnings.warn(tunerwarnings.NanAccuracy())
             #            raise pbutil.TimingRunFailed(None)
             #        candidate.metrics[i][self.n].add(v)
             #return True
             T = runCommand(self.app, cfg, self.hl_cfg, limit, self.test_func, self.func_d, self.func, self.scope)
             #print 'succeeded'
             for timeval in T:
                 candidate.metrics[config.timing_metric_idx][self.n].add(timeval)
         except TimingRunTimeout:
             #assert limit is not None
             #warnings.warn(tunerwarnings.ProgramTimeout(candidate, self.n, limit))
             candidate.metrics[config.timing_metric_idx][self.n].addTimeout(limit)
             self.timeoutCount += 1
             return False
         except TimingRunFailed, e:
             self.crashCount += 1
             raise CrashException(testNumber, self.n, candidate, self.app)
     except:
         traceback.print_exc()
         raise