Ejemplo n.º 1
0
 def autotune(self):
   self.tuning_time -= time.time()
   tunerconfig.applypatch(tunerconfig.patch_pbbenchmark)
   tunerconfig.applypatch(tunerconfig.patch_n_offset(self.n))
   tunerconfig.applypatch(tunerconfig.patch_accuracy_target(self.acc_target))
   self.tuned_candidate=sgatuner.autotune(self.benchmark)
   tunerconfig.applypatch(tunerconfig.patch_reset)
   self.tuning_time += time.time()
Ejemplo n.º 2
0
 def autotune(self):
     self.tuning_time -= time.time()
     tunerconfig.applypatch(tunerconfig.patch_pbbenchmark)
     tunerconfig.applypatch(tunerconfig.patch_n_offset(self.n))
     tunerconfig.applypatch(
         tunerconfig.patch_accuracy_target(self.acc_target))
     self.tuned_candidate = sgatuner.autotune(self.benchmark)
     tunerconfig.applypatch(tunerconfig.patch_reset)
     self.tuning_time += time.time()
Ejemplo n.º 3
0
 def compileLearningHeuristics(self, benchmark, finalBinary=None):
   #Define file names
   path, basenameExt = os.path.split(benchmark)
   if path == "":
     path="./"
   basename, ext = os.path.splitext(basenameExt)
   basesubdir=os.path.join(path,basename+".tmp")
   #Init variables
   candidates=CandidateList()
   
   #Compile with current best heuristics
   outDir = os.path.join(basesubdir, "0")
   if not os.path.isdir(outDir):
     #Create the output directory
     os.makedirs(outDir)
   binary= os.path.join(outDir, basename)  
   status=pbutil.compileBenchmark(self.__pbcExe, benchmark, binary=binary, jobs=self.__jobs)  
   if status != 0:
     return status
     
   try:
     autotune(binary, candidates)
   except tunerwarnings.AlwaysCrashes:
       print "Current best Candidate always crashes!"
       #Add an empty entry for the candidate
       candidates.append(None)
   
   #Get the full set of heuristics used
   infoFile=binary+".info"
   currentBestHSet = HeuristicSet()
   currentBestHSet.importFromXml(xml.dom.minidom.parse(infoFile))
   neededHeuristics = currentBestHSet.keys()
   
   #Get hSets
   allHSets = self.__heuristicManager.allHeuristicSets()
   while len(allHSets) < (self.__minTrialNumber): #Not enough hSets!
     allHSets.append(HeuristicSet())
   
   numSets = len(allHSets)
   
   
   count=1
   for hSet in allHSets:
     hSet.complete(neededHeuristics, self.__db, conf_pickBestN)
     
     #Define more file names
     outDir = os.path.join(basesubdir, str(count))
     if not os.path.isdir(outDir):
       #Create the output directory
       os.makedirs(outDir)
     binary= os.path.join(outDir, basename)  
     
     heuristicsFile= os.path.join(outDir, "heuristics.txt")
     hSet.toXmlFile(heuristicsFile)
     
     status = pbutil.compileBenchmark(self.__pbcExe, benchmark, binary=binary, heuristics=heuristicsFile, jobs=self.__jobs)
     if status != 0:
       print "Compile FAILED"
       print "while using heuristics: "
       print hSet
       return status
     
     #Autotune
     try:
       autotune(binary, candidates)
     except tunerwarnings.AlwaysCrashes:
       print "Candidate "+str(count)+" always crashes!"
       #Add an empty entry for the candidate
       candidates.append(None)
     
     count = count + 1
     
   candidates.addOriginalIndex()
   candidates.sortBySpeed()
   
   if candidates[0] is None:
     raise tunerwarnings.AlwaysCrashes()
   
   self.storeCandidatesDataInDB(candidates, basesubdir, basename)
   
   bestIndex = candidates[0].originalIndex
   
   print "The best candidate is: "+str(bestIndex)
 
   #Move every file to the right place
   bestSubDir=os.path.join(basesubdir, str(bestIndex))
   #  compiled program:
   bestBin=os.path.join(bestSubDir, basename)
   if finalBinary is not None:
     finalBin=finalBinary
   else:
     finalBin=os.path.join(path, basename)
   shutil.move(bestBin, finalBin)
   #  .cfg file
   bestCfg=os.path.join(bestSubDir, basename+".cfg")
   finalCfg=finalBin + ".cfg"
   shutil.move(bestCfg, finalCfg)
   #  .info file
   bestInfo=os.path.join(bestSubDir, basename+".info")
   finalInfo=finalBin+".info"
   shutil.move(bestInfo, finalInfo)
   #  .obj directory
   bestObjDir=os.path.join(bestSubDir, basename+".obj")
   destObjDir=finalBin+".obj"
   if os.path.isdir(destObjDir):
     shutil.rmtree(destObjDir)
   shutil.move(bestObjDir, destObjDir)
   #  input heuristic file
   if bestIndex != 0: #Program 0 is run with only the best heuristics in the DB
     bestHeurFile=os.path.join(bestSubDir, "heuristics.txt")
     finalHeurFile=finalBin+".heur"
     shutil.move(bestHeurFile, finalHeurFile)
   
   #Delete all the rest
   if conf_deleteTempDir:
     shutil.rmtree(basesubdir)
   
   return 0