From c3866d3d6482638b9c44a295c8e5bebe75602335 Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Mon, 3 Apr 2017 10:24:45 +0200 Subject: [PATCH] Remove underscore from names in sumfact permutation --- python/dune/perftool/sumfact/permutation.py | 24 ++++++++++----------- python/dune/perftool/sumfact/realization.py | 8 +++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/python/dune/perftool/sumfact/permutation.py b/python/dune/perftool/sumfact/permutation.py index a377be66..18b34331 100644 --- a/python/dune/perftool/sumfact/permutation.py +++ b/python/dune/perftool/sumfact/permutation.py @@ -1,13 +1,9 @@ """ Permute sum factorization kernels """ -# TODO! -# * get rid of the underscores in names -# * Pass the entire kernel object into the strategy thing - import itertools -def _sf_permutation_heuristic(permutations, stage): +def sumfact_permutation_heuristic(permutations, stage): """Heuristic to choose a permutation - Stage 1: Pick the permutation where in permutations[1:] most @@ -30,7 +26,7 @@ def _sf_permutation_heuristic(permutations, stage): return perm -def _sf_flop_cost(a_matrices): +def flop_cost(a_matrices): """Computational cost of sumfactorization with this list of a_matrices """ cost = 0 @@ -45,12 +41,16 @@ def _sf_flop_cost(a_matrices): return cost -def _sf_permutation_strategy(a_matrices, stage): +def sumfact_permutation_strategy(sf): """Choose permutation of a_matrices list based on computational cost Note: If there are multiple permutations with the same cost a heuristic is used to pick one. """ + # Extract information from the SumfactKernel object + a_matrices = sf.a_matrices + stage = sf.stage + # Combine permutation and a_matrices list perm = [i for i, _ in enumerate(a_matrices)] perm_a_matrices = zip(perm, a_matrices) @@ -59,7 +59,7 @@ def _sf_permutation_strategy(a_matrices, stage): perm_cost = [] for permutation in itertools.permutations(perm_a_matrices): perm, series = zip(*permutation) - cost = _sf_flop_cost(series) + cost = flop_cost(series) perm_cost.append((perm, cost)) # Find minimal cost and all permutations with that cost @@ -67,19 +67,19 @@ def _sf_permutation_strategy(a_matrices, stage): minimal_cost = min(costs) minimal_cost_permutations = [p[0] for p in perm_cost if p[1] == minimal_cost] - # Use heuristic to pic one of the minimal cost permutations - perm = _sf_permutation_heuristic(minimal_cost_permutations, stage) + # Use heuristic to pick one of the minimal cost permutations + perm = sumfact_permutation_heuristic(minimal_cost_permutations, stage) return perm -def _permute_forward(t, perm): +def permute_forward(t, perm): tmp = [] for pos in perm: tmp.append(t[pos]) return tuple(tmp) -def _permute_backward(t, perm): +def permute_backward(t, perm): tmp = [None] * len(t) for i, pos in enumerate(perm): tmp[pos] = t[i] diff --git a/python/dune/perftool/sumfact/realization.py b/python/dune/perftool/sumfact/realization.py index 8fca0bd6..51356802 100644 --- a/python/dune/perftool/sumfact/realization.py +++ b/python/dune/perftool/sumfact/realization.py @@ -21,9 +21,9 @@ from dune.perftool.pdelab.geometry import world_dimension from dune.perftool.pdelab.spaces import name_lfs, name_lfs_bound from dune.perftool.options import get_option from dune.perftool.pdelab.signatures import assembler_routine_name -from dune.perftool.sumfact.permutation import (_sf_permutation_strategy, - _permute_backward, - _permute_forward, +from dune.perftool.sumfact.permutation import (sumfact_permutation_strategy, + permute_backward, + permute_forward, ) from dune.perftool.sumfact.vectorization import attach_vectorization_info from dune.perftool.sumfact.sumfact import sumfact_iname @@ -114,7 +114,7 @@ def _realize_sum_factorization_kernel(sf): # face. # # Rule of thumb: small m's early and large n's late. - perm = _sf_permutation_strategy(sf.a_matrices, sf.stage) + perm = sumfact_permutation_strategy(sf) # Permute a_matrices a_matrices = _permute_forward(sf.a_matrices, perm) -- GitLab