Skip to content

Commit

Permalink
Update trace scripts and vector_scalar_mul to use new scripts (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackl-xilinx authored Oct 18, 2024
1 parent a040984 commit a561702
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 21 deletions.
14 changes: 6 additions & 8 deletions programming_examples/basic/vector_scalar_mul/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ def device_body():
)
of_out = object_fifo("out", ComputeTile2, ShimTile, buffer_depth, tile_ty)

# Set up a circuit-switched flow from core to shim for tracing information
# Set up a packet-switched flow from core to shim for tracing information
tiles_to_trace = [ComputeTile2]
if trace_size > 0:
flow(ComputeTile2, WireBundle.Trace, 0, ShimTile, WireBundle.DMA, 1)
trace_utils.configure_packet_tracing_flow(tiles_to_trace, ShimTile)

# Set up compute tiles

Expand All @@ -77,13 +78,10 @@ def core_body():
def sequence(A, F, C):

if trace_size > 0:
trace_utils.configure_simple_tracing_aie2(
ComputeTile2,
ShimTile,
ddr_id=2,
size=trace_size,
offset=N_in_bytes,
trace_utils.configure_packet_tracing_aie2(
tiles_to_trace, ShimTile, trace_size, N_in_bytes
)

npu_dma_memcpy_nd(
metadata=of_in, bd_id=1, mem=A, sizes=[1, 1, 1, N], issue_token=True
)
Expand Down
31 changes: 29 additions & 2 deletions programming_examples/basic/vector_scalar_mul/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
import numpy as np
import sys
from aie.utils.xrt import setup_aie, execute as execute_on_aie
import time
from aie.utils.xrt import setup_aie, write_out_trace, execute
import aie.utils.test as test_utils


Expand All @@ -18,6 +19,10 @@ def main(opts):
vector_dtype = np.int16
scalar_dtype = np.int32
scale_factor = 3
size_out = data_size * 2
print("output buffer size: " + str(size_out))

enable_trace = opts.trace_size > 0

app = setup_aie(
opts.xclbin,
Expand All @@ -28,12 +33,34 @@ def main(opts):
scalar_dtype,
data_size,
vector_dtype,
enable_trace=enable_trace,
trace_size=opts.trace_size,
)
input_vector = np.arange(1, data_size + 1, dtype=vector_dtype)
input_factor = np.array([3], dtype=scalar_dtype)
aie_output = execute_on_aie(app, input_vector, input_factor)
# aie_output = execute_on_aie(app, input_vector, input_factor)

start = time.time_ns()
full_output = execute(app, input_vector, input_factor)
stop = time.time_ns()
npu_time = stop - start
print("npu_time: ", npu_time)

# aie_output = full_output[:size_out].view(np.int8)
# aie_output = full_output[:size_out].view(np.uint8)
aie_output = full_output[:size_out].view(np.int16)
if enable_trace:
trace_buffer = full_output[size_out:].view(np.uint32)

ref = np.arange(1, data_size + 1, dtype=vector_dtype) * scale_factor

if enable_trace:
# trace_buffer = full_output[3920:]
print("trace_buffer shape: ", trace_buffer.shape)
print("trace_buffer dtype: ", trace_buffer.dtype)
# write_out_trace(trace_buffer, str(opts.trace_file))
write_out_trace(trace_buffer, "trace.txt")

# Copy output results and verify they are correct
errors = 0
if opts.verify:
Expand Down
15 changes: 13 additions & 2 deletions programming_examples/utils/parse_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import sys
import re

from aie.utils.trace_events_enum import CoreEvent, MemEvent, PLEvent, MemTileEvent

# Number of different trace types, currently 4
Expand All @@ -13,7 +14,8 @@
NumTraceTypes = 4
NUM_EVENTS = 8 # number of events we can view per trace

DEBUG = False
# DEBUG = False
# DEBUG = True


def parse_args():
Expand All @@ -23,6 +25,7 @@ def parse_args():
parser.add_argument(
"--colshift", help="column shift adjustment to source mlir", required=False
)
parser.add_argument("--debug", help="debug mode", required=False)
# TODO tracelabels removed since we can have multiple sets of labels for each pkt_type & loc combination
# parser.add_argument('--tracelabels',
# nargs='+',
Expand Down Expand Up @@ -610,7 +613,7 @@ def parse_mlir_trace_events(lines):
row = int(result.group(3 * i2 + 3))
elif var == "column":
col = int(result.group(3 * i2 + 3)) + colshift
col = 1 if col == 0 else col
# col = 1 if col == 0 else col
elif var == "value":
if result.group(3 * i2 + 2) == "0x":
value = int(result.group(3 * i2 + 3), 16)
Expand Down Expand Up @@ -757,6 +760,10 @@ def lookup_event_name_by_type(trace_type, code):
events_enum = CoreEvent
elif trace_type == 1: # Mem traces
events_enum = MemEvent
elif trace_type == 2: # Shim traces
events_enum = PLEvent
elif trace_type == 3: # MemTile traces
events_enum = MemTileEvent
if events_enum is not None and code in set(x.value for x in events_enum):
event = events_enum(code).name
else:
Expand Down Expand Up @@ -871,6 +878,10 @@ def setup_trace_metadata(trace_events, pid_events):

opts = parse_args()

DEBUG = opts.debug
if DEBUG:
print("Debug mode enable\n")

# set colshift based on optional argument
colshift = int(opts.colshift) if opts.colshift else 0

Expand Down
Loading

0 comments on commit a561702

Please sign in to comment.