Skip to content

Commit

Permalink
Add verbosity level.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqisun committed Dec 24, 2024
1 parent bab8bee commit 0e0e8e9
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 171 deletions.
20 changes: 16 additions & 4 deletions cgra/CGRAKingMeshRTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,23 @@ def construct( s, DataType, PredicateType, CtrlType, width, height,
s.tile[i].to_mem_waddr.rdy //= 0
s.tile[i].to_mem_wdata.rdy //= 0

# Line trace
def line_trace( s ):
# verbose trace if verbosity > 0
def verbose_trace(s, verbosity=1):
res = ''
for (i, x) in enumerate(s.tile):
res += "# [tile"+str(i)+"]: " + x.line_trace() + x.ctrl_mem.line_trace() + '\n'
res += f"\ndata_mem: {s.data_mem.line_trace()}"
res += "# [tile" + str(i) + "]: " + x.line_trace(verbosity=verbosity) + x.ctrl_mem.line_trace(verbosity=verbosity) + '\n'
res += f"\ndata_mem: {s.data_mem.line_trace(verbosity=verbosity)}"
res += "------\n\n"
return res

# Line trace
def line_trace(s, verbosity=0):
if verbosity==0:
# str = "||".join([ x.element.line_trace() for x in s.tile ])
# str += " :: [" + s.data_mem.line_trace() + "]"
res = "||\n".join([(("[tile" + str(i) + "]: ") + x.line_trace() + x.ctrl_mem.line_trace())
for (i, x) in enumerate(s.tile)])
res += "\n :: [" + s.data_mem.line_trace() + "] \n"
return res
else:
return s.verbose_trace(verbosity=verbosity)
3 changes: 2 additions & 1 deletion cgra/translate/VectorCGRAKingMeshRTL_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def done( s ):
return done

def line_trace( s ):
return s.dut.line_trace()
verbosity = 1
return s.dut.line_trace(verbosity=verbosity)

def test_homo_4x4( cmdline_opts ):
num_tile_inports = 8
Expand Down
14 changes: 12 additions & 2 deletions fu/flexible/FlexibleFuRTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def comb_logic():
s.fu_recv_in_rdy_vector[port][i] @= s.fu[i].recv_in[port].rdy
s.recv_in[port].rdy @= reduce_or( s.fu_recv_in_rdy_vector[port] )


def line_trace( s ):
# verbose trace if verbosity > 0
def verbose_trace(s, verbosity=1):
# for clk n
# recv:
# 1. OPT: opt+rdy(if ready to receive opt)
Expand Down Expand Up @@ -151,3 +151,13 @@ def line_trace( s ):
f'- FU out:'
f'{out_md}\n')

def line_trace( s, verbosity=0 ):
if verbosity == 0:
opt_str = " #"
if s.recv_opt.en:
opt_str = OPT_SYMBOL_DICT[s.recv_opt.msg.ctrl]
out_str = ",".join([str(x.msg) for x in s.send_out])
recv_str = ",".join([str(x.msg) for x in s.recv_in])
return f'[recv: {recv_str}] {opt_str}(P{s.recv_opt.msg.predicate}) (const: {s.recv_const.msg}, en: {s.recv_const.en}) ] = [out: {out_str}] (recv_opt.rdy: {s.recv_opt.rdy}, recv_in[0].rdy: {s.recv_in[0].rdy}, recv_in[1].rdy: {s.recv_in[1].rdy}, recv_predicate.msg: {s.recv_predicate.msg}, {OPT_SYMBOL_DICT[s.recv_opt.msg.ctrl]}, recv_opt.en: {s.recv_opt.en}, send[0].en: {s.send_out[0].en}) '
else:
return s.verbose_trace(verbosity=verbosity)
78 changes: 46 additions & 32 deletions mem/ctrl/CtrlMemRTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,56 +73,58 @@ def update_raddr():
else:
s.reg_file.raddr[0] <<= s.reg_file.raddr[0] + AddrType( 1 )


def line_trace( s ):
# verbose trace if verbosity > 0
def verbose_trace(s, verbosity=1):
num_fu_in = len(s.reg_file.regs[0].fu_in)
# num_inports = len(s.reg_file.regs[0].predicate_in)
num_outports = len(s.reg_file.regs[0].outport if hasattr(s.reg_file.regs[0], 'outport') else [])
num_direction_ports = num_outports - num_fu_in

# reg
reg_dicts = [ dict(data.__dict__) for data in s.reg_file.regs ]
reg_dicts = [dict(data.__dict__) for data in s.reg_file.regs]
reg_sub_header = {}
for reg_dict in reg_dicts:
for key in reg_dict.keys():
reg_sub_header[key] = ''
reg_dict['ctrl'] = OPT_SYMBOL_DICT[reg_dict['ctrl']]
reg_dict['fu_in'] = [ int(fi) for fi in reg_dict['fu_in']]
reg_dict['fu_in'] = [int(fi) for fi in reg_dict['fu_in']]
fu_in_header = []
for idx, val in enumerate(reg_dict['fu_in']):
fu_in_header.append(idx)
fu_in_header_str = "|".join([f"{hd : ^3}" for hd in fu_in_header])
reg_dict['fu_in'] = "|".join([f"{v : ^3}" for v in reg_dict['fu_in']])
reg_sub_header['fu_in'] = fu_in_header_str
if 'outport' in reg_dict:
reg_dict['outport'] = [ int(op) for op in reg_dict['outport']]
reg_dict['outport'] = [int(op) for op in reg_dict['outport']]
fu_reg_num = 1
outport_sub_header = []
for idx, val in enumerate(reg_dict['outport']):
# to directions
if idx <= num_direction_ports-1:
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
outport_sub_header.append(f"{hd : ^{len(hd)+2}}")
reg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val-1] if val != 0 else '-' : ^{len(hd)+2}}"
outport_sub_header.append(f"{hd : ^{len(hd) + 2}}")
reg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd) + 2}}"
# to fu regs
else:
hd = f"fu_reg_{fu_reg_num}"
outport_sub_header.append(f"{hd : ^{len(hd)}}")
reg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val-1] if val != 0 else '-' : ^{len(hd)}}"
reg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)}}"
fu_reg_num += 1
outport_sub_header_str = "|".join([hd for hd in outport_sub_header])
reg_dict['outport'] = "|".join([v for v in reg_dict['outport']])
reg_sub_header['outport'] = outport_sub_header_str
reg_sub_header['outport'] = outport_sub_header_str
if 'predicate_in' in reg_dict:
reg_dict['predicate_in'] = [ int(pi) for pi in reg_dict['predicate_in']]
reg_dict['predicate_in'] = [int(pi) for pi in reg_dict['predicate_in']]
fu_out_num = 1
predicate_in_sub_header = []
for idx, val in enumerate(reg_dict['predicate_in']):
# from directions
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
predicate_in_sub_header.append(f"{hd : ^{len(hd)+2}}")
reg_dict['predicate_in'][idx] = f"{val : ^{len(hd)+2}}"
predicate_in_sub_header.append(f"{hd : ^{len(hd) + 2}}")
reg_dict['predicate_in'][idx] = f"{val : ^{len(hd) + 2}}"
# from fu
else:
hd = f"fu_out_{fu_out_num}"
Expand All @@ -133,13 +135,13 @@ def line_trace( s ):
reg_dict['predicate_in'] = "|".join([v for v in reg_dict['predicate_in']])
reg_sub_header['predicate_in'] = predicate_in_sub_header_str
if 'routing_xbar_outport' in reg_dict:
reg_dict['routing_xbar_outport'] = [ int(rxop) for rxop in reg_dict['routing_xbar_outport']]
reg_dict['routing_xbar_outport'] = [int(rxop) for rxop in reg_dict['routing_xbar_outport']]
if 'fu_xbar_outport' in reg_dict:
reg_dict['fu_xbar_outport'] = [ int(fxop) for fxop in reg_dict['fu_xbar_outport']]
reg_dict['fu_xbar_outport'] = [int(fxop) for fxop in reg_dict['fu_xbar_outport']]
if 'routing_predicate_in' in reg_dict:
reg_dict['routing_predicate_in'] = [ int(rpi) for rpi in reg_dict['routing_predicate_in']]
reg_dict['routing_predicate_in'] = [int(rpi) for rpi in reg_dict['routing_predicate_in']]
reg_dicts.insert(0, reg_sub_header)
reg_md = markdown_table(reg_dicts).set_params(quote=False).get_markdown()
reg_md = markdown_table(reg_dicts).set_params(quote=False).get_markdown()

# recv_ctrl
recv_ctrl_msg_dict = dict(s.recv_ctrl.msg.__dict__)
Expand All @@ -148,7 +150,7 @@ def line_trace( s ):
recv_ctrl_sub_header[key] = ''
recv_ctrl_msg_list = []
recv_ctrl_msg_dict['ctrl'] = OPT_SYMBOL_DICT[recv_ctrl_msg_dict['ctrl']]
recv_ctrl_msg_dict['fu_in'] = [ int(fi) for fi in recv_ctrl_msg_dict['fu_in']]
recv_ctrl_msg_dict['fu_in'] = [int(fi) for fi in recv_ctrl_msg_dict['fu_in']]
fu_in_header = []
for idx, val in enumerate(recv_ctrl_msg_dict['fu_in']):
fu_in_header.append(idx)
Expand All @@ -157,34 +159,36 @@ def line_trace( s ):
recv_ctrl_sub_header['fu_in'] = fu_in_header_str

if 'outport' in recv_ctrl_msg_dict:
recv_ctrl_msg_dict['outport'] = [ int(op) for op in recv_ctrl_msg_dict['outport']]
recv_ctrl_msg_dict['outport'] = [int(op) for op in recv_ctrl_msg_dict['outport']]
fu_reg_num = 1
outport_sub_header = []
for idx, val in enumerate(recv_ctrl_msg_dict['outport']):
# to directions
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
outport_sub_header.append(f"{hd : ^{len(hd)+2}}")
recv_ctrl_msg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)+2}}"
outport_sub_header.append(f"{hd : ^{len(hd) + 2}}")
recv_ctrl_msg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd) + 2}}"
# to fu regs
else:
hd = f"fu_reg_{fu_reg_num}"
outport_sub_header.append(f"{hd : ^{len(hd)}}")
recv_ctrl_msg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)}}"
recv_ctrl_msg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)}}"
fu_reg_num += 1
outport_sub_header_str = "|".join([hd for hd in outport_sub_header])
recv_ctrl_msg_dict['outport'] = "|".join([v for v in recv_ctrl_msg_dict['outport']])
recv_ctrl_sub_header['outport'] = outport_sub_header_str
if 'predicate_in' in recv_ctrl_msg_dict:
recv_ctrl_msg_dict['predicate_in'] = [ int(pi) for pi in recv_ctrl_msg_dict['predicate_in']]
recv_ctrl_msg_dict['predicate_in'] = [int(pi) for pi in recv_ctrl_msg_dict['predicate_in']]
fu_out_num = 1
predicate_in_sub_header = []
for idx, val in enumerate(recv_ctrl_msg_dict['predicate_in']):
# from directions
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
predicate_in_sub_header.append(f"{hd : ^{len(hd)+2}}")
recv_ctrl_msg_dict['predicate_in'][idx] = f"{val : ^{len(hd)+2}}"
predicate_in_sub_header.append(f"{hd : ^{len(hd) + 2}}")
recv_ctrl_msg_dict['predicate_in'][idx] = f"{val : ^{len(hd) + 2}}"
# from fu
else:
hd = f"fu_out_{fu_out_num}"
Expand All @@ -199,7 +203,6 @@ def line_trace( s ):
send_ctrl_md = markdown_table(recv_ctrl_msg_list).set_params(quote=False).get_markdown()
# recv_ctrl_msg = "\n".join([(key + ": " + str(value)) for key, value in recv_ctrl_msg_dict.items()])


# send_ctrl
send_ctrl_msg_dict = dict(s.send_ctrl.msg.__dict__)
send_ctrl_sub_header = {}
Expand All @@ -209,7 +212,7 @@ def line_trace( s ):
send_ctrl_msg_dict['ctrl'] = OPT_SYMBOL_DICT[send_ctrl_msg_dict['ctrl']]
if 'predicate' in send_ctrl_msg_dict:
send_ctrl_msg_dict['predicate'] = int(send_ctrl_msg_dict['predicate'])
send_ctrl_msg_dict['fu_in'] = [ int(fi) for fi in send_ctrl_msg_dict['fu_in']]
send_ctrl_msg_dict['fu_in'] = [int(fi) for fi in send_ctrl_msg_dict['fu_in']]
fu_in_header = []
for idx, val in enumerate(send_ctrl_msg_dict['fu_in']):
fu_in_header.append(idx)
Expand All @@ -225,13 +228,15 @@ def line_trace( s ):
# to directions
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
outport_sub_header.append(f"{hd : ^{len(hd)+2}}")
send_ctrl_msg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)+2}}"
outport_sub_header.append(f"{hd : ^{len(hd) + 2}}")
send_ctrl_msg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd) + 2}}"
# to fu regs
else:
hd = f"fu_reg_{fu_reg_num}"
outport_sub_header.append(f"{hd : ^{len(hd)}}")
send_ctrl_msg_dict['outport'][idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)}}"
send_ctrl_msg_dict['outport'][
idx] = f"{tile_port_direction_dict_short_desc[val - 1] if val != 0 else '-' : ^{len(hd)}}"
fu_reg_num += 1
outport_sub_header_str = "|".join([hd for hd in outport_sub_header])
send_ctrl_msg_dict['outport'] = "|".join([v for v in send_ctrl_msg_dict['outport']])
Expand All @@ -244,8 +249,8 @@ def line_trace( s ):
# from directions
if idx <= num_direction_ports - 1:
hd = tile_port_direction_dict_short_desc[idx]
predicate_in_sub_header.append(f"{hd : ^{len(hd)+2}}")
send_ctrl_msg_dict['predicate_in'][idx] = f"{val : ^{len(hd)+2}}"
predicate_in_sub_header.append(f"{hd : ^{len(hd) + 2}}")
send_ctrl_msg_dict['predicate_in'][idx] = f"{val : ^{len(hd) + 2}}"
# from fu
else:
hd = f"fu_out_{fu_out_num}"
Expand Down Expand Up @@ -273,3 +278,12 @@ def line_trace( s ):
f'{send_ctrl_md}\n\n'
f'- ctrl_memory: {reg_md}\n')


def line_trace( s, verbosity=0 ):
if verbosity == 0:
out_str = "||".join([str(data) for data in s.reg_file.regs])
return f'{s.recv_ctrl.msg} : [{out_str}] : {s.send_ctrl.msg}'
else:
return s.verbose_trace(verbosity=verbosity)


22 changes: 21 additions & 1 deletion mem/data/DataMemRTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def update_signal():
s.recv_waddr[i].rdy @= Bits1( 1 )
s.recv_wdata[i].rdy @= Bits1( 1 )

def line_trace(s):

# verbose trace if verbosity > 0
def verbose_trace(s, verbosity=1):
# data memory: mem size, reg
# recv_raddr(rdy, msg), send_rdata(en, msg), recv_waddr(rdy, msg), recv_wdata, tile #
reg_dicts = [dict(data.__dict__) for data in s.reg_file.regs]
Expand Down Expand Up @@ -136,3 +138,21 @@ def line_trace(s):
f'- regs(mem size: {len(reg_dicts)}): {reg_md}\n'
f'- mem_r/w:'
f'{mem_md}')


def line_trace(s, verbosity=0):
if verbosity == 0:
recv_raddr_str = "recv_read_addr: " + "|".join([str(data.msg) for data in s.recv_raddr])
recv_waddr_str = "recv_write_addr: " + "|".join([str(data.msg) for data in s.recv_waddr])
recv_wdata_str = "recv_write_data: " + "|".join([str(data.msg) for data in s.recv_wdata])
content_str = "content: " + "|".join([str(data) for data in s.reg_file.regs])
send_rdata_str = "send_read_data: " + "|".join([str(data.msg) for data in s.send_rdata])
return f'{recv_raddr_str} || {recv_waddr_str} || {recv_wdata_str} || [{content_str}] || {send_rdata_str}'
# return f'DataMem: {recv_str} : [{out_str}] : {send_str} initWrites: {s.initWrites}'
# return s.reg_file.line_trace()
# return f'<{s.reg_file.wen[0]}>{s.reg_file.waddr[0]}:{s.reg_file.wdata[0]}|{s.reg_file.raddr[0]}:{s.reg_file.rdata[0]}'
# rf_trace = f'<{s.reg_file.wen[0]}>{s.reg_file.waddr[0]}:{s.reg_file.wdata[0]}|{s.reg_file.raddr[0]}:{s.reg_file.rdata[0]}'
# return f'[{s.recv_wdata[0].en & s.recv_waddr[0].en}]{s.recv_waddr[0]}<{s.recv_wdata[0]}({rf_trace}){s.recv_raddr[0]}>{s.send_rdata[0]}'
else:
return s.verbose_trace(verbosity=verbosity)

78 changes: 44 additions & 34 deletions tile/TileRTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,40 +124,50 @@ def update_opt():
s.crossbar.recv_opt.en @= s.ctrl_mem.send_ctrl.en
s.ctrl_mem.send_ctrl.rdy @= s.element.recv_opt.rdy & s.crossbar.recv_opt.rdy

# verbose trace if verbosity > 0
def verbose_trace(s, verbosity=1):
# recv:
# 1. rdy (if ready to receive data), if en and rdy: then data has been transferred (val, rdy are new type(protocol))
# 2. data
# [3. opt will show in FU trace]
# FU:
# FlexibleFuRTL.py
# tile out:
# 1. en (is data transferred)
recv_data = [x for x in s.recv_data]
recv_list = []
for idx, data in enumerate(recv_data):
msg_dict = data.msg.__dict__
tile_inport_dict = {"tile_inport_direction": tile_port_direction_dict[idx], "rdy": data.rdy}
tile_inport_dict.update(msg_dict)
recv_list.append(tile_inport_dict)
recv_md = markdown_table(recv_list).set_params(quote=False).get_markdown()

out_data = [x for x in s.send_data]
out_list = []
for idx, data in enumerate(out_data):
msg_dict = data.msg.__dict__
tile_outport_dict = {"tile_outport_direction": tile_port_direction_dict[idx], "en": data.en}
tile_outport_dict.update(msg_dict)
out_list.append(tile_outport_dict)
out_md = markdown_table(out_list).set_params(quote=False).get_markdown()
return (f"\n## class[{s.__class__.__name__}]:\n"
f"- Tile recv:"
f"{recv_md}\n"
f"- FU element:\n"
f"{s.element.line_trace(verbosity=verbosity)}\n"
f"===>\n"
f"- Tile out:"
f"{out_md}\n")

# Line trace
def line_trace( s ):
# recv:
# 1. rdy (if ready to receive data), if en and rdy: then data has been transferred (val, rdy are new type(protocol))
# 2. data
# [3. opt will show in FU trace]
# FU:
# FlexibleFuRTL.py
# tile out:
# 1. en (is data transferred)
recv_data = [x for x in s.recv_data]
recv_list = []
for idx, data in enumerate(recv_data):
msg_dict = data.msg.__dict__
tile_inport_dict = {"tile_inport_direction": tile_port_direction_dict[idx], "rdy": data.rdy}
tile_inport_dict.update(msg_dict)
recv_list.append(tile_inport_dict)
recv_md = markdown_table(recv_list).set_params(quote=False).get_markdown()

out_data = [x for x in s.send_data]
out_list = []
for idx, data in enumerate(out_data):
msg_dict = data.msg.__dict__
tile_outport_dict = {"tile_outport_direction": tile_port_direction_dict[idx], "en": data.en}
tile_outport_dict.update(msg_dict)
out_list.append(tile_outport_dict)
out_md = markdown_table(out_list).set_params(quote=False).get_markdown()
return (f"\n## class[{s.__class__.__name__}]:\n"
f"- Tile recv:"
f"{recv_md}\n"
f"- FU element:\n"
f"{s.element.line_trace()}\n"
f"===>\n"
f"- Tile out:"
f"{out_md}\n")
def line_trace( s, verbosity=0 ):
if verbosity == 0:
recv_str = "|".join([str(x.msg) for x in s.recv_data])
channel_recv_str = "|".join([str(x.recv.msg) for x in s.channel])
channel_send_str = "|".join([str(x.send.msg) for x in s.channel])
out_str = "|".join(["(" + str(x.msg.payload) + "," + str(x.msg.predicate) + ")" for x in s.send_data])
return f"{recv_str} => [{s.crossbar.recv_opt.msg}] ({s.element.line_trace()}) => {channel_recv_str} => {channel_send_str} => {out_str}"
else:
return s.verbose_trace(verbosity=verbosity)

Loading

0 comments on commit 0e0e8e9

Please sign in to comment.