From 69f2911e04ffb1b19eef1fafb8c040af271f656e Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Thu, 15 Jul 2010 18:09:46 -0800 Subject: creating branch for adding support for CUDA 3.x and Fermi [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6829] --- .../CUDA/CP/common/python/binaryfilecompare.py | 50 +++++++ benchmarks/CUDA/CP/common/python/filecompare.py | 154 +++++++++++++++++++++ .../CUDA/CP/common/python/textfilecompare.py | 27 ++++ 3 files changed, 231 insertions(+) create mode 100644 benchmarks/CUDA/CP/common/python/binaryfilecompare.py create mode 100644 benchmarks/CUDA/CP/common/python/filecompare.py create mode 100644 benchmarks/CUDA/CP/common/python/textfilecompare.py (limited to 'benchmarks/CUDA/CP/common/python') diff --git a/benchmarks/CUDA/CP/common/python/binaryfilecompare.py b/benchmarks/CUDA/CP/common/python/binaryfilecompare.py new file mode 100644 index 0000000..b143b68 --- /dev/null +++ b/benchmarks/CUDA/CP/common/python/binaryfilecompare.py @@ -0,0 +1,50 @@ +# (c) Copyright 2007 The Board of Trustees of the University of Illinois. + +import struct + +def uint16(f): + """Read a 16-bit unsigned integer from f.""" + [c, c2] = f.read(2) + return ord(c) + (ord(c2) << 8) + +def uint32(f): + """Read a 32-bit unsigned integer from f.""" + [c, c2, c3, c4] = f.read(4) + return ord(c) + (ord(c2) << 8) + (ord(c3) << 16) + (ord(c4) << 24) + +def float(f): + """Read a floating-point number from f.""" + s = f.read(4) + (n,) = struct.unpack(">= operator. Executes 'fst', then executes 'snd' with the result +# of 'fst'. +class Bind(CompareMonad): + + def __init__(self, fst, snd): + CompareMonad.checkType(fst) + self.fst = fst + self.snd = snd + + def run(self, ref_file, out_file): + (ok, value) = self.fst.run(ref_file, out_file) + if ok: + sndMonad = self.snd(value) + CompareMonad.checkType(sndMonad) + return sndMonad.run(ref_file, out_file) + return (False, None) + +# The >> operator. Executes 'fst', then executes 'snd'. +class Then(CompareMonad): + def __init__(self, fst, snd): + CompareMonad.checkType(fst) + CompareMonad.checkType(snd) + self.fst = fst + self.snd = snd + + def run(self, ref_file, out_file): + (ok, value) = self.fst.run(ref_file, out_file) + if ok: + return self.snd.run(ref_file, out_file) + return (False, None) + +# The 'return' operator. Returns a value that is accessible +# within the monad. +class Return(CompareMonad): + def __init__(self, value): + self.value = value + + def run(self, ref_file, out_file): + return (True, self.value) + +# Run a list of monad instances and return their results as +# a list. +class Sequence(CompareMonad): + def __init__(self, ms): + self.ms = ms + + def run(self, ref_file, out_file): + values = [] + for m in self.ms: + CompareMonad.checkType(m) + (ok, value) = m.run(ref_file, out_file) + if not ok: return (False, None) + values.append(value) + + return (True, values) + +# Run a list of monad instances, ignoring their results. +class Sequence_(CompareMonad): + def __init__(self, ms): + self.ms = ms + + def run(self, ref_file, out_file): + for m in self.ms: + CompareMonad.checkType(m) + (ok, value) = m.run(ref_file, out_file) + if not ok: return (False, None) + + return (True, None) + +# The basic CompareMonad routine. This reads a value from both input +# files, compares the result, and, if the comparison was successful, +# returns the value. +class Compare(CompareMonad): + """Read an item from both input files and compare it.""" + + def __init__(self, + read = file.read, + equal = lambda x, y: x == y, + message = "Output does not match the expected output"): + self.read = read + self.equal = equal + self.message = message + + def run(self, ref_file, out_file): + try: + x = self.read(ref_file) + except ValueError, e: + sys.stderr.write("Malformed reference file!\n") + return (False, None) + except EOFError: + sys.stderr.write("Unexpected end of reference file!\n") + return (False, None) + try: + y = self.read(out_file) + except ValueError, e: + sys.stderr.write("Malformed output file;\n") + sys.stderr.write(str(e)) + sys.stderr.write('\n') + return (False, None) + except EOFError: + sys.stderr.write("Unexpected end of output file\n") + return (False, None) + + # Compare reference data to result data + if self.equal(x, y): + return (True, x) + else: + sys.stderr.write(self.message) + sys.stderr.write('\n') + return (False, None) + +def open_or_abort(filename): + try: f = file(filename, "r") + except: + sys.stderr.write("Cannot open file '" + filename + "'\n") + sys.exit(-1) + return f + + +def default_main(comparison_routine): + """Default main() routine. Read file names from sys.argv + and compare the files.""" + + if len(sys.argv) != 3: + sys.stderr.write("Usage: compare-output \n") + sys.exit(-1) + + ref = open_or_abort(sys.argv[1]) + out = open_or_abort(sys.argv[2]) + + (ok, _) = comparison_routine.run(ref, out) + if ok: + sys.stdout.write("Pass\n") + sys.exit(0) + else: + sys.stdout.write("Mismatch\n") + sys.exit(-1) + diff --git a/benchmarks/CUDA/CP/common/python/textfilecompare.py b/benchmarks/CUDA/CP/common/python/textfilecompare.py new file mode 100644 index 0000000..2f6ef68 --- /dev/null +++ b/benchmarks/CUDA/CP/common/python/textfilecompare.py @@ -0,0 +1,27 @@ +# (c) Copyright 2007 The Board of Trustees of the University of Illinois. + +from binaryfilecompare import eof, many + +# Rename the builtin 'float' variable to avoid name conflicts +builtin_float = float + +def verbatim(f): + """Read a line of text from file 'f'.""" + line = f.readline() + return line + +def float(f): + """Read a line of text from file 'f' as a single floating-point + number.""" + words = f.readline().split() + if len(words) != 1: + raise ValueError, "Expecting line to contain a single number" + return builtin_float(words[0]) + +def floats(f): + """Read a line of text from file 'f' as a list of floating-point + numbers.""" + words = f.readline().split() + return [builtin_float(x) for x in words] + + -- cgit v1.3