def clusterize(exprs): """ Turn a sequence of LoweredEqs into a sequence of Clusters. """ # Initialization clusters = [Cluster(e, e.ispace, e.dspace) for e in exprs] # Setup the IterationSpaces based on data dependence analysis clusters = Schedule().process(clusters) # Handle ConditionalDimensions clusters = guard(clusters) # Determine relevant computational properties (e.g., parallelism) clusters = analyze(clusters) return ClusterGroup(clusters)
def clusterize(exprs): """ Turn a sequence of LoweredEqs into a sequence of Clusters. """ # Initialization clusters = [Cluster(e, e.ispace, e.dspace) for e in exprs] # Compute a topological ordering that honours flow- and anti-dependences clusters = Toposort().process(clusters) # Setup the IterationSpaces based on data dependence analysis clusters = Schedule().process(clusters) # Introduce conditional Clusters clusters = guard(clusters) # Determine relevant computational properties (e.g., parallelism) clusters = analyze(clusters) return ClusterGroup(clusters)
def optimize(clusters, dse_mode): """ Optimize a topologically-ordered sequence of Clusters by applying the following transformations: * [cross-cluster] Fusion * [intra-cluster] Several flop-reduction passes via the DSE * [cross-cluster] Lifting * [cross-cluster] Scalarization * [cross-cluster] Arrays Elimination """ # To create temporaries counter = generator() template = lambda: "r%d" % counter() # Toposort+Fusion (the former to expose more fusion opportunities) clusters = Toposort().process(clusters) clusters = fuse(clusters) # Flop reduction via the DSE from devito.dse import rewrite clusters = rewrite(clusters, template, mode=dse_mode) # Lifting clusters = Lift().process(clusters) # Lifting may create fusion opportunities clusters = fuse(clusters) # Fusion may create opportunities to eliminate Arrays (thus shrinking the # working set) if these store identical expressions clusters = eliminate_arrays(clusters, template) # Fusion may create scalarization opportunities clusters = scalarize(clusters, template) # Determine computational properties (e.g., parallelism) that will be # necessary for the later passes clusters = analyze(clusters) return ClusterGroup(clusters)