summaryrefslogtreecommitdiff
path: root/benchmarks/CUDA/CP/driver/actions.py
blob: 8525028bc8da93c5812d925083fd42770f954ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# (c) 2007 The Board of Trustees of the University of Illinois.

# These are the main actions that the driver may take.  The actions
# call lower-level routines from the process or benchmark modules.

import os
from itertools import imap

import process
import benchmark
import globals
from text import format_columns

def benchmark_iter():
    """Iterate over the benchmarks in 'bmks'."""
    # bmks is a dictionary from str to Future(Benchmark)
    return imap(lambda x: x.get(), globals.benchmarks.itervalues())

def list_benchmarks():
    """List all benchmarks on standard output."""
    print "Benchmarks:"
    for bmk in benchmark_iter(): print "  " + bmk.name
        
def describe_benchmarks():
    """Print descriptions of all benchmarks to standard output."""
    for bmk in benchmark_iter(): describe_benchmark(bmk)

def describe_benchmark(bmk):
    """Print a description of one benchmark to standard output."""

    print "  " + bmk.name
    print format_columns(bmk.describe(), 4)

def lookup_benchmark(name):
    """Find a benchmark, given its name.  Returns None if no benchmark
    is found with the given name or if the benchmark is invalid.
    If the benchmark cannot be found, an error is printed."""
    b = globals.benchmarks.get(name)
    if b is not None:
        bmk = b.get()
        if bmk.invalid is None:
            return bmk
        else:
            print "Error in benchmark:"
            print str(bmk.invalid)
            return None
    else:
        print "Cannot find benchmark"
        return None

def with_benchmark_named(name, action):
    """Look up the benchmark named 'name'.  If found, apply the action
    to it.  Otherwise, print an error message and return None."""

    bmk = lookup_benchmark(name)
    if bmk is not None: action(bmk)

def compile_benchmark(bmk, version_name):
    """Compile the benchmark 'bmk'."""
    try: impl = bmk.impls[version_name]
    except KeyError:
        print "Cannot find benchmark version"
        return
    
    impl.build(bmk)

def clean_benchmark(bmk, version_name=None):
    """Remove the compiled code for one implementation of 'bmk'.  If
    no version is given, clean all versions."""

    if version_name:
        try: impl = bmk.impls[version_name]
        except KeyError:
            print "Cannot find benchmark version"
            return

        impl.clean(bmk)
    else:
        # Clean all versions
        for impl in bmk.impls.itervalues():
            impl.clean(bmk)

def run_benchmark(bmk, version_name, input_name, check=True, extra_opts=[]):
    """Run the benchmark 'bmk'."""
    try: impl = bmk.impls[version_name]
    except KeyError:
        print "Cannot find benchmark version"
        return
    
    try: data = bmk.datas[input_name]
    except KeyError:
        print "Cannot find data set"
        return

    # Run the benchmark
    success = impl.run(bmk, data, check, extra_opts=extra_opts)

    if not success:
        print "Run failed!"
        return

    # Verify the output
    if check:
        success = impl.check(bmk, data)

        if not success:
            print "Output checking tool detected a mismatch"
    else:
        print "Output was not checked for correctness"