Skip to content

Commit

Permalink
- Use gcc/fortran/g++-4.7 as default in SPECCPU test (consistent with…
Browse files Browse the repository at this point in the history
… config file provided by #156)

- Add a flag allowing change build tool version
- Make lint happy.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177388988
yuyantingzero authored and s-deitz committed Dec 7, 2017
1 parent ca9513b commit 8bfbb9a
Showing 2 changed files with 51 additions and 4 deletions.
26 changes: 22 additions & 4 deletions perfkitbenchmarker/linux_benchmarks/speccpu2006_benchmark.py
Original file line number Diff line number Diff line change
@@ -24,18 +24,19 @@

import itertools
import logging
from operator import mul
import os
import posixpath
import re
import tarfile

from operator import mul
from perfkitbenchmarker import configs
from perfkitbenchmarker import data
from perfkitbenchmarker import errors
from perfkitbenchmarker import flags
from perfkitbenchmarker import sample
from perfkitbenchmarker import stages
from perfkitbenchmarker.linux_packages import build_tools


FLAGS = flags.FLAGS
@@ -62,6 +63,14 @@
'cfg file must be placed in the local PKB data directory and will be '
'copied to the remote machine prior to executing runspec. See README.md '
'for instructions if running with a repackaged cpu2006v1.2.tgz file.')
flags.DEFINE_string(
'runspec_build_tool_version', None,
'Version of gcc/g++/gfortran. This should match runspec_config. Note, if '
'neither runspec_config and runspec_build_tool_version is set, the test '
'install gcc/g++/gfortran-4.7, since that matches default config version. '
'If runspec_config is set, but not runspec_build_tool_version, default '
'version of build tools will be installed. Also this flag only works with '
'debian.')
flags.DEFINE_integer(
'runspec_iterations', 3,
'Used by the PKB speccpu2006 benchmark. The number of benchmark iterations '
@@ -119,7 +128,7 @@ def GetConfig(user_config):
return configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)


def CheckPrerequisites(benchmark_config):
def CheckPrerequisites(unused_benchmark_config):
"""Verifies that the required input files are present."""
try:
# Peeking into the tar file is slow. If running in stages, it's
@@ -227,6 +236,7 @@ class _SpecCpu2006SpecificState(object):
where the SPEC files are stored.
tar_file_path: Optional string. Path of the tar file on the remote machine.
"""

def __init__(self):
self.cfg_file_path = None
self.iso_file_path = None
@@ -246,8 +256,15 @@ def Prepare(benchmark_spec):
speccpu_vm_state = _SpecCpu2006SpecificState()
setattr(vm, _BENCHMARK_SPECIFIC_VM_STATE_ATTR, speccpu_vm_state)
vm.Install('wget')
vm.Install('build_tools')
vm.Install('fortran')
vm.Install('build_tools')

# If using default config files and runspec_build_tool_version is not set,
# install 4.7 gcc/g++/gfortan. If either one of the flag is set, we assume
# user is smart
if not FLAGS['runspec_config'].present or FLAGS.runspec_build_tool_version:
build_tool_version = FLAGS.runspec_build_tool_version or '4.7'
build_tools.Reinstall(vm, version=build_tool_version)
if FLAGS.runspec_enable_32bit:
vm.Install('multilib')
vm.Install('numactl')
@@ -329,6 +346,7 @@ def _ExtractScore(stdout, vm, keep_partial_results, estimate_spec):
keep_partial_results: A boolean indicating whether partial results should
be extracted in the event that not all benchmarks were successfully
run. See the "runspec_keep_partial_results" flag for more info.
estimate_spec: A boolean indicating whether should we estimate spec score.
Sample input for SPECint:
...
@@ -449,7 +467,7 @@ def _ExtractScore(stdout, vm, keep_partial_results, estimate_spec):


def _GeometricMean(arr):
"Calculates the geometric mean of the array."
"""Calculates the geometric mean of the array."""
return reduce(mul, arr) ** (1.0 / len(arr))


29 changes: 29 additions & 0 deletions perfkitbenchmarker/linux_packages/build_tools.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@


"""Module containing build tools installation and cleanup functions."""
from perfkitbenchmarker import os_types


def YumInstall(vm):
@@ -24,3 +25,31 @@ def YumInstall(vm):
def AptInstall(vm):
"""Installs build tools on the VM."""
vm.InstallPackages('build-essential git libtool autoconf automake')


def GetVersion(vm, pkg):
"""Get version of package."""
out, _ = vm.RemoteCommand('{pkg} -v'.format(pkg=pkg), ignore_failure=True)
return out


def Reinstall(vm, version='4.7'):
"""Install specific version of gcc.
Args:
vm: VirtualMachine object.
version: string. GCC version.
"""
if vm.OS_TYPE != os_types.DEBIAN:
return
for pkg in ('gcc', 'gfortran', 'g++'):
version_string = GetVersion(vm, pkg)
if version in version_string:
continue
else:
new_pkg = pkg + '-' + version
vm.RemoteCommand('sudo apt-get remove {pkg} -y'.format(pkg=pkg),
ignore_failure=True)
vm.InstallPackages(new_pkg)
vm.RemoteCommand('sudo ln -s /usr/bin/{new_pkg} /usr/bin/{pkg}'.format(
new_pkg=new_pkg, pkg=pkg))

0 comments on commit 8bfbb9a

Please sign in to comment.