cpu2000.py

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· Python 代码 · 共 726 行 · 第 1/2 页

PY
726
字号
import osimport sysfrom os.path import basename, exists, join as joinpath, normpathfrom os.path import isdir, isfile, islinkspec_dist = '/dist/m5/cpu2000'def copyfiles(srcdir, dstdir):    from filecmp import cmp as filecmp    from shutil import copyfile    srcdir = normpath(srcdir)    dstdir = normpath(dstdir)    if not isdir(dstdir):        os.mkdir(dstdir)    for root, dirs, files in os.walk(srcdir):        root = normpath(root)        prefix = os.path.commonprefix([root, srcdir])        root = root[len(prefix):]        if root.startswith('/'):            root = root[1:]        for entry in dirs:            newdir = joinpath(dstdir, root, entry)            if not isdir(newdir):                os.mkdir(newdir)        for entry in files:            dest = normpath(joinpath(dstdir, root, entry))            src = normpath(joinpath(srcdir, root, entry))            if not isfile(dest) or not filecmp(src, dest):                copyfile(src, dest)    # some of the spec benchmarks expect to be run from one directory up.    # just create some symlinks that solve the problem    inlink = joinpath(dstdir, 'input')    outlink = joinpath(dstdir, 'output')    if not exists(inlink):        os.symlink('.', inlink)    if not exists(outlink):        os.symlink('.', outlink)class Benchmark(object):    def __init__(self, isa, os, input_set):        if not hasattr(self.__class__, 'name'):            self.name = self.__class__.__name__        if not hasattr(self.__class__, 'binary'):            self.binary = self.name        if not hasattr(self.__class__, 'args'):            self.args = []        if not hasattr(self.__class__, 'output'):            self.output = '%s.out' % self.name        if not hasattr(self.__class__, 'simpoint'):            self.simpoint = None        try:            func = getattr(self.__class__, input_set)        except AttributeError:            raise AttributeError, \                  'The benchmark %s does not have the %s input set' % \                  (self.name, input_set)        executable = joinpath(spec_dist, 'binaries', isa, os, self.binary)        if not isfile(executable):            raise AttributeError, '%s not found' % executable        self.executable = executable        # root of tree for input & output data files        data_dir = joinpath(spec_dist, 'data', self.name)        # optional subtree with files shared across input sets        all_dir = joinpath(data_dir, 'all')        # dirs for input & output files for this input set        inputs_dir = joinpath(data_dir, input_set, 'input')        outputs_dir = joinpath(data_dir, input_set, 'output')        # keep around which input set was specified        self.input_set = input_set        if not isdir(inputs_dir):            raise AttributeError, '%s not found' % inputs_dir        self.inputs_dir = [ inputs_dir ]        if isdir(all_dir):            self.inputs_dir += [ joinpath(all_dir, 'input') ]        if isdir(outputs_dir):            self.outputs_dir = outputs_dir        if not hasattr(self.__class__, 'stdin'):            self.stdin = joinpath(inputs_dir, '%s.in' % self.name)            if not isfile(self.stdin):                self.stdin = None        if not hasattr(self.__class__, 'stdout'):            self.stdout = joinpath(outputs_dir, '%s.out' % self.name)            if not isfile(self.stdout):                self.stdout = None        func(self, isa, os)    def makeLiveProcessArgs(self, **kwargs):        # set up default args for LiveProcess object        process_args = {}        process_args['cmd'] = [ self.name ] + self.args        process_args['executable'] = self.executable        if self.stdin:            process_args['input'] = self.stdin        if self.stdout:            process_args['output'] = self.stdout        process_args['simpoint'] = self.simpoint        # explicit keywords override defaults        process_args.update(kwargs)        return process_args    def makeLiveProcess(self, **kwargs):        process_args = self.makeLiveProcessArgs(**kwargs)        # figure out working directory: use m5's outdir unless        # overridden by LiveProcess's cwd param        cwd = process_args.get('cwd')        if not cwd:            from m5.main import options            cwd = options.outdir            process_args['cwd'] = cwd        if not isdir(cwd):            os.makedirs(cwd)        # copy input files to working directory        for d in self.inputs_dir:            copyfiles(d, cwd)        # generate LiveProcess object        from m5.objects import LiveProcess        return LiveProcess(**process_args)    def __str__(self):        return self.nameclass DefaultBenchmark(Benchmark):    def ref(self, isa, os): pass    def test(self, isa, os): pass    def train(self, isa, os): passclass MinneDefaultBenchmark(DefaultBenchmark):    def smred(self, isa, os): pass    def mdred(self, isa, os): pass    def lgred(self, isa, os): passclass ammp(MinneDefaultBenchmark):    name = 'ammp'    number = 188    lang = 'C'    simpoint = 108*100E6class applu(MinneDefaultBenchmark):    name = 'applu'    number = 173    lang = 'F77'    simpoint = 2179*100E6class apsi(MinneDefaultBenchmark):    name = 'apsi'    number = 301    lang = 'F77'    simpoint = 3408*100E6class art(DefaultBenchmark):    name = 'art'    number = 179    lang = 'C'    def test(self, isa, os):        self.args = [ '-scanfile', 'c756hel.in',                      '-trainfile1', 'a10.img',                      '-stride', '2',                      '-startx', '134',                      '-starty', '220',                      '-endx', '139',                      '-endy', '225',                      '-objects', '1' ]        self.output = 'test.out'    def train(self, isa, os):        self.args = [ '-scanfile', 'c756hel.in',                      '-trainfile1', 'a10.img',                      '-stride', '2',                      '-startx', '134',                      '-starty', '220',                      '-endx', '184',                      '-endy', '240',                      '-objects', '3' ]        self.output = 'train.out'    def lgred(self, isa, os):        self.args = ['-scanfile', 'c756hel.in',                     '-trainfile1', 'a10.img',                     '-stride', '5',                     '-startx', '134',                     '-starty', '220',                     '-endx', '184',                     '-endy', '240',                     '-objects', '1' ]        self.output = 'lgred.out'class art110(art):    def ref(self, isa, os):        self.args = [ '-scanfile', 'c756hel.in',                      '-trainfile1', 'a10.img',                      '-trainfile2', 'hc.img',                      '-stride', '2',                      '-startx', '110',                      '-starty', '200',                      '-endx', '160',                      '-endy', '240',                      '-objects', '10' ]        self.output = 'ref.1.out'        self.simpoint = 340*100E6class art470(art):    def ref(self, isa, os):        self.args = [ '-scanfile', 'c756hel.in',                      '-trainfile1', 'a10.img',                      '-trainfile2', 'hc.img',                      '-stride', '2',                      '-startx', '470',                      '-starty', '140',                      '-endx', '520',                      '-endy', '180',                      '-objects', '10' ]        self.output = 'ref.2.out'        self.simpoint = 365*100E6class equake(DefaultBenchmark):    name = 'equake'    number = 183    lang = 'C'    simpoint = 812*100E6    def lgred(self, isa, os): passclass facerec(MinneDefaultBenchmark):    name = 'facerec'    number = 187    lang = 'F'    simpoint = 375*100E6class fma3d(MinneDefaultBenchmark):    name = 'fma3d'    number = 191    lang = 'F'    simpoint = 2541*100E6class galgel(MinneDefaultBenchmark):    name = 'galgel'    number = 178    lang = 'F'    simpoint = 2491*100E6class lucas(MinneDefaultBenchmark):    name = 'lucas'    number = 189    lang = 'F'    simpoint = 545*100E6class mesa(Benchmark):    name = 'mesa'    number = 177    lang = 'C'    stdin = None    def __set_args(self, frames):        self.args = [ '-frames', frames, '-meshfile', '%s.in' % self.name,                      '-ppmfile', '%s.ppm' % self.name ]    def test(self, isa, os):        self.__set_args('10')    def train(self, isa, os):        self.__set_args('500')    def ref(self, isa, os):        self.__set_args('1000')        self.simpoint = 1135*100E6    def lgred(self, isa, os):        self.__set_args('1')class mgrid(MinneDefaultBenchmark):    name = 'mgrid'    number = 172    lang = 'F77'    simpoint = 3292*100E6class sixtrack(DefaultBenchmark):    name = 'sixtrack'    number = 200    lang = 'F77'    simpoint = 3043*100E6    def lgred(self, isa, os): passclass swim(MinneDefaultBenchmark):    name = 'swim'    number = 171    lang = 'F77'    simpoint = 2079*100E6class wupwise(DefaultBenchmark):    name = 'wupwise'    number = 168    lang = 'F77'    simpoint = 3237*100E6    def lgred(self, isa, os): passclass bzip2(DefaultBenchmark):    name = 'bzip2'    number = 256    lang = 'C'    def test(self, isa, os):        self.args = [ 'input.random' ]    def train(self, isa, os):        self.args = [ 'input.compressed' ]class bzip2_source(bzip2):    def ref(self, isa, os):        self.simpoint = 977*100E6        self.args = [ 'input.source', '58' ]    def lgred(self, isa, os):        self.args = [ 'input.source', '1' ]class bzip2_graphic(bzip2):    def ref(self, isa, os):        self.simpoint = 718*100E6        self.args = [ 'input.graphic', '58' ]    def lgred(self, isa, os):        self.args = [ 'input.graphic', '1' ]class bzip2_program(bzip2):    def ref(self, isa, os):        self.simpoint = 458*100E6        self.args = [ 'input.program', '58' ]    def lgred(self, isa, os):        self.args = [ 'input.program', '1' ]class crafty(MinneDefaultBenchmark):    name = 'crafty'    number = 186    lang = 'C'    simpoint = 774*100E6class eon(MinneDefaultBenchmark):

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?