To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit b08ead5f authored by John Zhang's avatar John Zhang
Browse files

refactor: add cbconf.py to setup configuration for callbacks

parent ff79fd19
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# 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.
# Functions to configure callback settings
from pathlib import Path
from mubench import CALLBACKS_DIR
from mubench.util import expandenv
def configure_cb_perfevent(cb_d, env):
assert 'libpfm4_dir' in cb_d, "libpfm4 install directory not specified"
libpfm4 = Path(expandenv(cb_d['libpfm4_dir'], env))
if not libpfm4.is_absolute():
libpfm4 = CALLBACKS_DIR / libpfm4 # default relative to CALLBACKS_DIR
cb_d['include_dirs'].extend([
str(libpfm4 / 'include'),
str(libpfm4 / 'util')
])
cb_d['library_dirs'].append(str(libpfm4 / 'lib'))
cb_d['libraries'].append('pfm')
cb_d['extra_srcs'].append(str(libpfm4 / 'util' / 'perf_util.c'))
cb_d['flags'].append('-pthread')
def configure_cb_clock(cb_d, env):
pass
def configure_cb_print(cb_d, env):
pass
\ No newline at end of file
...@@ -29,6 +29,7 @@ from mubench.util import expandenv, dictify, run_in_subproc, ExecutionFailure ...@@ -29,6 +29,7 @@ from mubench.util import expandenv, dictify, run_in_subproc, ExecutionFailure
from mubench.util import add_path_to_ld_library_path from mubench.util import add_path_to_ld_library_path
from mubench.lang import get_lang, Language from mubench.lang import get_lang, Language
from mubench.models.result import Result from mubench.models.result import Result
from mubench.models import cbconf
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -62,22 +63,27 @@ class TaskSet: ...@@ -62,22 +63,27 @@ class TaskSet:
ts_env[v] = expandenv(ts_env[v], self.env) ts_env[v] = expandenv(ts_env[v], self.env)
self.env.update(ts_env) self.env.update(ts_env)
# expand environs in benchmark args and callback param # configure callback
benchmark['args'] = list( conf_func = getattr(cbconf, 'configure_cb_%(name)s' % callback)
map(lambda a: expandenv(str(a), self.env), benchmark['args'])) conf_func(callback, self.env)
# expand environs in benchmark args and callback param and paths
def get_expanded_list(l):
return list(map(lambda a: expandenv(str(a), self.env), l))
benchmark['args'] = get_expanded_list(benchmark['args'])
callback['param'] = expandenv(callback['param'], self.env) callback['param'] = expandenv(callback['param'], self.env)
callback['include_dirs'] = get_expanded_list(callback['include_dirs'])
callback['library_dirs'] = get_expanded_list(callback['library_dirs'])
callback['extra_srcs'] = get_expanded_list(callback['extra_srcs'])
# compiled callback shared library # compiled callback shared library
libext = '.dylib' if sys.platform == 'darwin' else '.so' libext = '.dylib' if sys.platform == 'darwin' else '.so'
add_path_to_ld_library_path(str(self.output_dir), self.env) add_path_to_ld_library_path(str(self.output_dir), self.env)
self.callback['dylib'] = self.output_dir / ('libcb_%(name)s' % self.callback + libext) self.callback['dylib'] = self.output_dir / ('libcb_%(name)s' % self.callback + libext)
# TODO: refactor this!
for d in self.callback['library_dirs']: for d in self.callback['library_dirs']:
p = Path(expandenv(d, self.env)) add_path_to_ld_library_path(d, self.env)
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
add_path_to_ld_library_path(str(p), self.env)
@staticmethod @staticmethod
def from_config_dict(name, conf_d, conf_dir=None): def from_config_dict(name, conf_d, conf_dir=None):
...@@ -113,6 +119,10 @@ class TaskSet: ...@@ -113,6 +119,10 @@ class TaskSet:
d['library_dirs'] = [] # default to [] d['library_dirs'] = [] # default to []
if 'libraries' not in d or d['libraries'] is None: if 'libraries' not in d or d['libraries'] is None:
d['libraries'] = [] # default to [] d['libraries'] = [] # default to []
if 'extra_srcs' not in d or d['extra_srcs'] is None:
d['extra_srcs'] = [] # default to []
if 'flags' not in d or d['flags'] is None:
d['flags'] = [] # default to []
conf_d['callback'] = d conf_d['callback'] = d
# add comparison # add comparison
...@@ -220,36 +230,23 @@ class TaskSet: ...@@ -220,36 +230,23 @@ class TaskSet:
cmd.extend(['-shared', '-fPIC']) cmd.extend(['-shared', '-fPIC'])
# include_dirs # include_dirs
for d in self.callback['include_dirs']: cmd.extend(map(lambda s: '-I' + s, self.callback['include_dirs']))
p = Path(expandenv(d, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append('-I%s' % p)
# library_dirs # library_dirs
for d in self.callback['library_dirs']: cmd.extend(map(lambda s: '-L' + s, self.callback['library_dirs']))
p = Path(expandenv(d, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append('-L%s' % p)
# libraries # libraries
for lib in self.callback['libraries']: cmd.extend(map(lambda s: '-l' + s, self.callback['libraries']))
cmd.append('-l%s' % lib)
# flags # flags
cmd.extend(self.callback.get('flags', [])) cmd.extend(self.callback['flags'])
# output # output
cmd.extend(['-o', self.callback['dylib']]) cmd.extend(['-o', self.callback['dylib']])
# source # source
cmd.append(CALLBACKS_DIR / ('cb_%(name)s.c' % self.callback)) cmd.append(CALLBACKS_DIR / ('cb_%(name)s.c' % self.callback))
for src in self.callback.get('extra_srcs', []): cmd.extend(self.callback['extra_srcs'])
p = Path(expandenv(src, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append(p)
run_in_subproc(cmd, self.env) run_in_subproc(cmd, self.env)
......
...@@ -15,7 +15,8 @@ tar xf libpfm-4.8.0.tar.gz ...@@ -15,7 +15,8 @@ tar xf libpfm-4.8.0.tar.gz
cd libpfm-4.8.0 cd libpfm-4.8.0
sudo make PREFIX=$DEST_DIR install sudo make PREFIX=$DEST_DIR install
sudo chown -R $USER:$USER $DEST_DIR sudo chown -R $USER:$USER $DEST_DIR
cp -r perf_examples $DEST_DIR mkdir $DEST_DIR/util
cp perf_examples/perf_util.h perf_examples/perf_util.c $DEST_DIR/util
cd .. cd ..
rm libpfm-4.8.0.tar.gz rm libpfm-4.8.0.tar.gz
# rm -rf libpfm-4.8.0 # rm -rf libpfm-4.8.0
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment