@@ -76,7 +76,30 @@ def lookup(self, nodeName: str, tensorName: str) -> str:
7676 return self ._mapping [nodeName , tensorName ]
7777
7878
79- class MemoryLevelAwareDeployer (NetworkDeployer ):
79+ class MemorySummaryMixin :
80+
81+ def _printMemorySummary (self ):
82+ log .info ("" )
83+ log .info ("Memory Usage Report:" )
84+ log .info (f" { 'Level' :<14} { 'Capacity (bytes)' :>10} { 'Total' :>10} ( Static + Dynamic ) (Usage )" )
85+ log .info (" " + "-" * 78 )
86+
87+ for level , dynamicSize in self .worstCaseBufferSize .items ():
88+ staticSize = 0
89+ for _buffer in self .ctxt .globalObjects .values ():
90+ # We do not count structs for now, since they are not properly modeled
91+ if isinstance (_buffer , ConstantBuffer ) and _buffer ._deploy and _buffer ._memoryLevel == level :
92+ staticSize += int ((np .prod (_buffer .shape ) * _buffer ._type .referencedType .typeWidth // 8 ))
93+
94+ capacity = self .Platform .memoryHierarchy .memoryLevels [level ].size
95+ total = staticSize + dynamicSize
96+
97+ log .info (f" { level :<20} { capacity :10,} { total :10,d} "
98+ f"({ staticSize :10,d} + { dynamicSize :10,d} ) "
99+ f"({ total / capacity * 100 :5.1f} %)" )
100+
101+
102+ class MemoryLevelAwareDeployer (NetworkDeployer , MemorySummaryMixin ):
80103
81104 def __init__ (self ,
82105 graph : gs .Graph ,
@@ -127,28 +150,8 @@ def codeTransform(self, verbose: CodeGenVerbosity = _NoVerbosity):
127150 self .ctxt , self .graph = self .memoryLevelAnnotationOptimizer .optimize (self .ctxt , self .graph )
128151 super ().codeTransform (verbose )
129152
130- def _printMemorySummary (self ):
131- log .info ("" )
132- log .info ("Memory Usage Report:" )
133- log .info (f" { 'Level' :<14} { 'Capacity (bytes)' :>10} { 'Total' :>10} ( Static + Dynamic ) (Usage )" )
134- log .info (" " + "-" * 78 )
135-
136- for level , dynamicSize in self .worstCaseBufferSize .items ():
137- staticSize = 0
138- for _buffer in self .ctxt .globalObjects .values ():
139- # We do not count structs for now, since they are not properly modeled
140- if isinstance (_buffer , ConstantBuffer ) and _buffer ._deploy and _buffer ._memoryLevel == level :
141- staticSize += int ((np .prod (_buffer .shape ) * _buffer ._type .referencedType .typeWidth // 8 ))
142-
143- capacity = self .Platform .memoryHierarchy .memoryLevels [level ].size
144- total = staticSize + dynamicSize
145-
146- log .info (f" { level :<20} { capacity :10,} { total :10,d} "
147- f"({ staticSize :10,d} + { dynamicSize :10,d} ) "
148- f"({ total / capacity * 100 :5.1f} %)" )
149-
150153
151- class MemoryLevelAwareSignPropDeployer (SignPropDeployer ):
154+ class MemoryLevelAwareSignPropDeployer (SignPropDeployer , MemorySummaryMixin ):
152155
153156 def __init__ (self ,
154157 graph : gs .Graph ,
@@ -204,28 +207,8 @@ def codeTransform(self, verbose: CodeGenVerbosity = _NoVerbosity):
204207 self .ctxt , self .graph = self .memoryLevelAnnotationOptimizer .optimize (self .ctxt , self .graph )
205208 super ().codeTransform (verbose )
206209
207- def _printMemorySummary (self ):
208- log .info ("" )
209- log .info ("Memory Usage Report:" )
210- log .info (f" { 'Level' :<14} { 'Capacity (bytes)' :>10} { 'Total' :>10} ( Static + Dynamic ) (Usage )" )
211- log .info (" " + "-" * 78 )
212-
213- for level , dynamicSize in self .worstCaseBufferSize .items ():
214- staticSize = 0
215- for _buffer in self .ctxt .globalObjects .values ():
216- # We do not count structs for now, since they are not properly modeled
217- if isinstance (_buffer , ConstantBuffer ) and _buffer ._deploy and _buffer ._memoryLevel == level :
218- staticSize += int ((np .prod (_buffer .shape ) * _buffer ._type .referencedType .typeWidth // 8 ))
219-
220- capacity = self .Platform .memoryHierarchy .memoryLevels [level ].size
221- total = staticSize + dynamicSize
222-
223- log .info (f" { level :<20} { capacity :10,} { total :10,d} "
224- f"({ staticSize :10,d} + { dynamicSize :10,d} ) "
225- f"({ total / capacity * 100 :5.1f} %)" )
226-
227210
228- class MemoryDeployerWrapper (NetworkDeployerWrapper ):
211+ class MemoryDeployerWrapper (NetworkDeployerWrapper , MemorySummaryMixin ):
229212
230213 def __init__ (self , deployer : NetworkDeployer , memoryLevelAnnotationPasses : List [NetworkOptimizationPass ] = []):
231214 super ().__init__ (deployer )
@@ -271,23 +254,3 @@ def bind(self):
271254 def codeTransform (self , verbose : CodeGenVerbosity = _NoVerbosity ):
272255 self .ctxt , self .graph = self .memoryLevelAnnotationOptimizer .optimize (self .ctxt , self .graph )
273256 super ().codeTransform (verbose )
274-
275- def _printMemorySummary (self ):
276- log .info ("" )
277- log .info ("Memory Usage Report:" )
278- log .info (f" { 'Level' :<14} { 'Capacity (bytes)' :>10} { 'Total' :>10} ( Static + Dynamic ) (Usage )" )
279- log .info (" " + "-" * 78 )
280-
281- for level , dynamicSize in self .worstCaseBufferSize .items ():
282- staticSize = 0
283- for _buffer in self .ctxt .globalObjects .values ():
284- # We do not count structs for now, since they are not properly modeled
285- if isinstance (_buffer , ConstantBuffer ) and _buffer ._deploy and _buffer ._memoryLevel == level :
286- staticSize += int ((np .prod (_buffer .shape ) * _buffer ._type .referencedType .typeWidth // 8 ))
287-
288- capacity = self .Platform .memoryHierarchy .memoryLevels [level ].size
289- total = staticSize + dynamicSize
290-
291- log .info (f" { level :<20} { capacity :10,} { total :10,d} "
292- f"({ staticSize :10,d} + { dynamicSize :10,d} ) "
293- f"({ total / capacity * 100 :5.1f} %)" )
0 commit comments