Пример #1
0
modes = {
    'basic': BasicRewriter,
    'advanced': DevitoRewriter,
    'advanced-safemath': DevitoRewriterSafeMath,
    'speculative': DevitoSpeculativeRewriter
}
"""The DLE transformation modes."""

default_options = {
    'blockinner': False,
    'blockshape': None,
    'blockalways': False
}
"""Default values for the various optimization options."""

configuration.add('dle', 'advanced', list(modes))
configuration.add('dle_options',
                  ';'.join('%s:%s' % (k, v) for k, v in default_options.items()),
                  list(default_options))


def transform(node, mode='basic', options=None):
    """
    Transform Iteration/Expression trees to generate highly optimized C code.

    :param node: The Iteration/Expression tree to be transformed, or an iterable
                 of Iteration/Expression trees.
    :param mode: Drive the tree transformation. ``mode`` is a string indicating
                 a certain optimization pipeline.
    :param options: A dictionary with additional information to drive the DLE.
Пример #2
0
from __future__ import absolute_import
import weakref
import abc

import numpy as np
import sympy
from operator import mul
from functools import reduce

from devito.arguments import ScalarArgProvider, ArrayArgProvider, ObjectArgProvider
from devito.parameters import configuration
from devito.tools import single_or

__all__ = ['Symbol', 'Indexed']

configuration.add('first_touch', 0, [0, 1], lambda i: bool(i))

# This cache stores a reference to each created data object
# so that we may re-create equivalent symbols during symbolic
# manipulation with the correct shapes, pointers, etc.
_SymbolCache = {}


class Basic(object):
    """
    Base class for API objects, used to build and run :class:`Operator`s.

    There are two main types of objects: symbolic and generic. Symbolic objects
    may carry data, and are used to build equations. Generic objects are used
    to represent arbitrary data structures. The following diagram outlines the
    top of this hierarchy.
Пример #3
0
                        'Compile log in %s\n'
                        'Compile errors in %s\n' %
                        (e.cmd, e.returncode, logfile, errfile))


# Registry dict for deriving Compiler classes according to the environment variable
# DEVITO_ARCH. Developers should add new compiler classes here.
compiler_registry = {
    'custom': CustomCompiler,
    'gcc': GNUCompiler,
    'gnu': GNUCompiler,
    'gcc-4.9': partial(GNUCompiler, version='4.9'),
    'gcc-5': partial(GNUCompiler, version='5'),
    'gcc-noavx': GNUCompilerNoAVX,
    'gnu-noavx': GNUCompilerNoAVX,
    'clang': ClangCompiler,
    'osx': ClangCompiler,
    'intel': IntelCompiler,
    'icpc': IntelCompiler,
    'icc': IntelCompiler,
    'intel-mic': IntelMICCompiler,
    'mic': IntelMICCompiler,
    'intel-knl': IntelKNLCompiler,
    'knl': IntelKNLCompiler,
}

configuration.add('compiler', 'custom', list(compiler_registry),
                  lambda i: compiler_registry[i]())
configuration.add('openmp', 0, [0, 1], lambda i: bool(i))
configuration.add('debug_compiler', 0, [0, 1], lambda i: bool(i))
Пример #4
0
from devito.dse.manipulation import cross_cluster_cse
from devito.logger import dse_warning
from devito.parameters import configuration
from devito.tools import flatten

__all__ = ['rewrite']

modes = {
    'basic': BasicRewriter,
    'advanced': AdvancedRewriter,
    'speculative': SpeculativeRewriter,
    'aggressive': AggressiveRewriter
}
"""The DSE transformation modes."""

configuration.add('dse', 'advanced', list(modes))


def rewrite(clusters, mode='advanced'):
    """
    Given a sequence of N Clusters, produce a sequence of M Clusters with reduced
    operation count, with M >= N.

    Parameters
    ----------
    clusters : list of Cluster
        The Clusters to be transformed.
    mode : str, optional
        The aggressiveness of the rewrite. Accepted:
        - ``noop``: Do nothing.
        - ``basic``: Apply common sub-expressions elimination.
Пример #5
0
        raise ValueError("Illegal logging level %s" % level)

    if comm is not None and comm.rank != 0:
        logger.removeHandler(stream_handler)
        logger.addHandler(logging.NullHandler())
    else:
        logger.addHandler(stream_handler)
        logger.setLevel(level)


def set_log_noperf():
    """Do not print performance-related messages."""
    logger.setLevel(WARNING)


configuration.add('log_level', 'INFO', list(logger_registry),
                  lambda i: set_log_level(i))


class silencio(object):
    """
    Decorator to temporarily change log levels.
    """
    def __init__(self, log_level='WARNING'):
        self.log_level = log_level

    def __call__(self, func, *args, **kwargs):
        @wraps(func)
        def wrapper(*args, **kwargs):
            previous = configuration['log_level']
            configuration['log_level'] = self.log_level
            result = func(*args, **kwargs)
Пример #6
0
        warning("Couldn't set up `%s` profiler; reverting to `advanced`" %
                level)
        profiler = profiler_registry['basic'](name)
        # We expect the `advanced` profiler to always initialize successfully
        assert profiler.initialized
        return profiler


# Set up profiling levels
profiler_registry = {
    'basic': Profiler,
    'advanced': AdvancedProfiler,
    'advisor': AdvisorProfiler
}
configuration.add('profiling',
                  'basic',
                  list(profiler_registry),
                  impacts_jit=False)


def locate_intel_advisor():
    try:
        path = Path(os.environ['ADVISOR_HOME'])
        # Little hack: assuming a 64bit system
        if path.joinpath('bin64').joinpath('advixe-cl').is_file():
            return path
        else:
            warning(
                "Requested `advisor` profiler, but couldn't locate executable")
            return None
    except KeyError:
        warning("Requested `advisor` profiler, but ADVISOR_HOME isn't set")
Пример #7
0
def clear_cache():
    cache.clear_cache()
    gc.collect()

    for key, val in list(_SymbolCache.items()):
        if val() is None:
            del _SymbolCache[key]


from ._version import get_versions  # noqa
__version__ = get_versions()['version']
del get_versions

# Initialize the Devito backend
configuration.add('travis_test', 0, [0, 1], lambda i: bool(i))
configuration.add('autotuning', 'basic', ['none', 'basic', 'aggressive'])
init_configuration()
init_backend(configuration['backend'])


def print_defaults():
    """Print the environment variables accepted by Devito, their default value,
    as well as all of the accepted values."""
    for k, v in env_vars_mapper.items():
        info('%s: %s. Default: %s' %
             (k, configuration._accepted[v], configuration._defaults[v]))


def print_state():
    """Print the current configuration state."""
Пример #8
0
    """
    level = configuration['profiling']
    profiler = profiler_registry[level](name)
    if profiler.initialized:
        return profiler
    else:
        warning("Couldn't set up `%s` profiler; reverting to `basic`" % level)
        profiler = profiler_registry['basic'](name)
        # We expect the `basic` profiler to always initialize successfully
        assert profiler.initialized
        return profiler


# Set up profiling levels
profiler_registry = {'basic': Profiler, 'advisor': AdvisorProfiler}
configuration.add('profiling', 'basic', list(profiler_registry))


def locate_intel_advisor():
    try:
        path = Path(os.environ['ADVISOR_HOME'])
        # Little hack: assuming a 64bit system
        if path.joinpath('bin64').joinpath('advixe-cl').is_file():
            return path
        else:
            warning(
                "Requested `advisor` profiler, but couldn't locate executable")
            return None
    except KeyError:
        warning("Requested `advisor` profiler, but ADVISOR_HOME isn't set")
        return None
Пример #9
0
            # package.
            mod = __import__('devito.%s' % backend, fromlist=['None'])
        except ImportError as e:
            warning('Unable to import backend %s' % backend)
            raise e
    backends[backend] = mod
    _BackendSelector._backend = mod


def initialised_backend():
    """Check whether Devito has been yet initialised."""
    return backends.get_backend() != 'void'


def init_backend(backend):
    """
    Initialise Devito: select the backend and other configuration options.
    """
    current_backend = get_backend()
    if current_backend not in backends_registry:
        raise RuntimeError(
            "Calling init() for a different backend is illegal.")
    if current_backend == 'void':
        try:
            set_backend(backend)
        except (ImportError, RuntimeError):
            raise DevitoError("Couldn't initialize Devito.")


configuration.add('backend', 'core', list(backends_registry))