Esempio n. 1
0
def test_write_once_persistent_dict_synchronization():
    try:
        tmpdir = tempfile.mkdtemp()
        pdict1 = WriteOncePersistentDict("pytools-test", container_dir=tmpdir)
        pdict2 = WriteOncePersistentDict("pytools-test", container_dir=tmpdir)

        # check lookup
        pdict1[1] = 0
        assert pdict2[1] == 0

        # check updating
        with pytest.raises(ReadOnlyEntryError):
            pdict2[1] = 1

    finally:
        shutil.rmtree(tmpdir)
Esempio n. 2
0
def test_write_once_persistent_dict_lru_policy():
    try:
        tmpdir = tempfile.mkdtemp()
        pdict = WriteOncePersistentDict("pytools-test",
                                        container_dir=tmpdir,
                                        in_mem_cache_size=3)

        pdict[1] = PDictTestingKeyOrValue(1)
        pdict[2] = PDictTestingKeyOrValue(2)
        pdict[3] = PDictTestingKeyOrValue(3)
        pdict[4] = PDictTestingKeyOrValue(4)

        val1 = pdict.fetch(1)

        assert pdict.fetch(1) is val1
        pdict.fetch(2)
        assert pdict.fetch(1) is val1
        pdict.fetch(2)
        pdict.fetch(3)
        assert pdict.fetch(1) is val1
        pdict.fetch(2)
        pdict.fetch(3)
        pdict.fetch(2)
        assert pdict.fetch(1) is val1
        pdict.fetch(2)
        pdict.fetch(3)
        pdict.fetch(4)
        assert pdict.fetch(1) is not val1

    finally:
        shutil.rmtree(tmpdir)
Esempio n. 3
0
def test_write_once_persistent_dict_storage_and_lookup(in_mem_cache_size):
    try:
        tmpdir = tempfile.mkdtemp()
        pdict = WriteOncePersistentDict("pytools-test",
                                        container_dir=tmpdir,
                                        in_mem_cache_size=in_mem_cache_size)

        # check lookup
        pdict[0] = 1
        assert pdict[0] == 1
        # do two lookups to test the cache
        assert pdict[0] == 1

        # check updating
        with pytest.raises(ReadOnlyEntryError):
            pdict[0] = 2

        # check not found
        with pytest.raises(NoSuchEntryError):
            pdict.fetch(1)

        # check store_if_not_present
        pdict.store_if_not_present(0, 2)
        assert pdict[0] == 1
        pdict.store_if_not_present(1, 1)
        assert pdict[1] == 1

    finally:
        shutil.rmtree(tmpdir)
Esempio n. 4
0
def test_write_once_persistent_dict_clear():
    try:
        tmpdir = tempfile.mkdtemp()
        pdict = WriteOncePersistentDict("pytools-test", container_dir=tmpdir)

        pdict[0] = 1
        pdict.fetch(0)
        pdict.clear()

        with pytest.raises(NoSuchEntryError):
            pdict.fetch(0)
    finally:
        shutil.rmtree(tmpdir)
Esempio n. 5
0
def test_write_once_persistent_dict_cache_collisions():
    try:
        tmpdir = tempfile.mkdtemp()
        pdict = WriteOncePersistentDict("pytools-test", container_dir=tmpdir)

        key1 = PDictTestingKeyOrValue(1, hash_key=0)
        key2 = PDictTestingKeyOrValue(2, hash_key=0)
        pdict[key1] = 1

        # check lookup
        with pytest.warns(CollisionWarning):
            with pytest.raises(NoSuchEntryError):
                pdict.fetch(key2)

        # check update
        with pytest.raises(ReadOnlyEntryError):
            pdict[key2] = 1

        # check store_if_not_present
        pdict.store_if_not_present(key2, 2)
        assert pdict[key1] == 1

    finally:
        shutil.rmtree(tmpdir)
Esempio n. 6
0
"""

import os
from sumpy.p2p import P2P, P2PFromCSR
from sumpy.p2e import P2EFromSingleBox, P2EFromCSR
from sumpy.e2p import E2PFromSingleBox, E2PFromCSR
from sumpy.e2e import E2EFromCSR, E2EFromChildren, E2EFromParent
from sumpy.version import VERSION_TEXT
from pytools.persistent_dict import WriteOncePersistentDict

__all__ = [
    "P2P", "P2PFromCSR", "P2EFromSingleBox", "P2EFromCSR", "E2PFromSingleBox",
    "E2PFromCSR", "E2EFromCSR", "E2EFromChildren", "E2EFromParent"
]

code_cache = WriteOncePersistentDict("sumpy-code-cache-v6-" + VERSION_TEXT)

# {{{ cache control

CACHING_ENABLED = True

CACHING_ENABLED = ("SUMPY_NO_CACHE" not in os.environ
                   and "CG_NO_CACHE" not in os.environ)


def set_caching_enabled(flag):
    """Set whether :mod:`loopy` is allowed to use disk caching for its various
    code generation stages.
    """
    global CACHING_ENABLED
    CACHING_ENABLED = flag
Esempio n. 7
0
    # {{{ generate set_args

    gen("")
    gen("def set_args(%s):" % (", ".join(["self"] + arg_names)))

    with Indentation(gen):
        add_local_imports(gen)
        gen.extend(err_handler)

    # }}}

    return gen.get_picklable_module(), enqueue_name


invoker_cache = WriteOncePersistentDict("pyopencl-invoker-cache-v1",
                                        key_builder=_NumpyTypesKeyBuilder())


def generate_enqueue_and_set_args(function_name, num_passed_args, num_cl_args,
                                  scalar_arg_dtypes, work_around_arg_count_bug,
                                  warn_about_arg_count_bug):

    cache_key = (function_name, num_passed_args, num_cl_args,
                 scalar_arg_dtypes, work_around_arg_count_bug,
                 warn_about_arg_count_bug)

    from_cache = False

    try:
        result = invoker_cache[cache_key]
        from_cache = True
Esempio n. 8
0
        result = self.buf_var
        if access_subscript:
            result = result.index(tuple(access_subscript))

        # Can't possibly be nested, but recurse anyway to
        # make sure substitution rules referenced below here
        # do not get thrown away.
        self.rec(result, expn_state.copy(arg_context={}))

        return result

# }}}


buffer_array_cache = WriteOncePersistentDict(
        "loopy-buffer-array-cache-"+DATA_MODEL_VERSION,
        key_builder=LoopyKeyBuilder())


# Adding an argument? also add something to the cache_key below.
def buffer_array(kernel, var_name, buffer_inames, init_expression=None,
        store_expression=None, within=None, default_tag="l.auto",
        temporary_scope=None, temporary_is_local=None,
        fetch_bounding_box=False):
    """Replace accesses to *var_name* with ones to a temporary, which is
    created and acts as a buffer. To perform this transformation, the access
    footprint to *var_name* is determined and a temporary of a suitable
    :class:`loopy.AddressSpace` and shape is created.

    By default, the value of the buffered cells in *var_name* are read prior to
    any (read/write) use, and the modified values are written out after use has
Esempio n. 9
0
        from loopy.codegen.result import merge_codegen_results
        return merge_codegen_results(self, result)

    @property
    def ast_builder(self):
        if self.is_generating_device_code:
            return self.kernel.target.get_device_ast_builder()
        else:
            return self.kernel.target.get_host_ast_builder()


# }}}

code_gen_cache = WriteOncePersistentDict("loopy-code-gen-cache-v3-" +
                                         DATA_MODEL_VERSION,
                                         key_builder=LoopyKeyBuilder())


class PreambleInfo(ImmutableRecord):
    """
    .. attribute:: kernel
    .. attribute:: seen_dtypes
    .. attribute:: seen_functions
    .. attribute:: seen_atomic_dtypes
    .. attribute:: codegen_state
    """


# {{{ main code generation entrypoint
Esempio n. 10
0
# }}}

# }}}


class _KernelInfo(ImmutableRecord):
    pass


class _Kernels:
    pass


typed_and_scheduled_cache = WriteOncePersistentDict(
        "loopy-typed-and-scheduled-cache-v1-"+DATA_MODEL_VERSION,
        key_builder=LoopyKeyBuilder())


invoker_cache = WriteOncePersistentDict(
        "loopy-invoker-cache-v10-"+DATA_MODEL_VERSION,
        key_builder=LoopyKeyBuilder())


# {{{ kernel executor

class KernelExecutorBase:
    """An object connecting a kernel to a :class:`pyopencl.Context`
    for execution.

    .. automethod:: __init__
Esempio n. 11
0
from volumential.singular_integral_2d import box_quad
from volumential.version import VERSION_TEXT
from volumential.table_manager import NearFieldInteractionTableManager  # noqa: F401
from volumential.nearfield_potential_table import (  # noqa: F401
    NearFieldInteractionTable, )

volumential_version = VERSION_TEXT

__all__ = ["volumential_version", "box_quad", "nearfield_potential_table"]

__doc__ = """
:mod:`volumential` can compute 2/3D volume potentials using FMM.
"""

code_cache = WriteOncePersistentDict("volumential-code-cache-v0-" +
                                     VERSION_TEXT)

# {{{ optimization control

OPT_ENABLED = True

OPT_ENABLED = "VOLUMENTIAL_NO_OPT" not in os.environ


def set_optimization_enabled(flag):
    """Set whether the :mod:`loopy` kernels should be optimized."""
    global OPT_ENABLED
    OPT_ENABLED = flag


# }}}