From 2c838ccbb15953584d7bc9febffb35ec393d315c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 27 Aug 2017 00:32:36 -0500 Subject: [PATCH 1/4] Remove derivatives in translation operators to increase effectiveness of translation operator caching --- sumpy/e2e.py | 16 ++++++++++++++++ sumpy/e2p.py | 14 +++++++++----- sumpy/expansion/__init__.py | 4 ++++ sumpy/kernel.py | 5 +++++ sumpy/p2e.py | 4 ++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/sumpy/e2e.py b/sumpy/e2e.py index 66e5e975..bff0f508 100644 --- a/sumpy/e2e.py +++ b/sumpy/e2e.py @@ -63,6 +63,22 @@ class E2EBase(KernelCacheWrapper): if device is None: device = ctx.devices[0] + if src_expansion is tgt_expansion: + from sumpy.kernel import TargetDerivativeRemover, SourceDerivativeRemover + tgt_expansion = src_expansion = src_expansion.with_kernel( + SourceDerivativeRemover()( + TargetDerivativeRemover()(src_expansion.kernel))) + + else: + + from sumpy.kernel import TargetDerivativeRemover, SourceDerivativeRemover + src_expansion = src_expansion.with_kernel( + SourceDerivativeRemover()( + TargetDerivativeRemover()(src_expansion.kernel))) + tgt_expansion = tgt_expansion.with_kernel( + SourceDerivativeRemover()( + TargetDerivativeRemover()(tgt_expansion.kernel))) + self.ctx = ctx self.src_expansion = src_expansion self.tgt_expansion = tgt_expansion diff --git a/sumpy/e2p.py b/sumpy/e2p.py index 6a77a5cc..2b00d9d2 100644 --- a/sumpy/e2p.py +++ b/sumpy/e2p.py @@ -59,6 +59,15 @@ class E2PBase(KernelCacheWrapper): if device is None: device = ctx.devices[0] + from sumpy.kernel import SourceDerivativeRemover + expansion = expansion.with_kernel( + SourceDerivativeRemover()(expansion.kernel)) + + from sumpy.kernel import TargetDerivativeRemover + tdr = TargetDerivativeRemover() + for knl in kernels: + assert tdr(knl) == expansion.kernel + self.ctx = ctx self.expansion = expansion self.kernels = kernels @@ -68,11 +77,6 @@ class E2PBase(KernelCacheWrapper): self.dim = expansion.dim - from sumpy.kernel import TargetDerivativeRemover - tdr = TargetDerivativeRemover() - for knl in kernels: - assert tdr(knl) == expansion.kernel - def get_loopy_insns_and_result_names(self): from sumpy.symbolic import make_sym_vector bvec = make_sym_vector("b", self.dim) diff --git a/sumpy/expansion/__init__.py b/sumpy/expansion/__init__.py index 08754a10..b5096e0c 100644 --- a/sumpy/expansion/__init__.py +++ b/sumpy/expansion/__init__.py @@ -83,6 +83,10 @@ class ExpansionBase(object): # }}} + def with_kernel(self, kernel): + return type(self)(kernel, self.order) + # FIXME: add self.use_rscale once the rscale MR is in + def __len__(self): return len(self.get_coefficient_identifiers()) diff --git a/sumpy/kernel.py b/sumpy/kernel.py index aed3d931..780cf8eb 100644 --- a/sumpy/kernel.py +++ b/sumpy/kernel.py @@ -902,6 +902,11 @@ class TargetDerivativeRemover(AxisTargetDerivativeRemover): return self.rec(kernel.inner_kernel) +class SourceDerivativeRemover(KernelIdentityMapper): + def map_directional_source_derivative(self, kernel): + return self.rec(kernel.inner_kernel) + + class DerivativeCounter(KernelCombineMapper): def combine(self, values): return max(values) diff --git a/sumpy/p2e.py b/sumpy/p2e.py index 6a8fcfa9..b8c60a64 100644 --- a/sumpy/p2e.py +++ b/sumpy/p2e.py @@ -61,6 +61,10 @@ class P2EBase(KernelCacheWrapper): if device is None: device = ctx.devices[0] + from sumpy.kernel import TargetDerivativeRemover + expansion = expansion.with_kernel( + TargetDerivativeRemover()(expansion.kernel)) + self.ctx = ctx self.expansion = expansion self.options = options -- GitLab From 95eb88804d1479fb3c85fc3ccc513526e8a655e7 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 27 Aug 2017 10:41:51 -0500 Subject: [PATCH 2/4] Fix e2p to add removal of source derivatives in kernel-to-expansion comparison --- sumpy/e2p.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sumpy/e2p.py b/sumpy/e2p.py index 2b00d9d2..9a2a8bc1 100644 --- a/sumpy/e2p.py +++ b/sumpy/e2p.py @@ -59,14 +59,14 @@ class E2PBase(KernelCacheWrapper): if device is None: device = ctx.devices[0] - from sumpy.kernel import SourceDerivativeRemover + from sumpy.kernel import SourceDerivativeRemover, TargetDerivativeRemover + sdr = SourceDerivativeRemover() + tdr = TargetDerivativeRemover() expansion = expansion.with_kernel( - SourceDerivativeRemover()(expansion.kernel)) + sdr(expansion.kernel)) - from sumpy.kernel import TargetDerivativeRemover - tdr = TargetDerivativeRemover() for knl in kernels: - assert tdr(knl) == expansion.kernel + assert sdr(tdr(knl)) == expansion.kernel self.ctx = ctx self.expansion = expansion -- GitLab From 6190657f7d478a35c7aa3b362f280becc32bf1c7 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 28 Aug 2017 00:25:32 -0500 Subject: [PATCH 3/4] Fix use of a multipoles view when a local view should have been used --- sumpy/fmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sumpy/fmm.py b/sumpy/fmm.py index b20c9827..77226a9a 100644 --- a/sumpy/fmm.py +++ b/sumpy/fmm.py @@ -517,7 +517,7 @@ class SumpyExpansionWrangler(object): p2l = self.code.p2l(self.level_orders[lev]) target_level_start_ibox, target_local_exps_view = \ - self.multipole_expansions_view(local_exps, lev) + self.local_expansions_view(local_exps, lev) evt, (result,) = p2l( self.level_queues[lev], -- GitLab From 21b3cbefd121790a2ac4ca36dc5a86edd31e6ba3 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 28 Aug 2017 10:25:13 -0500 Subject: [PATCH 4/4] Make test_sumpy_fmm deterministic --- test/test_fmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fmm.py b/test/test_fmm.py index 0d8f36d8..c1df96a6 100644 --- a/test/test_fmm.py +++ b/test/test_fmm.py @@ -169,7 +169,7 @@ def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): # }}} from pyopencl.clrandom import PhiloxGenerator - rng = PhiloxGenerator(ctx) + rng = PhiloxGenerator(ctx, seed=44) weights = rng.uniform(queue, nsources, dtype=np.float64) logger.info("computing direct (reference) result") -- GitLab