Spaces:
Runtime error
Runtime error
File size: 6,096 Bytes
be11144 |
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# Copyright (c) 2018 NVIDIA Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
from sys import exit
from os.path import join, dirname, basename, realpath
from csv import DictReader as csv_dict_reader
from subprocess import Popen
from argparse import ArgumentParser as argument_parser
###############################################################################
def printable_cmd(c):
"""Converts a `list` of `str`s representing a shell command to a printable
`str`."""
return " ".join(map(lambda e: '"' + str(e) + '"', c))
###############################################################################
def print_file(p):
"""Open the path `p` and print its contents to `stdout`."""
print "********************************************************************************"
with open(p) as f:
for line in f:
print line,
print "********************************************************************************"
###############################################################################
ap = argument_parser(
description = (
"CUDA Eris driver script: runs a benchmark suite multiple times, combines "
"the results, and outputs them in the CUDA Eris performance result format."
)
)
ap.add_argument(
"-b", "--benchmark",
help = ("The location of the benchmark suite executable to run."),
type = str,
default = join(dirname(realpath(__file__)), "bench"),
metavar = "R"
)
ap.add_argument(
"-p", "--postprocess",
help = ("The location of the postprocessing script to run to combine the "
"results."),
type = str,
default = join(dirname(realpath(__file__)), "combine_benchmark_results.py"),
metavar = "R"
)
ap.add_argument(
"-r", "--runs",
help = ("Run the benchmark suite `R` times.a),"),
type = int, default = 5,
metavar = "R"
)
args = ap.parse_args()
if args.runs <= 0:
print "ERROR: `--runs` must be greater than `0`."
ap.print_help()
exit(1)
BENCHMARK_EXE = args.benchmark
BENCHMARK_NAME = basename(BENCHMARK_EXE)
POSTPROCESS_EXE = args.postprocess
OUTPUT_FILE_NAME = lambda i: BENCHMARK_NAME + "_" + str(i) + ".csv"
COMBINED_OUTPUT_FILE_NAME = BENCHMARK_NAME + "_combined.csv"
###############################################################################
print '&&&& RUNNING {0}'.format(BENCHMARK_NAME)
print '#### RUNS {0}'.format(args.runs)
###############################################################################
print '#### CMD {0}'.format(BENCHMARK_EXE)
for i in xrange(args.runs):
with open(OUTPUT_FILE_NAME(i), "w") as output_file:
print '#### RUN {0} OUTPUT -> {1}'.format(i, OUTPUT_FILE_NAME(i))
p = None
try:
p = Popen(BENCHMARK_EXE, stdout = output_file, stderr = output_file)
p.communicate()
except OSError as ex:
print_file(OUTPUT_FILE_NAME(i))
print '#### ERROR Caught OSError `{0}`.'.format(ex)
print '&&&& FAILED {0}'.format(BENCHMARK_NAME)
exit(-1)
print_file(OUTPUT_FILE_NAME(i))
if p.returncode != 0:
print '#### ERROR Process exited with code {0}.'.format(p.returncode)
print '&&&& FAILED {0}'.format(BENCHMARK_NAME)
exit(p.returncode)
###############################################################################
post_cmd = [POSTPROCESS_EXE]
# Add dependent variable options.
post_cmd += ["-dSTL Average Walltime,STL Walltime Uncertainty,STL Trials"]
post_cmd += ["-dSTL Average Throughput,STL Throughput Uncertainty,STL Trials"]
post_cmd += ["-dThrust Average Walltime,Thrust Walltime Uncertainty,Thrust Trials"]
post_cmd += ["-dThrust Average Throughput,Thrust Throughput Uncertainty,Thrust Trials"]
post_cmd += [OUTPUT_FILE_NAME(i) for i in range(args.runs)]
print '#### CMD {0}'.format(printable_cmd(post_cmd))
with open(COMBINED_OUTPUT_FILE_NAME, "w") as output_file:
p = None
try:
p = Popen(post_cmd, stdout = output_file, stderr = output_file)
p.communicate()
except OSError as ex:
print_file(COMBINED_OUTPUT_FILE_NAME)
print '#### ERROR Caught OSError `{0}`.'.format(ex)
print '&&&& FAILED {0}'.format(BENCHMARK_NAME)
exit(-1)
print_file(COMBINED_OUTPUT_FILE_NAME)
if p.returncode != 0:
print '#### ERROR Process exited with code {0}.'.format(p.returncode)
print '&&&& FAILED {0}'.format(BENCHMARK_NAME)
exit(p.returncode)
with open(COMBINED_OUTPUT_FILE_NAME) as input_file:
reader = csv_dict_reader(input_file)
variable_units = reader.next() # Get units header row.
distinguishing_variables = reader.fieldnames
measured_variables = [
("STL Average Throughput", "+"),
("Thrust Average Throughput", "+")
]
for record in reader:
for variable, directionality in measured_variables:
# Don't monitor regressions for STL implementations, nvbug 28980890:
if "STL" in variable:
continue
print "&&&& PERF {0}_{1}_{2}bit_{3}mib_{4} {5} {6}{7}".format(
record["Algorithm"],
record["Element Type"],
record["Element Size"],
record["Total Input Size"],
variable.replace(" ", "_").lower(),
record[variable],
directionality,
variable_units[variable]
)
###############################################################################
print '&&&& PASSED {0}'.format(BENCHMARK_NAME)
|