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 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
def procOutcome(resMgr, compiler, opts, pad="", sizeParams=None): params = opts['static_params'] if sizeParams is None else sizeParams openLog(opts) validated = True if opts['validate']: if all(compiler.validateList): if not 'libname' in opts: printToLog(pad + str(compiler.llprog) + " : " + "VALIDATED." + "\n\n", opts, openf=False, closef=False) else: printToLog(pad + opts.get('libname', "<Libname???>") + " : " + "VALIDATED." + "\n\n", opts, openf=False, closef=False) print "* Test passed" # if the test hadn't passed, an exception would have already been raised else: validated = False if not 'libname' in opts: printToLog(pad + str(compiler.llprog) + " : " + "FAILED " + str(compiler.validateList.count(False)) + "/" + str(len(compiler.validateList)) + " VALIDATIONS." + "\n", opts, openf=False, closef=False) else: printToLog( pad + opts.get('libname', "<Libname???>") + " : " + "FAILED " + str(compiler.validateList.count(False)) + "/" + str(len(compiler.validateList)) + " VALIDATIONS." + "\n", opts, openf=False, closef=False) print "* Test not passed: " + str( compiler.validateList.count(False)) + "/" + str( len(compiler.validateList)) if opts.get('test', True): if validated: bestout = compiler.outcome[0] print "\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Best computation $$$$$$$$$$$$$$$$$$$$$$$$$$$$\n" # print "Tested expression: " + str(bestout[0]) + "\nPerformance: " + str(bestout[1][0]) + " f/c\n" print "Performance: " + str(bestout[1][0]) + " f/c\n" print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n" msg = pad for p in params: msg += str(p) + ', ' printToLog(msg + str(bestout[0]) + ", " + str(bestout[1][0]) + " f/c -- folder: " + opts['compileroot'] + '/' + opts['compilename'] + "\n\n", opts, openf=False, closef=False) size = str(params[0]) for p in params[1:]: size += ',' + str(p) if len(params) > 1: size = '[' + size + ']' # if not 'libname' in opts: # printTracking(bestout[0], size, opts) # Add track-tiling (tt) attribute to desired matrices (see mmm tester) curve_name = opts['legendname'] if 'legendname' in opts else "" resMgr.addCurve(opts['testname'], size, bestout[1][1:], basefolder=opts['logroot'] + '/results', curve_name=curve_name, curve_marker=opts['marker'], curve_color=opts['color'], curve_lw=opts['lw'], rank_by_variants=deepcopy( compiler.rank_by_variants)) else: print "Some tests failed: Performance report aborted.\n\n" closeLog(opts) if opts.get('copycompfolder', True): compfolder = opts['compileroot'] + '/' + opts['compilename'] dstfolder = opts['logroot'] + '/results/' + opts[ 'testname'] + '/compfolder' print "Copying compilation folder: " + compfolder + "\n\n" if not os.path.exists(dstfolder): args = shlex.split("mkdir -p " + dstfolder) subprocess.call(args) if os.path.exists(compfolder): args = shlex.split("cp -r " + compfolder + " " + dstfolder) subprocess.call(args)