Skip to content
Snippets Groups Projects
Commit 49298e64 authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Implement a first draft of a heuristic model

parent c5812a92
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ class PerftoolOptionsArray(ImmutableRecord): ...@@ -55,7 +55,7 @@ class PerftoolOptionsArray(ImmutableRecord):
fastdg = PerftoolOption(default=False, helpstr="Use FastDGGridOperator from PDELab.") fastdg = PerftoolOption(default=False, helpstr="Use FastDGGridOperator from PDELab.")
sumfact = PerftoolOption(default=False, helpstr="Use sumfactorization") sumfact = PerftoolOption(default=False, helpstr="Use sumfactorization")
vectorization_quadloop = PerftoolOption(default=False, helpstr="whether to generate code with explicit vectorization") vectorization_quadloop = PerftoolOption(default=False, helpstr="whether to generate code with explicit vectorization")
vectorization_strategy = PerftoolOption(default="none", helpstr="The identifier of the vectorization cost model. Possible values: none|explicit") vectorization_strategy = PerftoolOption(default="none", helpstr="The identifier of the vectorization cost model. Possible values: none|explicit|model")
vectorization_horizontal = PerftoolOption(default=None, helpstr="an explicit value for horizontal vectorization read by the 'explicit' strategy") vectorization_horizontal = PerftoolOption(default=None, helpstr="an explicit value for horizontal vectorization read by the 'explicit' strategy")
vectorization_vertical = PerftoolOption(default=None, helpstr="an explicit value for vertical vectorization read by the 'explicit' strategy") vectorization_vertical = PerftoolOption(default=None, helpstr="an explicit value for vertical vectorization read by the 'explicit' strategy")
vectorization_padding = PerftoolOption(default=None, helpstr="an explicit value for the allowed padding in vectorization") vectorization_padding = PerftoolOption(default=None, helpstr="an explicit value for the allowed padding in vectorization")
......
...@@ -333,7 +333,7 @@ class SumfactKernel(SumfactKernelBase, ImmutableRecord, prim.Variable): ...@@ -333,7 +333,7 @@ class SumfactKernel(SumfactKernelBase, ImmutableRecord, prim.Variable):
def operations(self): def operations(self):
""" The total number of floating point operations for the kernel """ The total number of floating point operations for the kernel
to be carried out """ to be carried out """
from dune.perftool.sumfact.tabulation import flop_cost from dune.perftool.sumfact.permutation import flop_cost
return flop_cost(self.matrix_sequence) return flop_cost(self.matrix_sequence)
...@@ -642,5 +642,5 @@ class VectorizedSumfactKernel(SumfactKernelBase, ImmutableRecord, prim.Variable) ...@@ -642,5 +642,5 @@ class VectorizedSumfactKernel(SumfactKernelBase, ImmutableRecord, prim.Variable)
def operations(self): def operations(self):
""" The total number of floating point operations for the kernel """ The total number of floating point operations for the kernel
to be carried out """ to be carried out """
from dune.perftool.sumfact.tabulation import flop_cost from dune.perftool.sumfact.permutation import flop_cost
return flop_cost(self.matrix_sequence) return flop_cost(self.matrix_sequence)
...@@ -26,6 +26,7 @@ from frozendict import frozendict ...@@ -26,6 +26,7 @@ from frozendict import frozendict
import itertools as it import itertools as it
import loopy as lp import loopy as lp
import numpy as np import numpy as np
import math
@generator_factory(item_tags=("vecinfo", "dryrundata"), cache_key_generator=lambda o, n: o) @generator_factory(item_tags=("vecinfo", "dryrundata"), cache_key_generator=lambda o, n: o)
...@@ -51,6 +52,22 @@ def attach_vectorization_info(sf): ...@@ -51,6 +52,22 @@ def attach_vectorization_info(sf):
return _cache_vectorization_info(sf, None) return _cache_vectorization_info(sf, None)
def position_penalty_factor(sf):
if isinstance(sf, SumfactKernel):
return 1
else:
return 1 + sum(abs(sf.kernels[i].position_priority - i) if sf.kernels[i].position_priority is not None else 0 for i in range(sf.length))
@backend(interface="vectorization_strategy", name="model")
def costmodel(sf):
# Penalize vertical vectorization
vertical_penalty = 1 + math.log(sf.vertical_width)
# Return total operations
return sf.operations * position_penalty_factor(sf) * vertical_penalty
@backend(interface="vectorization_strategy", name="explicit") @backend(interface="vectorization_strategy", name="explicit")
def explicit_costfunction(sf): def explicit_costfunction(sf):
# Read the explicitly set values for horizontal and vertical vectorization # Read the explicitly set values for horizontal and vertical vectorization
...@@ -66,8 +83,7 @@ def explicit_costfunction(sf): ...@@ -66,8 +83,7 @@ def explicit_costfunction(sf):
if sf.horizontal_width == horizontal and sf.vertical_width == vertical: if sf.horizontal_width == horizontal and sf.vertical_width == vertical:
# Penalize position mapping # Penalize position mapping
penalty = sum(abs(sf.kernels[i].position_priority - i) if sf.kernels[i].position_priority is not None else 0 for i in range(sf.length)) return position_penalty_factor(sf)
return 1 + penalty
else: else:
return 1000000000000 return 1000000000000
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment