Refactor: Run SymPy expression simplification before dependency resolution
This commit is contained in:
parent
070dbf9dd7
commit
5f4efb740c
2 changed files with 26 additions and 12 deletions
|
|
@ -7,6 +7,7 @@ from post import (
|
|||
CompilationContext,
|
||||
ParserStage,
|
||||
DerivativeExpansionStage,
|
||||
SympySimplificationStage,
|
||||
DependencyResolutionStage,
|
||||
SympyOptimizationStage,
|
||||
FortranProgramWriter,
|
||||
|
|
@ -74,11 +75,11 @@ class VersionInfo(object):
|
|||
|
||||
|
||||
def compile_terms(terms_raw):
|
||||
"""Parses DSL terms spec and runs it through the four compiler stages.
|
||||
"""Parses DSL terms spec and runs it through the five compiler stages.
|
||||
|
||||
This function initializes a new `CompilationContext` and executes the compiler pipeline
|
||||
sequentially: parsing, derivative/fluctuation expansion, data dependency resolution,
|
||||
and SymPy optimization (including buffer pooling).
|
||||
sequentially: parsing, derivative/fluctuation expansion, SymPy expression simplification,
|
||||
data dependency resolution, and array buffer pooling.
|
||||
|
||||
Args:
|
||||
terms_raw (str): The raw string contents of the DSL terms specification input file.
|
||||
|
|
@ -89,6 +90,7 @@ def compile_terms(terms_raw):
|
|||
ctx = CompilationContext()
|
||||
ParserStage().execute(terms_raw, ctx)
|
||||
DerivativeExpansionStage().execute(ctx)
|
||||
SympySimplificationStage().execute(ctx)
|
||||
DependencyResolutionStage().execute(ctx)
|
||||
SympyOptimizationStage().execute(ctx)
|
||||
return ctx
|
||||
|
|
|
|||
|
|
@ -2497,21 +2497,19 @@ class DependencyResolutionStage(object):
|
|||
return order
|
||||
|
||||
|
||||
class SympyOptimizationStage(object):
|
||||
"""Compiler pipeline Stage 4: Optimizes mathematical equations and shares memory buffers.
|
||||
class SympySimplificationStage(object):
|
||||
"""Compiler pipeline Stage 3: Expands, simplifies equations and prunes dependencies.
|
||||
|
||||
This stage:
|
||||
1. Invokes the SympyOptimizer to apply algebraic simplification and CSE.
|
||||
2. Updates variable dependencies to reflect optimized equations.
|
||||
3. Runs liveness window analysis to map multiple non-overlapping temporary variables
|
||||
to a limited set of shared XYZ buffers (array pooling) to prevent RAM exhaustion.
|
||||
1. Invokes the SympyOptimizer to substitute and simplify equations.
|
||||
2. Updates variable dependencies in CompilationContext to reflect optimized equations.
|
||||
"""
|
||||
|
||||
def execute(self, ctx):
|
||||
"""Executes Stage 4 mathematical optimization and array buffer sharing.
|
||||
"""Executes Stage 3 mathematical expression expansion and dependency pruning.
|
||||
|
||||
Args:
|
||||
ctx (CompilationContext): Active compilation context.
|
||||
ctx (CompilationContext): Active compilation context to update.
|
||||
"""
|
||||
# 1. SymPy 수식 최적화 엔진 초기화
|
||||
opt = SympyOptimizer.get_instance(ctx.derived)
|
||||
|
|
@ -2531,9 +2529,23 @@ class SympyOptimizationStage(object):
|
|||
updated_dependency[name] = dep_set
|
||||
ctx.dependency = updated_dependency
|
||||
|
||||
|
||||
class SympyOptimizationStage(object):
|
||||
"""Compiler pipeline Stage 5: Performs liveness analysis and memory buffer sharing.
|
||||
|
||||
This stage runs liveness window analysis to map multiple non-overlapping temporary
|
||||
variables to a limited set of shared XYZ buffers (array pooling) to prevent RAM exhaustion.
|
||||
"""
|
||||
|
||||
def execute(self, ctx):
|
||||
"""Executes Stage 5 array buffer sharing based on topologically sorted lists.
|
||||
|
||||
Args:
|
||||
ctx (CompilationContext): Active compilation context.
|
||||
"""
|
||||
self.array_name = "xyzbuffer{}"
|
||||
|
||||
# 3. Pass 1 및 Pass 2 연산 순서 배열들에 대해 각각 버퍼 공유 매핑(Pooling) 수행
|
||||
# 1. Pass 1 및 Pass 2 연산 순서 배열들에 대해 각각 버퍼 공유 매핑(Pooling) 수행
|
||||
narr1, alloc1 = (self.allocate_arr(ctx, ctx.pass1))
|
||||
narr2, alloc2 = (self.allocate_arr(ctx, ctx.pass2))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue