def testing2Param(resMgr, p0, p1, opts): ''' Test the kernel opts['hfilebasename'] for the cartesian product of the values in the given intervals p0, p1. ''' sizesP0 = range(p0[0], p0[1] + 1) if len(p0) == 2 else range(p0[0], p0[1] + 1, p0[2]) sizesP1 = range(p1[0], p1[1] + 1) if len(p1) == 2 else range(p1[0], p1[1] + 1, p1[2]) sizes = [(i, j) for i in sizesP0 for j in sizesP1] for M, N in sizes: opts['static_params'] = [M, N] genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: llprog = parseLL({'M': M, 'N': N}, opts) # expr = eval(opts['hfilebasename'])(N, opts) compiler = Compiler(llprog, opts) else: compiler = LibraryCode(opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ") printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts)
def testing3Param(resMgr, p0, p1, p2, opts): ''' Test the kernel for the cartesian product of the values in the given intervals p0, p1, p3. ''' sizesP0 = range(p0[0], p0[1] + 1) if len(p0) == 2 else range(p0[0], p0[1] + 1, p0[2]) sizesP1 = range(p1[0], p1[1] + 1) if len(p1) == 2 else range(p1[0], p1[1] + 1, p1[2]) sizesP2 = range(p2[0], p2[1] + 1) if len(p2) == 2 else range(p2[0], p2[1] + 1, p2[2]) sizes = [(i, j, k) for i in sizesP0 for j in sizesP1 for k in sizesP2] fine = True for M, K, N in sizes: try: opts['static_params'] = [M, K, N] genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: llprog = parseLL({'M': M, 'K': K, 'N': N}, opts) # expr = eval(opts['hfilebasename'])(M, K, N, opts) compiler = Compiler(llprog, opts) else: compiler = LibraryCode(opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) fine = fine and compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ") printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts) except Exception: if opts.get('breakonexc', False): raise fine = False openLog(opts) ts = '%s.%s' % (date.today().isoformat(), time.strftime('%H-%M-%S', time.localtime(time.time()))) msg = "=@" * 10 + " Begin Exc Report from testing3Param (" + ts + ") " + "=@" * 10 + "\n" msg += "-" * 10 + " opts " + "-" * 10 + "\n" msg += str(opts) + "\n" msg += "-" * 10 + " traceback " + "-" * 10 + "\n" printToLog(msg, opts, openf=False, closef=False) traceback.print_exc(file=opts['logfile']) msg = "\n" + "=@" * 10 + " End Exc Report (" + ts + ") " + "=@" * 10 + "\n" printToLog(msg, opts, openf=False) return fine
def testingRandom(resMgr, maxops, maxdim, maxeq, numgen, opts): fine = True llgen = RandomLLGen(maxops=maxops, maxdim=maxdim, maxeq=maxeq) for _ in range(numgen): genres = llgen.gen() srcfile = open(opts['source'], 'w') srcfile.write(genres[0]) srcfile.close() for pvalues in genres[2]: try: opts['static_params'] = pvalues genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: llprog = parseLL(dict(zip(genres[1], pvalues)), opts) compiler = Compiler(llprog, opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) fine = fine and compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ") printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts) else: print "Please enable code generation." except Exception: if opts.get('breakonexc', False): raise fine = False openLog(opts) ts = '%s.%s' % (date.today().isoformat(), time.strftime('%H-%M-%S', time.localtime(time.time()))) msg = "=@" * 10 + " Begin Exc Report from testingRandom (" + ts + ") " + "=@" * 10 + "\n" msg += "Generation of:\n\n%s\n\nParams:\n\n%s = %s\n\n" % ( genres[0], str(genres[1]), str(genres[2])) msg += "-" * 10 + " opts " + "-" * 10 + "\n" msg += str(opts) + "\n" msg += "-" * 10 + " traceback " + "-" * 10 + "\n" printToLog(msg, opts, openf=False, closef=False) traceback.print_exc(file=opts['logfile']) msg = "\n" + "=@" * 10 + " End Exc Report (" + ts + ") " + "=@" * 10 + "\n" printToLog(msg, opts, openf=False) return fine
def testing1Param(resMgr, p, opts): sizes = range(p[0], p[1] + 1) if len(p) == 2 else range(p[0], p[1] + 1, p[2]) fine = True for M in sizes: try: opts['static_params'] = [M] genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: llprog = parseLL({'M': M}, opts) # expr = eval(opts['hfilebasename'])(N, opts) compiler = Compiler(llprog, opts) else: compiler = LibraryCode(opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) fine = fine and compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ") printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts) except Exception: if opts.get('breakonexc', False): raise fine = False openLog(opts) ts = '%s.%s' % (date.today().isoformat(), time.strftime('%H-%M-%S', time.localtime(time.time()))) msg = "=@" * 10 + " Begin Exc Report from testing1Param (" + ts + ") " + "=@" * 10 + "\n" msg += "-" * 10 + " opts " + "-" * 10 + "\n" msg += str(opts) + "\n" msg += "-" * 10 + " traceback " + "-" * 10 + "\n" printToLog(msg, opts, openf=False, closef=False) traceback.print_exc(file=opts['logfile']) msg = "\n" + "=@" * 10 + " End Exc Report (" + ts + ") " + "=@" * 10 + "\n" printToLog(msg, opts, openf=False) return fine
def testing1toNParam(resMgr, p0, fs, opts): sizesP0 = range(p0[0], p0[1] + 1) if len(p0) == 2 else range(p0[0], p0[1] + 1, p0[2]) params = [f[0] for f in fs] sizes = [] for i in sizesP0: sizes.append([f[1](i) for f in fs]) fine = True for pvalues, i in zip(sizes, sizesP0): try: opts['static_params'] = pvalues genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: opts['pvalues'] = { p: pvalue for p, pvalue in zip(params, pvalues) } llprog = parseLL( {p: pvalue for p, pvalue in zip(params, pvalues)}, opts) compiler = Compiler(llprog, opts) else: compiler = LibraryCode(opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) fine = fine and compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ", sizeParams=[i]) printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts) except Exception: # openLog(opts) ts = '%s.%s' % (date.today().isoformat(), time.strftime('%H-%M-%S', time.localtime(time.time()))) msg = "=@" * 10 + " Begin Exc Report from testing1toNParam (" + ts + ") " + "=@" * 10 + "\n" msg += "-" * 10 + " opts " + "-" * 10 + "\n" msg += str(opts) + "\n" msg += "-" * 10 + " traceback " + "-" * 10 + "\n" # printToLog(msg, opts, openf=False, closef=False) # traceback.print_exc(file=opts['logfile']) msg += traceback.format_exc() msg += "\n" + "=@" * 10 + " End Exc Report (" + ts + ") " + "=@" * 10 + "\n" printToLog(msg, opts) if opts.get('breakonexc', False): # openLog(opts, 'r') # body = opts['logfile'].read() # closeLog(opts) send_email_with_log(opts, subj="SLinGen Report on Exception", body=msg) raise fine = False return fine
def testingNParam(resMgr, ps, opts): ''' Test the kernel for the cartesian product of the values in the given intervals p0, p1, p2, ... ''' params = [pi[0] for pi in ps] sizesPi = [ range(pi[1], pi[2] + 1) if len(pi) == 3 else range(pi[1], pi[2] + 1, pi[3]) for pi in ps ] sizes = list(itertools.product(*sizesPi)) fine = True for pvalues in sizes: try: opts['static_params'] = list(pvalues) genCode = not 'libname' in opts onlygen = 'onlygen' in opts and opts['onlygen'] compiler = None if genCode: opts['pvalues'] = { p: pvalue for p, pvalue in zip(params, pvalues) } llprog = parseLL( {p: pvalue for p, pvalue in zip(params, pvalues)}, opts) compiler = Compiler(llprog, opts) else: compiler = LibraryCode(opts) s = datetime.now() if not onlygen: printToLog( " " + "Starting compiler at " + str(s) + " ----------------------------------------", opts) fine = fine and compiler.compile() e = datetime.now() if not (genCode and onlygen): procOutcome(resMgr, compiler, opts, " ") printToLog( " " + "Compiling took " + str(e - s) + " ----------------------------------------------------------", opts) recordTime((e - s).total_seconds(), opts) except Exception: openLog(opts) ts = '%s.%s' % (date.today().isoformat(), time.strftime('%H-%M-%S', time.localtime(time.time()))) msg = "=@" * 10 + " Begin Exc Report from testingNParam (" + ts + ") " + "=@" * 10 + "\n" msg += "-" * 10 + " opts " + "-" * 10 + "\n" msg += str(opts) + "\n" msg += "-" * 10 + " traceback " + "-" * 10 + "\n" # printToLog(msg, opts, openf=False, closef=False) # traceback.print_exc(file=opts['logfile']) msg += traceback.format_exc() msg += "\n" + "=@" * 10 + " End Exc Report (" + ts + ") " + "=@" * 10 + "\n" # printToLog(msg, opts, openf=False) printToLog(msg, opts) if opts.get('breakonexc', False): send_email_with_log(opts, subj="SLinGen Report on Exception", body=msg) raise fine = False return fine
# decl = self.declout if pos == 'l' else self.declin # if key in decl: # decl[key].append(op) # else: # decl[key] = [op] # elif (isin and pos == 'l') or (isout and pos == 'r'): # src = self.declin if isin else self.declout # src[key].remove(op) # if not src[key]: # del src[key] # if key in self.declinout: # self.declinout[key].append(op) # else: # self.declinout[key] = [op] # else: # src = None # if isinout: # src = self.declinout # elif isin: # src = self.declin # else: # src = self.declout # if op not in src[key]: # src[key] = [op] # return op if __name__ == '__main__': opts = {'source': 'tests/rdiv_nublac.ll'} llprog = parseLL({'M': 4}, opts) print llprog