The following is the list of the advanced Python traffic generator API along with their usage.
API | Behavior |
---|---|
ipc_axis_master_util("<sender_io_name>")
|
To instantiate the master traffic generator (TG) |
ipc_axis_slave_util("<receiver_io_name>")
|
To instantiate the slave TG |
b_transport(packet)
|
Blocking API to send the AXI4-Stream packets |
sample_transaction()
|
Blocking API to receive the AXI4-Stream packets. Data is received beat by beat
(one sample_transaction() call gives one beat). |
ipc_axis_master_nb_util("<sender_io_name>")
|
To instantiate a non-blocking master TG |
ipc_axis_slave_nb_util("<receiver_io_name>")
|
To instantiate a non-blocking slave TG |
nb_transport(packet)
|
Non-blocking API call to send the AXI4-Stream packets |
nb_sample_transaction()
|
Non-blocking API call to receive the AXI4-Stream packets. Data is received beat by beat
(one sample_transaction() call gives one
beat). |
no_of_available_txns()
|
Used to get the number of transactions received for non-blocking TG |
end_of_simulation()
|
End and exit the simulation using this API Preferable use in external TG with sw_emu/hw_emu |
disconnect()
|
To disconnect the socket connections (DataIn, DataOut etc) Preferable for use in external TG with |
ipc_axis_master_util (<sender_io_name>)
Used to instantiate the sender port in the Python script.
- API usage
- Creates a user object using the API for sender:
- Parameters
- Name of the external port that sends data:
- Example
-
#Instantiating AXI Master Utilities data_in = ipc_axis_master_util("DataIn")
ipc_axis_slave_util(<receiver_io_name>)
Used to instantiate the receiver port in the Python script.
- API usage
- Creates a user object using the API for the receiver:
- Parameters
- Name of the external port that receives the data:
- Example
-
#Instantiating AXI Slave Utilities data_out = ipc_axis_slave_util("DataOut")
b_transport(packet)
- API usage
- Calls the API using the object created
- Parameters
- AXI4-Stream packet:
- Example
-
#Create packet data_packet = xtlm_ipc.axi_stream_packet() // API to generate the stream packet data = generate_data() # custom user code to generate the data data_packet.data = data data_packet.tlast = True #AXI Stream Fields #Optional AXI Stream Parameters data_packet.tuser = optional data data_packet.tkeep = optional data #Send Transaction data_in.b_transport(data_packet)
sample_transaction()
Blocking API to receive the AXI4-Stream packets.- API Usage
- Calls the API using the receiver_obj created:
- Example
-
#Sample the packets data_packet = data_out.sample_transaction() # Will wait until data is received.
ipc_axis_master_nb_util (<sender_io_name>)
Instantiates the sender port for non-blocking in the python script.- API Usage
- Creates a user object using the API for sender:
- Parameters
- Name of the external port that sends the data:
- Example
-
#Instantiating AXI Master Utilities data_in = ipc_axis_master_nb_util("DataIn")
ipc_axis_slave_nb_util(<receiver_io_name>)
Used to instantiate the receiver port for non-blocking in the Python script
- API Usage
- Creates a user object using the API for receiver
- Parameters
- Name of the external port that sends the data
- Example
-
#Instantiating AXI Slave Utilities data_out = ipc_axis_slave_nb_util("DataOut")
nb_transport(<packet>)
Non-blocking API used to send AXI4-Stream packets. Prior to transporting data you need to format it into data packets as described in Formatting Data with Traffic Generators in Python below.
- API Usage
- Calls the API using sender_obj:
- Parameters
- AXI4-Stream packet:
- Example
-
#Create packet data_packet = xtlm_ipc.axi_stream_packet() data = generate_data() # custom user code to generate the desired data data_packet.data_length = "DATA_LENGTH" data_packet.data = data data_packet.tlast = True #to mark end of packet. This is user's choice based on application data_in.nb_transport(data_packet)
nb_sample_transaction()
A non-blocking API to receive the AXI stream packets.
- API Usage
-
packet = receiver_obj.nb_sample_transaction()
- Example
-
#Sample the packets # Will return data if it is available # Will return empty list if nothing is available # Will not wait or stop the execution until data is present to sample data_packet = data_out.nb_sample_transaction()
Here, data_out
is the receiver
object and data_packet
is the received packet.
no_of_available_txns
For non-blocking, this API is used to get to get number of transactions received.
- API Usage
- Calls the API using the user object for the receiver.
- Example
-
data_out = ipc_axis_slave_nb_util("ReceiverName") data = [] # Checks if any data is present to receive if(slave.no_of_available_txns != 0) : data = data_out.nb_sample_transaction() # fill data with respective received data
end_of_simulation()
Ends and exits the simulation.
- API Usage
- Call the API using the sender object
- Example
-
data_in.end_of_simulation()
Preferably used with with sw_emu/hw_emu.
disconnect()
To disconnect the socket connections (DataIn, DataOut etc)
- API Usage
- Calls the API using sender or receiver object:
- Example
-
data_in.disconnect() data_out.disconnect()
Preferably used with
x86simulator
oraiesimulator
.
Formatting Data with Traffic Generators in Python
Data formatting is not necessary when using the AI Engine API as described in Python API for AI Engine Graphs. However, to send or receive data using the advanced API, which expects data to be in the form of packets, you need to format the data prior to transport.
To emulate AXI4-Stream transactions AXI Traffic Generators require the payload data to be broken into appropriately sized bursts. For example, to send 128 bytes with a PLIO width of 32 bits (4 bytes) requires 128 bytes/4 bytes = 32 AXI4-Stream transactions. Converting between bytes arrays and AXI transactions can be handled in Python.
The Python struct
library
provides a mechanism to convert between Python and C data types. Specifically, the
struct.pack
and struct.unpack
functions pack and unpack byte arrays according to a
format string argument. The following table shows format strings for common C data
types and PLIO widths.
For more information see: https://docs.python.org/3/library/struct.html
Data Type | PLIO Width | Python Code Snippet |
---|---|---|
cfloat | PLIO32 | N/A |
PLIO64 |
rVec =
np.real(data)
|
|
PLIO128 | ||
cint16 | PLIO32 |
rVec =
np.real(data).astype(np.int16)
|
PLIO64 | ||
PLIO128 | ||
int8 | PLIO32 |
intvec =
np.real(data).astype(np.int8)
|
PLIO64 | ||
PLIO128 | ||
int32 | PLIO32 |
intvec =
np.real(data).astype(np.int32)
|
PLIO64 | ||
PLIO128 |