@@ -220,43 +220,85 @@ def lut_estimation(self):
220220 return int (cnt_luts + cset_luts )
221221
222222 def prepare_kwargs_for_characteristic_fx (self ):
223- # function for the old DWC version
224- # newer version will need a separate, much more
225- # complicated function
223+ """Characteristic function of the non-general DWC
224+ variant."""
226225
227- numInWords = int (np .prod (self .get_folded_input_shape ()[- 2 :- 1 ]))
228- numOutWords = int (np .prod (self .get_folded_output_shape ()[- 2 :- 1 ]))
229- numReps = int (np .prod (self .get_folded_input_shape ()[:1 ]))
226+ numReps = int (np .prod (self .get_folded_input_shape ()[:- 1 ]))
230227
231- # inWidth = self.get_nodeattr("inWidth")
232- # outWidth = self.get_nodeattr("outWidth")
228+ inWidth = self .get_nodeattr ("inWidth" )
229+ outWidth = self .get_nodeattr ("outWidth" )
233230
234- read_inputs = Characteristic_Node ("read all words" , [(numInWords , [1 , 0 ])], True )
231+ print ("\n in,out widths:" , inWidth , outWidth )
232+ print ("inshape:" , self .get_folded_input_shape ())
233+ print ("outshape:" , self .get_folded_output_shape ())
235234
236- write_outputs = Characteristic_Node ( "write all words" , [( numOutWords , [ 0 , 1 ])], True )
235+ wind_up = 1
237236
238- up_convert_word = Characteristic_Node (
239- "up convert all words in a single transaction" ,
240- [(1 , read_inputs ), (1 , write_outputs )],
241- False ,
242- )
237+ idle = Characteristic_Node ("idle" , [(1 , [0 , 0 ])], True )
243238
244- down_convert_word = Characteristic_Node (
245- "down convert all words in a single transaction" ,
246- [(1 , read_inputs ), (1 , write_outputs )],
247- False ,
248- )
239+ if inWidth > outWidth :
240+ # down-conversion
241+ if inWidth % outWidth != 0 :
242+ return None # no support for gcd partial conversion yet
249243
250- if numInWords > numOutWords :
251- reps = Characteristic_Node (
252- "compute a set of DWCs with up conversion" , [(numReps , up_convert_word )], False
244+ writes_per_read = inWidth // outWidth
245+ # read 1, write many, repeats for in-word count
246+
247+ read_input = Characteristic_Node ("read 1 word" , [(1 , [1 , 0 ])], True )
248+
249+ write_output = Characteristic_Node ("write words" , [(writes_per_read , [0 , 1 ])], True )
250+
251+ down_convert_word = Characteristic_Node (
252+ "down convert all words in a single transaction" ,
253+ [(1 , read_input ), (1 , write_output )],
254+ False ,
253255 )
254- else :
255- reps = Characteristic_Node (
256- "compute a set of DWCs with down conversion" , [(numReps , down_convert_word )], False
256+
257+ numReps = int (np .prod (self .get_folded_input_shape ()[:- 1 ]))
258+
259+ dwc_top = Characteristic_Node (
260+ "compute a set of DWCs with down conversion" ,
261+ [(wind_up , idle ), (numReps , down_convert_word )],
262+ False ,
263+ )
264+
265+ elif inWidth < outWidth :
266+ # up-conversion
267+
268+ if outWidth % inWidth != 0 :
269+ return None # no support for gcd partial conversion yet
270+
271+ reads_per_write = outWidth // inWidth
272+ # read 1, write many, repeats for in-word count
273+
274+ read_input = Characteristic_Node ("read words" , [(reads_per_write , [1 , 0 ])], True )
275+
276+ write_output = Characteristic_Node ("write 1 word" , [(1 , [0 , 1 ])], True )
277+
278+ up_convert_word = Characteristic_Node (
279+ "down convert all words in a single transaction" ,
280+ [(1 , read_input ), (1 , write_output )],
281+ False ,
282+ )
283+
284+ numReps = int (np .prod (self .get_folded_output_shape ()[:- 1 ]))
285+ dwc_top = Characteristic_Node (
286+ "compute a set of DWCs with up conversion" ,
287+ [(wind_up , idle ), (numReps , up_convert_word )],
288+ False ,
257289 )
258290
259- return reps
291+ else :
292+ # pass-through
293+
294+ numReps = int (np .prod (self .get_folded_input_shape ()[:- 1 ]))
295+
296+ pass_through = Characteristic_Node ("pass-through" , [(1 , [1 , 1 ])], True )
297+
298+ dwc_top = Characteristic_Node (
299+ "DWC pass-through, no conversion" , [(wind_up , idle ), (numReps , pass_through )], False
300+ )
301+ return dwc_top
260302
261303 # def prepare_kwargs_for_characteristic_fx_old(self):
262304 # numInWords = int(np.prod(self.get_folded_input_shape()[-2:-1]))
0 commit comments