-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XRTRunner Utility Class & Programming Examples Cleanup (#673)
* Introduces the XRTRunner class, which is used to run programs on the npu while using common numpy operations to check the input/output * Remove spaghetti python path logic in examples * Allows the data_transfer_transpose to run for both float and int 32-bit datatypes * Makes it easier to change the sizes of things in the matrix_scalar_add example * Percolate changes from #672 to other programming examples as appropriate * Remove relative paths in makefiles * Make matrix_scalar_add/multi_launch_channel code correct * Adds/updates READMEs
- Loading branch information
Showing
78 changed files
with
1,876 additions
and
2,218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,61 @@ | ||
# Channel Examples | ||
|
||
This example focuses on one of the key abstractions of air: *channels*. This is a collection of examples that use channels in various ways. The patterns shown here may be used to create more complex examples. | ||
This collection of examples focuses on one of the key abstractions of air: *channels*. The patterns shown here may be used to create more complex examples. | ||
|
||
## Running and Testing | ||
|
||
#### ```herd-to-herd```: Using a channel to pass data between herd. | ||
|
||
There are two part of this example: two herds within one segment (single segment), and one herd per segment for two segments (multi-segment) | ||
There are two part of this example: two herds within one segment (single segment), and one herd per segment for two segments (multi-segment). | ||
|
||
The single segment example example ([herd_to_herd/single_segment/herd_to_herd.py](herd_to_herd/single_segment/herd_to_herd.py)) defines two `herd`s within the same `launch` + `segment`. There is a *producer herd*, which writes data to a `Herd2Herd` channel, and a *consumer herd*, which reads data form the `Herd2Herd` channel. | ||
|
||
```bash | ||
cd herd_to_herd/single_segment | ||
make clean && make | ||
``` | ||
The single segment example example ([herd_to_herd/single_segment/herd_to_herd.py](herd_to_herd/single_segment/herd_to_herd.py)) defines two *herds* within the same *launch* and *segment*. There is a *producer herd*, which writes data to a `Herd2Herd` channel, and a *consumer herd*, which reads data form the `Herd2Herd` channel. | ||
|
||
The multi-segment example ([herd_to_herd/multi_segment/herd_to_herd.py](herd_to_herd/multi_segment/herd_to_herd.py)) defines two `segment`s, each with one `herd`, within the same `launch`. There is a *producer_segment* with a *producer herd*, which writes data to a `Herd2Herd` channel, and a *consumer_segment* with a *consumer herd*, which reads data form the `Herd2Herd` channel. | ||
|
||
Warning: The multi-segment example is a work in progress! | ||
|
||
```bash | ||
cd herd_to_herd/multi_segment | ||
make clean && make | ||
``` | ||
|
||
#### ```channel-size```: Use the channel size argument | ||
|
||
This example ([channel_size/channel_size.py](channel_size/channel_size.py)) is a data passthrough example using the same tiling structure as the [matrix_scalar_add/multi_core_channel](../matrix_scalar_add/multi_core_channel.py) examples, only instead of using a separately defined channel for each tile/core, a bundle of channels is created (using the `ChannelOp` `size` parameter) and indexed into (the `ChannelGet` and `ChannelPut` `indices` parameter). | ||
|
||
```bash | ||
cd channel_size | ||
make clean && make | ||
``` | ||
|
||
#### ```hierarchical```: Use channels for sending data from Launch to Segment to Herd and back again | ||
|
||
This example ([hierarchical/hierarchical.py](hierarchical/hierarchical.py)) is a data passthrough example that uses a channel to send data from Launch to Segment (L3->L2 memory) and then from Segment to Herd (L2->L1 memory). The data is then sent back on an analogous path. | ||
|
||
```bash | ||
cd hierarchical | ||
make clean && make | ||
``` | ||
|
||
#### WIP: ```worker-to-self```: | ||
|
||
This example ([worker_to_self/worker_to_self.py](worker_to_self/worker_to_self.py)) is a work-in-progress data passthrough example using the same tiling structure as the [matrix_scalar_add/multi_core_channel](../matrix_scalar_add/multi_core_channel.py) examples, only the sole worker in the herd does some extra shuffling between input and output by putting the current data tile into a channel and then getting it from the same channel. | ||
|
||
WARNING: This example currently fails because it is assumed channel gets/parts are not from the same memory region, and this example breaks this assumption. | ||
|
||
```bash | ||
cd worker_to_self | ||
make clean && make | ||
``` | ||
WARNING: This example currently fails for unknown reasons. | ||
|
||
#### WIP: ```worker-to-worker```: | ||
|
||
This example ([worker_to_worker/worker_to_worker.py](worker_to_worker/worker_to_worker.py)) is a work-in-progress data passthrough example using the same tiling structure as the [matrix_scalar_add/multi_core_channel](../matrix_scalar_add/multi_core_channel.py) examples, only the each worker trades a tile of input data to another worker in the herd by sending it via channel. | ||
|
||
WARNING: This example currently fails for unknown reasons. | ||
|
||
#### Usage (For All Examples) | ||
|
||
To generate AIR MLIR from Python: | ||
```bash | ||
cd worker_to_worker | ||
cd <example_dir> | ||
make clean && make print | ||
``` | ||
|
||
To run: | ||
```bash | ||
cd <example_dir> | ||
make clean && make | ||
`` | ||
``` | ||
|
||
#### WIP: more examples! | ||
To run with verbose output: | ||
```bash | ||
cd <example_dir> | ||
python <example_file>.py -v | ||
``` | ||
|
||
You may be able to configure examples (data types, sizes); to get additional usage information, run: | ||
```bash | ||
cd <example_dir> | ||
python <example_file>.py -h | ||
``` |
13 changes: 9 additions & 4 deletions
13
programming_examples/channel_examples/channel_size/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
# Copyright (C) 2022, Advanced Micro Devices, Inc. | ||
# (c) Copyright 2024 Advanced Micro Devices, Inc. | ||
# SPDX-License-Identifier: MIT | ||
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
|
||
targetname := $(shell basename ${srcdir}) | ||
|
||
all: run | ||
|
||
print: | ||
${powershell} python3 ${srcdir}/channel_size.py -p | ||
|
||
run: | ||
mkdir -p build | ||
cd build && ${powershell} python3 ${srcdir}/run.py | ||
mkdir -p ${srcdir}/build | ||
cd ${srcdir}/build && ${powershell} python3 ${srcdir}/channel_size.py | ||
|
||
clean: | ||
rm -rf build __pycache__ | ||
rm -rf ${srcdir}/build ${srcdir}/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.