def show_profile(self, path, tool_name=None): """Shows profile data in the specified file or folder. Args: path (str): Path to the directory containing profile files or MULTI__ directories. tool_name (str): Name of the profile visualization tool to use, e.g. 'pprof'. Returns: int: Return code of the visualization tool. """ LOGGER.debug("Showing profile files at '%s'", path) _, env = super(TauInstallation,self).runtime_config() if tool_name: tools = [tool_name] else: tools = ['paraprof', 'pprof'] for tool in tools: if os.path.isfile(path): cmd = [tool, path] else: cmd = [tool] LOGGER.info("Opening %s in %s", path, tool) retval = util.create_subprocess(cmd, cwd=path, env=env, log=False) if retval == 0: return else: LOGGER.warning("%s failed", tool) if retval != 0: raise ConfigurationError("All visualization or reporting tools failed to open '%s'" % path, "Check Java installation, X11 installation," " network connectivity, and file permissions")
def make_install(self, flags, env, parallel=False): """Invoke `make install`. Changes to `env` are propagated to subsequent steps. Normally there wouldn't be anything after `make install`, but a subclass could change that. Changes to `flags` are not propogated to subsequent steps. Args: flags (list): Command line flags to pass to `make`. env (dict): Environment variables to set before invoking `make`. parallel (bool): If True, pass parallelization flags to `make`. Raises: SoftwarePackageError: Configuration failed. """ assert self.src_prefix LOGGER.debug("Installing %s at '%s' to '%s'", self.name, self.src_prefix, self.install_prefix) flags = list(flags) if parallel: flags += parallel_make_flags() cmd = ['make', 'install'] + flags LOGGER.info("Installing %s...", self.name) if util.create_subprocess(cmd, cwd=self.src_prefix, env=env, stdout=False): raise SoftwarePackageError('%s installation failed' % self.name) # Some systems use lib64 instead of lib if os.path.isdir(self.lib_path+'64') and not os.path.isdir(self.lib_path): os.symlink(self.lib_path+'64', self.lib_path)
def compile(self, compiler, compiler_args): """Executes a compilation command. Sets TAU environment variables and configures TAU compiler wrapper command line arguments to match specified configuration, then executes the compiler command. Args: compiler (Compiler): A compiler command. compiler_args (list): Compiler command line arguments. Raises: ConfigurationError: Compilation failed. Returns: int: Compiler return value (always 0 if no exception raised). """ opts, env = self.compiletime_config() compiler_cmd = self.get_compiler_command(compiler) cmd = [compiler_cmd] + opts + compiler_args tau_env_opts = ['%s=%s' % item for item in env.iteritems() if item[0].startswith('TAU_')] LOGGER.info('\n'.join(tau_env_opts)) LOGGER.info(' '.join(cmd)) retval = util.create_subprocess(cmd, env=env, stdout=True) if retval != 0: raise ConfigurationError("TAU was unable to build the application.", "See detailed output at the end of in '%s'" % logger.LOG_FILE) return retval
def configure(self, flags, env): """Invoke `configure`. Changes to `env` are propagated to subsequent steps, i.e. `make`. Changes to `flags` are not propogated to subsequent steps. Args: flags (list): Command line flags to pass to `configure`. env (dict): Environment variables to set before invoking `configure`. Raises: SoftwarePackageError: Configuration failed. """ assert self.src_prefix LOGGER.debug("Configuring %s at '%s'", self.name, self.src_prefix) flags = list(flags) # Prepare configuration flags flags += ['--prefix=%s' % self.install_prefix] compiler_env = {'GNU': {'CC': 'gcc', 'CXX': 'g++'}, 'Intel': {'CC': 'icc', 'CXX': 'icpc'}, 'PGI': {'CC': 'pgcc', 'CXX': 'pgCC'}} try: env.update(compiler_env[self.compilers[CC_ROLE].info.family]) except KeyError: LOGGER.info("Allowing %s to select compilers", self.name) cmd = ['./configure'] + flags LOGGER.info("Configuring %s...", self.name) if util.create_subprocess(cmd, cwd=self.src_prefix, env=env, stdout=False): raise SoftwarePackageError('%s configure failed' % self.name)
def configure(self, flags, env): family_flags = {GNU_COMPILERS.name: '-GNU', INTEL_COMPILERS.name: '-icpc', PGI_COMPILERS.name: '-pgCC'} family = self.compilers[CXX_ROLE].info.family compiler_flag = family_flags.get(family.name, '') prefix_flag = '-prefix=%s' % self.install_prefix cmd = ['./configure', prefix_flag, compiler_flag] LOGGER.info("Configuring PDT for %s compilers...", family) if util.create_subprocess(cmd, cwd=self.src_prefix, stdout=False): raise SoftwarePackageError('PDT configure failed')
def make_install(self): """Installs TAU to ``self.install_prefix``. Executes 'make install' to build and install TAU. Raises: SoftwarePackageError: 'make install' failed. """ cmd = ['make', 'install'] + parallel_make_flags() LOGGER.info('Compiling and installing TAU...') if util.create_subprocess(cmd, cwd=self.src_prefix, stdout=False): raise SoftwarePackageError('TAU compilation/installation failed')
def execute_command(self, expr, cmd, cwd, env): """Execute a command as part of an experiment trial. Creates a new subprocess for the command and checks for TAU data files when the subprocess exits. Args: expr (Experiment): Experiment data. cmd (str): Command to profile, with command line arguments. cwd (str): Working directory to perform trial in. env (dict): Environment variables to set before performing the trial. Returns: int: Subprocess return code. """ cmd_str = ' '.join(cmd) LOGGER.info(cmd_str) try: retval = util.create_subprocess(cmd, cwd=cwd, env=env) except OSError as err: target = expr.populate('target') errno_hint = {errno.EPERM: "Check filesystem permissions", errno.ENOENT: "Check paths and command line arguments", errno.ENOEXEC: "Check that this host supports '%s'" % target['host_arch']} raise TrialError("Couldn't execute %s: %s" % (cmd_str, err), errno_hint.get(err.errno, None)) if retval: LOGGER.warning("Return code %d from '%s'", retval, cmd_str) measurement = expr.populate('measurement') if measurement['profile']: profiles = self.profile_files() if profiles: LOGGER.info("Trial produced %d profile files.", len(profiles)) elif retval != 0: raise TrialError("Program died without producing performance data.", "Verify that the right input parameters were specified.", "Check the program output for error messages.", "Does the selected application configuration correctly describe this program?", "Does the selected measurement configuration specifiy the right measurement methods?", "Does the selected target configuration match the runtime environment?") else: raise TrialError("Application completed successfuly but did not produce any performance data.") return retval
def make(self, flags, env, parallel=True): """Invoke `make`. Changes to `env` are propagated to subsequent steps, i.e. `make install`. Changes to `flags` are not propogated to subsequent steps. Args: flags (list): Command line flags to pass to `make`. env (dict): Environment variables to set before invoking `make`. parallel (bool): If True, pass parallelization flags to `make`. Raises: SoftwarePackageError: Compilation failed. """ assert self.src_prefix LOGGER.debug("Making %s at '%s'", self.name, self.src_prefix) flags = list(flags) if parallel: flags += parallel_make_flags() cmd = ['make'] + flags LOGGER.info("Compiling %s...", self.name) if util.create_subprocess(cmd, cwd=self.src_prefix, env=env, stdout=False): raise SoftwarePackageError('%s compilation failed' % self.name)
def configure(self): """Configures TAU Executes TAU's configuration script with appropriate arguments to support the specified configuration. Raises: SoftwareConfigurationError: TAU's configure script failed. """ # TAU's configure script does a really bad job of detecting MPI settings # so set up mpiinc, mpilib, mpilibrary when we have that information mpiinc = None mpilib = None mpilibrary = None if self.mpi_support: # TAU's configure script does a really bad job detecting the wrapped compiler command # so don't even bother trying. Pass as much of this as we can and hope for the best. cc_command = self.compilers[MPI_CC_ROLE].wrapped.info.command cxx_command = self.compilers[MPI_CXX_ROLE].wrapped.info.command fc_family = self.compilers[MPI_FC_ROLE].wrapped.info.family if self.mpi_include_path: # Unfortunately, TAU's configure script can only accept one path on -mpiinc # and it expects the compiler's include path argument (e.g. "-I") to be omitted for path in self.mpi_include_path: if os.path.exists(os.path.join(path, 'mpi.h')): mpiinc = path break if not mpiinc: raise ConfigurationError("mpi.h not found on MPI include path: %s" % self.mpi_include_path) if self.mpi_library_path: # Unfortunately, TAU's configure script can only accept one path on -mpilib # and it expects the compiler's include path argument (e.g. "-L") to be omitted for path in self.mpi_library_path: if glob.glob(os.path.join(path, 'libmpi*')): mpilib = path break if self.mpi_libraries: # Multiple MPI libraries can be given but only if they're separated by a '#' symbol # and the compiler's library linking flag (e.g. '-l') must be included link_library_flag = self.compilers[CC_ROLE].info.family.link_library_flags[0] mpilibrary = '#'.join(["%s%s" % (link_library_flag, library) for library in self.mpi_libraries]) else: # TAU's configure script can't cope with compiler absolute paths or compiler names that # don't exactly match what it expects. Use `info.command` instead of `command` to work # around these problems e.g. 'gcc-4.9' becomes 'gcc' cc_command = self.compilers[CC_ROLE].info.command cxx_command = self.compilers[CXX_ROLE].info.command fc_family = self.compilers[FC_ROLE].info.family # TAU's configure script can't detect Fortran compiler from the compiler # command so translate Fortran compiler command into TAU's funkey magic words magic_map = {GNU_COMPILERS: 'gfortran', INTEL_COMPILERS: 'intel', PGI_COMPILERS: 'pgi', SYSTEM_COMPILERS: 'ftn', SYSTEM_MPI_COMPILERS: 'mpif90', INTEL_MPI_COMPILERS: 'mpiifort'} try: fortran_magic = magic_map[fc_family] except KeyError: raise InternalError("Unknown compiler family for Fortran: '%s'" % fc_family) pdt_cxx_command = self.pdt.compilers[CXX_ROLE].info.command if self.pdt else '' flags = [ flag for flag in ['-prefix=%s' % self.install_prefix, '-arch=%s' % self.arch, '-cc=%s' % cc_command, '-c++=%s' % cxx_command, '-pdt_c++=%s' % pdt_cxx_command, '-fortran=%s' % fortran_magic, '-pdt=%s' % self.pdt.install_prefix if self.pdt else '', '-bfd=%s' % self.binutils.install_prefix if self.binutils else '', '-papi=%s' % self.papi.install_prefix if self.papi else '', '-unwind=%s' % self.libunwind.install_prefix if self.libunwind else '', '-pthread' if self.pthreads_support else '', '-mpi' if self.mpi_support else '', '-mpiinc=%s' % mpiinc if mpiinc else '', '-mpilib=%s' % mpilib if mpilib else '', '-mpilibrary=%s' % mpilibrary if mpilibrary else '', '-cuda=%s' % self.cuda_prefix if self.cuda_prefix else '', '-opencl=%s' % self.opencl_prefix if self.opencl_prefix else '' ] if flag] if self.openmp_support: flags.append('-openmp') if self.measure_openmp == 'ompt': flags.append('-ompt') elif self.measure_openmp == 'opari': flags.append('-opari') cmd = ['./configure'] + flags LOGGER.info("Configuring TAU...") if util.create_subprocess(cmd, cwd=self.src_prefix, stdout=False): raise SoftwarePackageError('TAU configure failed')