コード例 #1
0
 def clean():
     for paths, dirs, files in os.walk(os.path.abspath(os.curdir)):
         for filename in files:
             if re.match(r'%s[0-9]+\.txt' % new_filename_prefix, filename):
                 full_path = os.path.join(paths, filename)
                 debug.verbose_message("Removing '%s'" % full_path, __name__)
                 os.remove(full_path)
コード例 #2
0
ファイル: calculations.py プロジェクト: jiankangren/Projects
 def solve(self):
     with open(self._filename, 'w') as clpFile:
         for line in self._lines:
             clpFile.write(line)
     debug.debug_message("Solving CLP in %s" % self._filename, 10)
     command = 'jeclipse -b %s -e "%s."' % (self._filename, self.__goal)
     debug.verbose_message("Running command '%s'" % command, __name__)
     start = timeit.default_timer()
     proc = subprocess.Popen(command, shell=True, executable="/bin/bash")
     returnCode = proc.wait()
     self._solvingTime = (timeit.default_timer() - start)
     if returnCode != 0:
         debug.warning_message("Running '%s' failed" % command)
         return self._wcet, self._solvingTime
     else:
         with open(self._filename + '.res') as f:
             for line in f:
                 if re.match(r'%s' % CLP.WCET, line):
                     values = re.findall(r'[0-9]+', line)
                     assert len(
                         values
                     ) == 1, "Unable to find WCET value in CLP output file"
                     self._wcet = int(values[0])
     assert self._wcet
     assert self._solvingTime
     return self._wcet, self._solvingTime
コード例 #3
0
ファイル: calculations.py プロジェクト: abetts155/WCET
 def __init__ (self, program, data):
     self.__VanillaContextIDToWCET = {}
     self.__ExtraContextIDToWCET = {}
     contextg = program.getContextGraph()
     dfs      = directed_graphs.DepthFirstSearch(contextg, contextg.getRootID())
     for vertexID in dfs.getPostorder():
         contextv     = contextg.getVertex(vertexID)
         functionName = contextv.getName()
         pathg        = program.getPathInfoGraph(functionName)
         if pathg.isExecutedFunction():
             debug.verbose_message("Doing WCET calculation on %s" % functionName, __name__)
             lnt   = program.getLNT(functionName)
             cfg   = program.getCFG(functionName)
             ilp1  = CreateCFGILPVanilla(data, self.__VanillaContextIDToWCET, contextv, cfg, lnt, pathg)
             ilp1WCET, ilp1SolvingTime = ilp1.solve()
             debug.verbose_message("ILP(vanilla):: WCET(%s)=%s (SOLVE TIME=%.5f)" % (functionName, ilp1WCET, ilp1SolvingTime), __name__)
             self.__VanillaContextIDToWCET[contextv.vertexID] = ilp1WCET
             if not pathg.executionDependencies() and not pathg.mutualInclusionPairs() and not pathg.mutualExclusionPairs():
                 ilp2 = CreateCFGILPExtra(data, self.__ExtraContextIDToWCET, contextv, cfg, lnt, pathg)
                 ilp2WCET, ilp2SolvingTime = ilp2.solve()
                 self.__ExtraContextIDToWCET[contextv.vertexID] = ilp2WCET
                 debug.verbose_message("ILP(extra):: WCET(%s)=%s (SOLVE TIME=%.5f)" % (functionName, ilp2WCET, ilp2SolvingTime), __name__)
             else:
                 clp2 = CreateCFGCLPExtra(data, self.__ExtraContextIDToWCET, contextv, cfg, lnt, pathg)
                 clp2WCET, clp2SolvingTime = clp2.solve()
                 self.__ExtraContextIDToWCET[contextv.vertexID] = clp2WCET
                 debug.verbose_message("CLP(extra):: WCET(%s)=%s (SOLVE TIME=%.5f)" % (functionName, clp2WCET, clp2SolvingTime), __name__)
         else:
             debug.verbose_message("%s did not execute" % functionName, __name__)
             self.__VanillaContextIDToWCET[contextv.vertexID] = 0
             self.__ExtraContextIDToWCET[contextv.vertexID] = 0
コード例 #4
0
ファイル: individual.py プロジェクト: carpproject/autotuner
 def binary(self):
     time_regex = re.compile(r'^(\d*\.\d+|\d+)$')
     total_time = 0.0
     status     = enums.Status.passed
     for run in xrange(1,config.Arguments.runs+1):
         debug.verbose_message("Run #%d of '%s'" % (run, config.Arguments.run_cmd), __name__)
         start = timeit.default_timer()
         proc  = subprocess.Popen(config.Arguments.run_cmd, shell=True, stdout=subprocess.PIPE)    
         stdout, stderr = proc.communicate()
         end   = timeit.default_timer()
         if proc.returncode:
             status = enums.Status.failed
             debug.warning_message("FAILED: '%s'" % config.Arguments.run_cmd)
             continue
         if config.Arguments.execution_time_from_binary:
             if not stdout:
                 raise internal_exceptions.BinaryRunException("Expected the binary to dump its execution time. Found nothing")
             for line in stdout.split(os.linesep):
                 line    = line.strip()
                 matches = time_regex.findall(line)
                 if matches:
                     try:
                         total_time += float(matches[0])
                     except:
                         raise internal_exceptions.BinaryRunException("Execution time '%s' is not in the required format" % matches[0])
         else:
             total_time += end - start
     self.status = status
     config.time_binary += total_time
     self.execution_time = total_time/config.Arguments.runs
コード例 #5
0
ファイル: main.py プロジェクト: abetts155/WCET
 def clean():
     for paths, dirs, files in os.walk(os.path.abspath(os.curdir)):
         files.sort()
         for filename in files:
             if filename.endswith('.udraw') or filename.endswith('.ilp'):
                 full_path = os.path.join(paths, filename)
                 debug.verbose_message("Removing '%s'" % full_path, __name__)
                 os.remove(full_path)
コード例 #6
0
 def clean():
     for paths, dirs, files in os.walk(os.path.abspath(os.curdir)):
         for filename in files:
             if re.match(r'%s[0-9]+\.txt' % new_filename_prefix, filename):
                 full_path = os.path.join(paths, filename)
                 debug.verbose_message("Removing '%s'" % full_path,
                                       __name__)
                 os.remove(full_path)
コード例 #7
0
def run_compiler(the_cmd):  
    debug.verbose_message("Running '%s'" % the_cmd, __name__)
    start = timeit.default_timer()
    proc  = subprocess.Popen(the_cmd, shell=True, stderr=subprocess.PIPE)    
    end   = timeit.default_timer() 
    config.time_VOBLA += end - start
    if proc.wait():
        raise internal_exceptions.FailedCompilationException("FAILED: '%s'" % the_cmd) 
コード例 #8
0
ファイル: individual.py プロジェクト: carpproject/autotuner
 def build(self):
     debug.verbose_message("Running '%s'" % config.Arguments.build_cmd, __name__)
     start  = timeit.default_timer()
     proc   = subprocess.Popen(config.Arguments.build_cmd, shell=True)  
     stderr = proc.communicate()[1]     
     end    = timeit.default_timer()
     config.time_backend += end - start
     if proc.returncode:
         raise internal_exceptions.FailedCompilationException("FAILED: '%s'" % config.Arguments.build_cmd)
コード例 #9
0
 def clean():
     for paths, dirs, files in os.walk(os.path.abspath(os.curdir)):
         files.sort()
         for filename in files:
             if filename.endswith('.udraw') or filename.endswith('.ilp'):
                 full_path = os.path.join(paths, filename)
                 debug.verbose_message("Removing '%s'" % full_path,
                                       __name__)
                 os.remove(full_path)
コード例 #10
0
ファイル: traces.py プロジェクト: abetts155/WCET
 def __init__ (self, program, traceFiles):
     debug.verbose_message("Parsing gem5 traces", __name__)
     TraceInformation.__init__(self, program)
     self.__initialise()
     self.__parse(traceFiles)
     self._end()
     self._normaliseData()
     self._outputConjectures()
     self._outputCBMCConjectures()
コード例 #11
0
ファイル: traces.py プロジェクト: jiankangren/Projects
 def __init__(self, program, traceFiles):
     debug.verbose_message("Parsing gem5 traces", __name__)
     TraceInformation.__init__(self, program)
     self.__initialise()
     self.__parse(traceFiles)
     self._end()
     self._normaliseData()
     self._outputConjectures()
     self._outputCBMCConjectures()
コード例 #12
0
ファイル: tool_Gem5.py プロジェクト: abetts155/WCET
def disassemble_program(binary):
    debug.verbose_message("Disassembling program", __name__)
    disassembly_filename = binary + ".dis"
    with open(disassembly_filename, "w") as disassembly:
        cmd = "%s %s -d" % (config.Arguments.objdump, binary)
        proc = subprocess.Popen(cmd, shell=True, stdout=disassembly, stderr=sys.stderr)
        returncode = proc.wait()
        if returncode:
            debug.exit_message("Disassembling '%s' failed" % binary)
    return disassembly_filename
コード例 #13
0
ファイル: individual.py プロジェクト: carpproject/autotuner
 def run(self):
     try:
         self.compile()
         if self.status == enums.Status.passed:
             # Fitness is inversely proportional to execution time
             self.fitness = 1/self.execution_time 
             debug.verbose_message("Individual %d: execution time = %f, fitness = %f" \
                                   % (self.ID, self.execution_time, self.fitness), __name__) 
         else:
             self.fitness = 0
     except internal_exceptions.FailedCompilationException as e:
         debug.exit_message(e)
コード例 #14
0
ファイル: tool_Gem5.py プロジェクト: jiankangren/Projects
def disassemble_program(binary):
    debug.verbose_message("Disassembling program", __name__)
    disassembly_filename = binary + ".dis"
    with open(disassembly_filename, 'w') as disassembly:
        cmd = "%s %s -d" % (config.Arguments.objdump, binary)
        proc = subprocess.Popen(cmd,
                                shell=True,
                                stdout=disassembly,
                                stderr=sys.stderr)
        returncode = proc.wait()
        if returncode:
            debug.exit_message("Disassembling '%s' failed" % binary)
    return disassembly_filename
コード例 #15
0
 def do_mutation(self, child):
     debug.verbose_message("Mutating child %d" % child.ID, __name__)
     for flag in child.ppcg_flags.keys():   
         if bool(random.getrandbits(1)):
             child.ppcg_flags[flag] = flag.random_value()
     for flag in child.cc_flags.keys():    
         if bool(random.getrandbits(1)):
             child.cc_flags[flag] = flag.random_value()
     for flag in child.cxx_flags.keys():    
         if bool(random.getrandbits(1)):
             child.cxx_flags[flag] = flag.random_value()
     for flag in child.nvcc_flags.keys():    
         if bool(random.getrandbits(1)):
             child.nvcc_flags[flag] = flag.random_value()
コード例 #16
0
ファイル: traces.py プロジェクト: abetts155/WCET
    def _end (self):
        for cfg in self._program.getcfgs():
            functionName = cfg.getName()
            pathg        = self._program.getPathInfoGraph(functionName)            
            debug.verbose_message(
"""%s
FUNCTION '%s'
%s""" \
% ('*' * 100, functionName, '*' * 100), __name__)
            for vertexID1, vertexID2 in pathg.mutualInclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                succe1 = v1.getSuccessoredges(edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                succe2 = v2.getSuccessoredges(edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                if succe1.lower > 0 and succe2.lower > 0:
                    debug.verbose_message("  IGNORING MUTUAL INCLUSION: %s and %s" % (v1.__str__(), v2.__str__()), __name__)
                    v1.removeSuccessorEdge(vertexID2, edges.PathInformationEdgeType.INCLUSION)
                    v2.removeSuccessorEdge(vertexID1, edges.PathInformationEdgeType.INCLUSION)
            
            for v in pathg:
                vertexID = v.vertexID
                succe = v.getSuccessoredges(edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                if succe.lower == 0 and succe.upper == 0:
                    for succe in v.getSuccessoredges(edges.PathInformationEdgeType.INCLUSION):
                        succID = succe.vertexID
                        succv  = pathg.getVertex(succID)
                        succv.removeSuccessorEdge(vertexID, edges.PathInformationEdgeType.INCLUSION)
                        debug.verbose_message("  IGNORING MUTUAL INCLUSION BECAUSE OF DEAD CODE: %s and %s" % (v.__str__(), succv.__str__()), __name__)
                    for succe in v.getSuccessoredges(edges.PathInformationEdgeType.EXCLUSION):
                        succID = succe.vertexID
                        succv  = pathg.getVertex(succID)
                        succv.removeSuccessorEdge(vertexID, edges.PathInformationEdgeType.EXCLUSION)
                        debug.verbose_message("  IGNORING MUTUAL EXCLUSION BECAUSE OF DEAD CODE: %s and %s" % (v.__str__(), succv.__str__()), __name__)
                    v.removeAllSuccessors()
コード例 #17
0
ファイル: individual.py プロジェクト: carpproject/autotuner
 def ppcg(self):
     self.ppcg_cmd_line_flags = "--target=%s --dump-sizes %s" % (config.Arguments.target, 
                                                                 ' '.join(flag.get_command_line_string(self.ppcg_flags[flag]) for flag in self.ppcg_flags.keys()))
     
     os.environ["AUTOTUNER_PPCG_FLAGS"] = self.ppcg_cmd_line_flags
     debug.verbose_message("Running '%s'" % config.Arguments.ppcg_cmd, __name__)
     start  = timeit.default_timer()
     proc   = subprocess.Popen(config.Arguments.ppcg_cmd, shell=True, stderr=subprocess.PIPE)  
     stderr = proc.communicate()[1]
     end    = timeit.default_timer()
     config.time_PPCG += end - start
     if proc.returncode:
         raise internal_exceptions.FailedCompilationException("FAILED: '%s'" % config.Arguments.ppcg_cmd)         
     # Store the sizes used by PPCG
     self.size_data = compiler_flags.SizesFlag.parse_PPCG_dump_sizes(stderr)
コード例 #18
0
 def run(self):        
     self.generations      = collections.OrderedDict()  
     self.total_mutations  = 0
     self.total_crossovers = 0
     
     state_random_population = "random_population"
     state_basic_evolution   = "basic_evolution"
     state_sizes_evolution   = "sizes_evolution"        
     current_state           = state_random_population
     legal_transitions       = set()
     legal_transitions.add((state_random_population, state_basic_evolution))
     legal_transitions.add((state_basic_evolution, state_sizes_evolution))
     legal_transitions.add((state_basic_evolution, state_basic_evolution))
     legal_transitions.add((state_sizes_evolution, state_basic_evolution))
     
     for generation in xrange(1, config.Arguments.generations+1):
         debug.verbose_message("%s Creating generation %d %s" % ('+' * 10, generation, '+' * 10), __name__)
         if current_state == state_random_population:
             self.generations[generation] = self.create_initial()
             next_state = state_basic_evolution
         elif current_state == state_basic_evolution:
             old_population = self.generations[generation-1]
             self.generations[generation] = self.do_evolution(old_population)
             next_state = state_basic_evolution
         elif current_state == state_sizes_evolution:
             debug.verbose_message("Now tuning individual kernel sizes", __name__)
             the_sizes_flag = compiler_flags.PPCG.flag_map[compiler_flags.PPCG.sizes]
             old_population = self.generations[generation-1]
             for individual in old_population:
                 individual.ppcg_flags[the_sizes_flag] = individual.size_data
             self.generations[generation] = self.do_evolution(old_population)
             legal_transitions.remove((state_basic_evolution, state_sizes_evolution))
             next_state = state_basic_evolution
         else:
             assert False, "Unknown state reached"
         
         # Generation created, now calculate the fitness of each individual
         for solution in self.generations[generation]:
             solution.run()
             
         if current_state == state_basic_evolution:
             # Decide whether to start tuning on individual kernel sizes in the next state
             if not config.Arguments.no_tune_kernel_sizes \
             and (state_basic_evolution, state_sizes_evolution) in legal_transitions \
             and bool(random.getrandbits(1)):
                 next_state = state_sizes_evolution
                 
         current_state = next_state
コード例 #19
0
ファイル: tool_Gem5.py プロジェクト: abetts155/WCET
def do_analysis(program):
    time1 = timing.log("TRACE PARSING RUN #1 (NO INLINING)")
    data = traces.Gem5Parser(program, config.Arguments.gem5_traces)
    debug.verbose_message("HWMT = %d" % data.getLongestTime(), __name__)
    calculations.WCETCalculation(program, data)
    program.output()
    program.generateAllUDrawFiles()

    if program.getCallGraph().numOfvertices() > 1 and config.Arguments.inline:
        program.inlineCalls()
        time2 = timing.log("TRACE PARSING RUN #2 (INLINED PROGRAM)")
        data = traces.Gem5Parser(program, config.Arguments.gem5_traces)
        debug.verbose_message("HWMT = %d" % data.getLongestTime(), __name__)
        calculations.WCETCalculation(program, data)
        program.output()
        program.generateAllUDrawFiles("inlined")
コード例 #20
0
ファイル: tool_Gem5.py プロジェクト: jiankangren/Projects
def do_analysis(program):
    time1 = timing.log("TRACE PARSING RUN #1 (NO INLINING)")
    data = traces.Gem5Parser(program, config.Arguments.gem5_traces)
    debug.verbose_message("HWMT = %d" % data.getLongestTime(), __name__)
    calculations.WCETCalculation(program, data)
    program.output()
    program.generateAllUDrawFiles()

    if program.getCallGraph().numOfvertices() > 1 and config.Arguments.inline:
        program.inlineCalls()
        time2 = timing.log("TRACE PARSING RUN #2 (INLINED PROGRAM)")
        data = traces.Gem5Parser(program, config.Arguments.gem5_traces)
        debug.verbose_message("HWMT = %d" % data.getLongestTime(), __name__)
        calculations.WCETCalculation(program, data)
        program.output()
        program.generateAllUDrawFiles("inlined")
コード例 #21
0
ファイル: tool_Gem5.py プロジェクト: abetts155/WCET
def compile_program(program):
    debug.verbose_message("Compiling program", __name__)
    optimisation = ""
    extraFlags = ""
    if config.Arguments.flags:
        for flag in config.Arguments.flags:
            extraFlags += "-%s " % flag
            if re.match(r"O[0-3]+", flag):
                optimisation = flag
    binary = program[:-2] + optimisation
    cmd = "%s -fno-stack-protector -static %s %s -o %s" % (config.Arguments.GCC, extraFlags, program, binary)
    debug.debug_message("Compiling with command '%s'" % cmd, 1)
    proc = subprocess.Popen(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
    returncode = proc.wait()
    if returncode:
        debug.exit_message("Compiling '%s' with '%s' failed" % (program, cmd))
    return binary
コード例 #22
0
ファイル: calculations.py プロジェクト: jiankangren/Projects
 def __init__(self, program, data):
     self.__VanillaContextIDToWCET = {}
     self.__ExtraContextIDToWCET = {}
     contextg = program.getContextGraph()
     dfs = directed_graphs.DepthFirstSearch(contextg, contextg.getRootID())
     for vertexID in dfs.getPostorder():
         contextv = contextg.getVertex(vertexID)
         functionName = contextv.getName()
         pathg = program.getPathInfoGraph(functionName)
         if pathg.isExecutedFunction():
             debug.verbose_message(
                 "Doing WCET calculation on %s" % functionName, __name__)
             lnt = program.getLNT(functionName)
             cfg = program.getCFG(functionName)
             ilp1 = CreateCFGILPVanilla(data, self.__VanillaContextIDToWCET,
                                        contextv, cfg, lnt, pathg)
             ilp1WCET, ilp1SolvingTime = ilp1.solve()
             debug.verbose_message(
                 "ILP(vanilla):: WCET(%s)=%s (SOLVE TIME=%.5f)" %
                 (functionName, ilp1WCET, ilp1SolvingTime), __name__)
             self.__VanillaContextIDToWCET[contextv.vertexID] = ilp1WCET
             if not pathg.executionDependencies(
             ) and not pathg.mutualInclusionPairs(
             ) and not pathg.mutualExclusionPairs():
                 ilp2 = CreateCFGILPExtra(data, self.__ExtraContextIDToWCET,
                                          contextv, cfg, lnt, pathg)
                 ilp2WCET, ilp2SolvingTime = ilp2.solve()
                 self.__ExtraContextIDToWCET[contextv.vertexID] = ilp2WCET
                 debug.verbose_message(
                     "ILP(extra):: WCET(%s)=%s (SOLVE TIME=%.5f)" %
                     (functionName, ilp2WCET, ilp2SolvingTime), __name__)
             else:
                 clp2 = CreateCFGCLPExtra(data, self.__ExtraContextIDToWCET,
                                          contextv, cfg, lnt, pathg)
                 clp2WCET, clp2SolvingTime = clp2.solve()
                 self.__ExtraContextIDToWCET[contextv.vertexID] = clp2WCET
                 debug.verbose_message(
                     "CLP(extra):: WCET(%s)=%s (SOLVE TIME=%.5f)" %
                     (functionName, clp2WCET, clp2SolvingTime), __name__)
         else:
             debug.verbose_message("%s did not execute" % functionName,
                                   __name__)
             self.__VanillaContextIDToWCET[contextv.vertexID] = 0
             self.__ExtraContextIDToWCET[contextv.vertexID] = 0
コード例 #23
0
ファイル: programs.py プロジェクト: jiankangren/Projects
 def inline_calls(self):
     debug.verbose_message("Inlining to create single CFG", __name__)
     rootv = self.callg.getVertex(self.callg.rootID)
     dfs   = directed_graphs.DepthFirstSearch(self.callg, rootv.vertexID)
     for vertexID in dfs.post_order:
         succv = self.callg.getVertex(vertexID)
         for calle in succv.predecessors.values():
             predv = self.callg.getVertex(calle.vertexID)
             for call_siteID in calle.getCallSites():
                 debug.debug_message("Inlining '%s' into '%s' at call site %d" % (succv.name, predv.name, call_siteID), 1)
                 self.__doInline(self.cfgs[predv.name], self.cfgs[succv.name], call_siteID)
                 self.cfgs[succv.name].remove_call_site(call_siteID)
     for vertexID in dfs.post_order:
         callv = self.callg.getVertex(vertexID)
         if callv != rootv:
             self.remove_function(callv.name)
         else:
             cfg = self.cfgs[rootv.name]
             cfg.addEdge(cfg.get_exitID(), cfg.get_entryID())
コード例 #24
0
ファイル: tool_Gem5.py プロジェクト: jiankangren/Projects
def compile_program(program):
    debug.verbose_message("Compiling program", __name__)
    optimisation = ""
    extraFlags = ""
    if config.Arguments.flags:
        for flag in config.Arguments.flags:
            extraFlags += "-%s " % flag
            if re.match(r'O[0-3]+', flag):
                optimisation = flag
    binary = program[:-2] + optimisation
    cmd = "%s -fno-stack-protector -static %s %s -o %s" % (
        config.Arguments.GCC, extraFlags, program, binary)
    debug.debug_message("Compiling with command '%s'" % cmd, 1)
    proc = subprocess.Popen(cmd,
                            shell=True,
                            stdout=sys.stdout,
                            stderr=sys.stderr)
    returncode = proc.wait()
    if returncode:
        debug.exit_message("Compiling '%s' with '%s' failed" % (program, cmd))
    return binary
コード例 #25
0
ファイル: traces.py プロジェクト: jiankangren/Projects
    def _end(self):
        for cfg in self._program.getcfgs():
            functionName = cfg.getName()
            pathg = self._program.getPathInfoGraph(functionName)
            debug.verbose_message(
                """%s
FUNCTION '%s'
%s""" \
% ('*' * 100, functionName, '*' * 100), __name__)
            for vertexID1, vertexID2 in pathg.mutualInclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                succe1 = v1.getSuccessoredges(
                    edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                succe2 = v2.getSuccessoredges(
                    edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                if succe1.lower > 0 and succe2.lower > 0:
                    debug.verbose_message(
                        "  IGNORING MUTUAL INCLUSION: %s and %s" %
                        (v1.__str__(), v2.__str__()), __name__)
                    v1.removeSuccessorEdge(
                        vertexID2, edges.PathInformationEdgeType.INCLUSION)
                    v2.removeSuccessorEdge(
                        vertexID1, edges.PathInformationEdgeType.INCLUSION)

            for v in pathg:
                vertexID = v.vertexID
                succe = v.getSuccessoredges(
                    edges.PathInformationEdgeType.CAPACITY_BOUNDS)[0]
                if succe.lower == 0 and succe.upper == 0:
                    for succe in v.getSuccessoredges(
                            edges.PathInformationEdgeType.INCLUSION):
                        succID = succe.vertexID
                        succv = pathg.getVertex(succID)
                        succv.removeSuccessorEdge(
                            vertexID, edges.PathInformationEdgeType.INCLUSION)
                        debug.verbose_message(
                            "  IGNORING MUTUAL INCLUSION BECAUSE OF DEAD CODE: %s and %s"
                            % (v.__str__(), succv.__str__()), __name__)
                    for succe in v.getSuccessoredges(
                            edges.PathInformationEdgeType.EXCLUSION):
                        succID = succe.vertexID
                        succv = pathg.getVertex(succID)
                        succv.removeSuccessorEdge(
                            vertexID, edges.PathInformationEdgeType.EXCLUSION)
                        debug.verbose_message(
                            "  IGNORING MUTUAL EXCLUSION BECAUSE OF DEAD CODE: %s and %s"
                            % (v.__str__(), succv.__str__()), __name__)
                    v.removeAllSuccessors()
コード例 #26
0
ファイル: calculations.py プロジェクト: abetts155/WCET
 def solve (self):
     with open(self._filename, 'w') as clpFile:
         for line in self._lines:
             clpFile.write(line)          
     debug.debug_message("Solving CLP in %s" % self._filename, 10)
     command    = 'jeclipse -b %s -e "%s."' % (self._filename, self.__goal) 
     debug.verbose_message("Running command '%s'" % command, __name__)
     start = timeit.default_timer()
     proc       = subprocess.Popen(command, shell=True, executable="/bin/bash")
     returnCode = proc.wait()
     self._solvingTime = (timeit.default_timer() - start)
     if returnCode != 0:
         debug.warning_message("Running '%s' failed" % command)
         return self._wcet, self._solvingTime
     else:
         with open(self._filename + '.res') as f:
             for line in f:
                 if re.match(r'%s' % CLP.WCET, line):
                     values = re.findall(r'[0-9]+', line)
                     assert len(values) == 1, "Unable to find WCET value in CLP output file"
                     self._wcet = int(values[0])
     assert self._wcet
     assert self._solvingTime
     return self._wcet, self._solvingTime
コード例 #27
0
 def run(self):        
     debug.verbose_message("Creating initial solution", __name__)
     current = individual.create_random()
     current.run()   
     self.fittest = current
     
     temperature = config.Arguments.initial_temperature
     for i in range(1, config.Arguments.cooling_steps+1):
         debug.verbose_message("Cooling step %d" % i, __name__)
         temperature *= config.Arguments.cooling
         for j in range(1, config.Arguments.temperature_steps+1):
             debug.verbose_message("Temperature step %d" % j, __name__)
             new = self.mutate(current)
             new.run()       
             if new.status == enums.Status.passed:     
                 if self.acceptance_probability(current.execution_time, new.execution_time, temperature):
                     current = new
                 if current.execution_time < self.fittest.execution_time:
                     self.fittest = current
コード例 #28
0
ファイル: tool_Gem5.py プロジェクト: abetts155/WCET
        debug.exit_message(
            "The first command-line argument must be a file: '%s' is not a file" % config.Arguments.program_file
        )

    config.Arguments.test_specification_file = os.path.splitext(config.Arguments.program_file)[0] + ".test"
    if not os.path.exists(config.Arguments.test_specification_file):
        debug.exit_message(
            "Expected to find the test specification file '%s' but it is not there"
            % config.Arguments.test_specification_file
        )


if __name__ == "__main__":
    the_command_line()
    debug.verbose_message(
        "%s Analysing program '%s' %s" % ("*" * 10, config.Arguments.program_file, "*" * 10), __name__
    )
    time1 = timing.log("COMPILING BEGIN")
    binary, program = get_binary_and_program()
    time2 = timing.log("COMPILING END")
    if config.Arguments.compile:
        debug.exit_message("DONE")
    if config.Arguments.gem5_traces:
        check_trace_files()
    else:
        set_gem5_variables()
        if config.Arguments.ga:
            debug.verbose_message("Using GA to generate test vectors", __name__)
            config.Arguments.gem5_traces.extend(testing.runGAGem5(binary))
        else:
            debug.verbose_message("Running program on gem5 with %d tests" % config.Arguments.tests, __name__)
コード例 #29
0
ファイル: programs.py プロジェクト: jiankangren/Projects
 def output(self):
     totalMutualExclusion = 0
     totalMutualInclusion = 0
     totalDependencies    = 0
     totalNever           = 0
     totalAlways          = 0        
     for function_name, cfg in self.cfgs.iteritems():
         pathg                = self.getPathInfoGraph(function_name)
         mutualExclusionPairs = len(pathg.mutualExclusionPairs())
         mutualInclusionPairs = len(pathg.mutualInclusionPairs())
         dependencies         = len(pathg.executionDependencies())
         neverExecute         = pathg.numOfNeverExecuteedges()
         alwaysExecute        = pathg.numOfAlwaysExecuteedges()
         totalMutualExclusion += mutualExclusionPairs
         totalMutualInclusion += mutualInclusionPairs
         totalDependencies    += dependencies
         totalNever           += neverExecute
         totalAlways          += alwaysExecute
         debug.verbose_message("In %s..." % function_name, __name__)
         debug.verbose_message("...#CFG edges              = %d" % cfg.numOfedges(), __name__)
         debug.verbose_message("...#monitored              = %d" % pathg.numOfvertices(), __name__)
         debug.verbose_message("...#mutual exclusion pairs = %d" % mutualExclusionPairs, __name__)
         debug.verbose_message("...#mutual inclusion pairs = %d" % mutualInclusionPairs, __name__)
         debug.verbose_message("...#execution dependencies = %d" % dependencies, __name__)
         debug.verbose_message("...#never execute          = %d" % neverExecute, __name__)
         debug.verbose_message("...#always execute         = %d" % alwaysExecute, __name__)
     debug.verbose_message("...#TOTAL mutual exclusion pairs = %d" % totalMutualExclusion, __name__)
     debug.verbose_message("...#TOTAL mutual inclusion pairs = %d" % totalMutualInclusion, __name__)
     debug.verbose_message("...#TOTAL execution dependencies = %d" % totalDependencies, __name__)
     debug.verbose_message("...#TOTAL never execute          = %d" % totalAlways, __name__)
     debug.verbose_message("...#TOTAL always execute         = %d" % totalAlways, __name__)
コード例 #30
0
ファイル: tool_Gem5.py プロジェクト: jiankangren/Projects
        debug.exit_message(
            "The first command-line argument must be a file: '%s' is not a file"
            % config.Arguments.program_file)

    config.Arguments.test_specification_file = os.path.splitext(
        config.Arguments.program_file)[0] + '.test'
    if not os.path.exists(config.Arguments.test_specification_file):
        debug.exit_message(
            "Expected to find the test specification file '%s' but it is not there"
            % config.Arguments.test_specification_file)


if __name__ == "__main__":
    the_command_line()
    debug.verbose_message(
        "%s Analysing program '%s' %s" %
        ('*' * 10, config.Arguments.program_file, '*' * 10), __name__)
    time1 = timing.log("COMPILING BEGIN")
    binary, program = get_binary_and_program()
    time2 = timing.log("COMPILING END")
    if config.Arguments.compile:
        debug.exit_message("DONE")
    if config.Arguments.gem5_traces:
        check_trace_files()
    else:
        set_gem5_variables()
        if config.Arguments.ga:
            debug.verbose_message("Using GA to generate test vectors",
                                  __name__)
            config.Arguments.gem5_traces.extend(testing.runGAGem5(binary))
        else:
コード例 #31
0
ファイル: traces.py プロジェクト: abetts155/WCET
    def _outputConjectures (self): 
        for cfg in self._program.getcfgs():
            functionName = cfg.getName()
            pathg        = self._program.getPathInfoGraph(functionName)
            debug.verbose_message(
"""%s
FUNCTION '%s'
%s""" \
% ('*' * 100, functionName, '*' * 100), __name__)
            
            for v in pathg:
                for succe in v.getSuccessoredges(edges.PathInformationEdgeType.CAPACITY_BOUNDS):
                    if succe.lower == 0 and succe.upper == 0:
                        debug.verbose_message("  NEVER EXECUTES: %s" % (v.__str__(),), __name__)
                    elif succe.lower > 0:
                        debug.verbose_message("  ALWAYS EXECUTES: %s, at least %d time(s), at most %d time(s)" % (v.__str__(), succe.lower, succe.upper), __name__)
                    else:
                        debug.verbose_message("  MAY EXECUTE: %s, at most %d time(s)" % (v.__str__(), succe.upper), __name__)
                    
            
            debug.verbose_message(
"""%s
DEPENDENT EXECUTION CONJECTURES
%s""" \
    % ('-' * 50, '-' * 50), __name__)
            for vertexID1, vertexID2 in pathg.mutualInclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message("  MUTUALLY INCLUSIVE: %s and %s" % (v1.__str__(), v2.__str__()), __name__)
            for vertexID1, vertexID2 in pathg.mutualExclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message("  MUTUALLY EXCLUSIVE: %s and %s" % (v1.__str__(), v2.__str__()), __name__)
            for vertexID1, vertexID2 in pathg.executionDependencies():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message("  ONE-WAY DEPENDENCY: %s on %s" % (v1.__str__(), v2.__str__()), __name__)
コード例 #32
0
ファイル: traces.py プロジェクト: jiankangren/Projects
    def _outputConjectures(self):
        for cfg in self._program.getcfgs():
            functionName = cfg.getName()
            pathg = self._program.getPathInfoGraph(functionName)
            debug.verbose_message(
                """%s
FUNCTION '%s'
%s""" \
% ('*' * 100, functionName, '*' * 100), __name__)

            for v in pathg:
                for succe in v.getSuccessoredges(
                        edges.PathInformationEdgeType.CAPACITY_BOUNDS):
                    if succe.lower == 0 and succe.upper == 0:
                        debug.verbose_message(
                            "  NEVER EXECUTES: %s" % (v.__str__(), ), __name__)
                    elif succe.lower > 0:
                        debug.verbose_message(
                            "  ALWAYS EXECUTES: %s, at least %d time(s), at most %d time(s)"
                            % (v.__str__(), succe.lower, succe.upper),
                            __name__)
                    else:
                        debug.verbose_message(
                            "  MAY EXECUTE: %s, at most %d time(s)" %
                            (v.__str__(), succe.upper), __name__)


            debug.verbose_message(
                """%s
DEPENDENT EXECUTION CONJECTURES
%s""" \
    % ('-' * 50, '-' * 50), __name__)
            for vertexID1, vertexID2 in pathg.mutualInclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message(
                    "  MUTUALLY INCLUSIVE: %s and %s" %
                    (v1.__str__(), v2.__str__()), __name__)
            for vertexID1, vertexID2 in pathg.mutualExclusionPairs():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message(
                    "  MUTUALLY EXCLUSIVE: %s and %s" %
                    (v1.__str__(), v2.__str__()), __name__)
            for vertexID1, vertexID2 in pathg.executionDependencies():
                v1 = pathg.getVertex(vertexID1)
                v2 = pathg.getVertex(vertexID2)
                debug.verbose_message(
                    "  ONE-WAY DEPENDENCY: %s on %s" %
                    (v1.__str__(), v2.__str__()), __name__)
コード例 #33
0
def create_main(pencil_info):
    debug.verbose_message("Create AST for function 'main'", __name__)
    
    # The statements in "main"
    main_stmts = []
    
    # Initialise the pseudo-random number generator
    ast_time_param = c_ast.Constant("int", "0") 
    ast_time_call  = c_ast.FuncCall(c_ast.ID("time"), c_ast.ExprList([ast_time_param]))
    ast_srand_call = c_ast.FuncCall(c_ast.ID("srand"), c_ast.ExprList([ast_time_call]));
    main_stmts.append(ast_srand_call);
    
    # Create local variable declarations matching those in the
    # formal parameter list of each function.
    # Each scalar is initialised using the value selected
    for function_name in pencil_info.functions.keys():
        for formal_param in pencil_info.get_formal_params(function_name):
            ast_local_decl = copy.deepcopy(formal_param)
            if isinstance(formal_param.type, c_ast.TypeDecl):
                if isinstance(formal_param.type.type, c_ast.IdentifierType):
                    ast_local_decl.init = c_ast.Constant(ast_local_decl.type.type.names[0], str(formal_param.value))     
            main_stmts.append(ast_local_decl)
            
    # Initialise array variables using a loop nest of the appropriate depth
    for function_name in pencil_info.functions.keys():
        for formal_param in pencil_info.get_formal_params(function_name):
            if isinstance(formal_param.type, c_ast.ArrayDecl):
                # The name of the loop indices to create
                loop_indices = ["test_%d" % dim for dim in range(0,len(formal_param.dimensions))]
                # The innermost loop index is the last one in the list
                inner_loop_index = len(formal_param.dimensions) - 1
                # Create the statement that assigns into an array element
                for i in range(0, len(formal_param.dimensions)):
                    if i == 0:
                        ast_array_reference = c_ast.ArrayRef(c_ast.ID(formal_param.name), c_ast.ID(loop_indices[i]))
                    else:
                        ast_array_reference = c_ast.ArrayRef(ast_array_reference, c_ast.ID(loop_indices[i]))
                # Create the loop nest
                for i in reversed(range(0, len(formal_param.dimensions))):
                    ast_loop_header_step = c_ast.UnaryOp("++", 
                                                         c_ast.ID(loop_indices[i]))
                    ast_loop_header_cond = c_ast.BinaryOp("<", 
                                                          c_ast.ID(loop_indices[i]), 
                                                          c_ast.ID(formal_param.dimensions[i]))
                    ast_loop_header_decl = c_ast.Decl(loop_indices[i], 
                                                      [], 
                                                      [], 
                                                      [], 
                                                      c_ast.TypeDecl(loop_indices[i], [], c_ast.IdentifierType(["int"])),
                                                      c_ast.Constant("int", "0"), 
                                                      None)
                    ast_loop_header_init = c_ast.DeclList([ast_loop_header_decl])
                    if i == inner_loop_index:
                        ast_rand_call = c_ast.FuncCall(c_ast.ID("rand"), c_ast.ExprList([]))                        
                        if len(formal_param.base_type) == 1:
                            ast_cast_type      = c_ast.TypeDecl(None, None, c_ast.IdentifierType([formal_param.base_type[0]]))
                            ast_cast_rand_call = c_ast.Cast(c_ast.Typename(None, ast_cast_type), ast_rand_call)
                            ast_loop_body      = c_ast.Assignment("=", ast_array_reference, ast_cast_rand_call)
                        else:
                            loop_body_stmts = []
                            struct_field_initialisers = []
                            for j in range(0, len(formal_param.base_type)):
                                ast_cast_type      = c_ast.TypeDecl(None, None, c_ast.IdentifierType([formal_param.base_type[j]]))
                                ast_cast_rand_call = c_ast.Cast(c_ast.Typename(None, ast_cast_type), ast_rand_call)
                                struct_field_initialisers.append(ast_cast_rand_call)
                            ast_struct_initialiser = c_ast.InitList(struct_field_initialisers)
                            ast_struct_decl = c_ast.Decl("rand_value", 
                                                         [],
                                                         [],
                                                         [],
                                                         c_ast.TypeDecl("rand_value", [], c_ast.Struct(formal_param.struct_name, None)),
                                                         ast_struct_initialiser,
                                                         None)
                            loop_body_stmts.append(ast_struct_decl)
                            
                            ast_array_assignment = c_ast.Assignment("=", ast_array_reference, c_ast.ID("rand_value"))
                            loop_body_stmts.append(ast_array_assignment)
                            ast_loop_body = c_ast.Compound(loop_body_stmts)
                        ast_loop = c_ast.For(ast_loop_header_init, 
                                             ast_loop_header_cond, 
                                             ast_loop_header_step, 
                                             ast_loop_body)
                    else:
                        ast_loop = c_ast.For(ast_loop_header_init, 
                                             ast_loop_header_cond, 
                                             ast_loop_header_step, 
                                             ast_loop)
                main_stmts.append(ast_loop)
        
    # Create function calls into each PENCIL function
    for function_name in pencil_info.functions.keys():
        expr_list = []
        for formal_param in pencil_info.get_formal_params(function_name):
            the_type = formal_param.type
            # Whittle down through array declarations to get the identifier
            while isinstance(the_type, c_ast.ArrayDecl):
                the_type = the_type.type
            expr_list.append(c_ast.ID(the_type.declname))
        ast_func_call = c_ast.FuncCall(c_ast.ID(function_name), c_ast.ExprList(expr_list))
        main_stmts.append(ast_func_call)
    
    # The return statement
    ast_return = c_ast.Return(c_ast.Constant("int", "0"))
    main_stmts.append(ast_return)
    
    # The function body for "main"
    ast_type_decl = c_ast.TypeDecl("main", 
                                   [], 
                                   c_ast.IdentifierType(["int"]))
    ast_func_decl = c_ast.FuncDecl(c_ast.ParamList([]), 
                                   ast_type_decl)
    ast_decl      = c_ast.Decl(ast_type_decl.declname, 
                               [], 
                               [], 
                               [], 
                               ast_func_decl, 
                               None, 
                               None)
    ast_main_func = c_ast.FuncDef(ast_decl, 
                                  None, 
                                  c_ast.Compound(main_stmts))
    return ast_main_func