-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dma_task
in programming examples
#1919
Draft
hunhoffe
wants to merge
22
commits into
main
Choose a base branch
from
port-examples-dma-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,883
−63
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b6d7180
Start to port programming examples to use dma task
hunhoffe 49fa9e1
remove unneeded field
hunhoffe b43a48d
Finish adding alternate (dma task) impls of programming_examples/vision
hunhoffe fb59e20
Add alt version for ml programming examples
hunhoffe bbc991f
Add convenience wrappers around dma_*_task functions
hunhoffe 2bfb325
Start porting some of the basic examples to use the dma task structure
hunhoffe 88a033f
Merge branch 'main' into port-examples-dma-task
hunhoffe 774e0e6
Finish rewriting programming examples to use dma task
hunhoffe f95bf36
Fix for [1, 1, 1, N]
jgmelber 174cdf0
Additional verification linear case patch
jgmelber bbcde4c
Default sizes to 1
jgmelber 0d86176
Use uint32_t for sizes to match transfer length for dim 0
jgmelber c7f38ec
Apply suggestions from code review
jgmelber daa4598
Revert "Default sizes to 1"
jgmelber 259b2a6
Init sizes for vec scalar mul
jgmelber 10b386b
calculate transfer len with less lines of code
hunhoffe d3ee4e6
Merge branch 'main' into port-examples-dma-task
hunhoffe efbff0e
Merge branch 'main' into port-examples-dma-task
hunhoffe ee0fa1a
Remove lingering npu_dma_memcpy_nd from alt examples
hunhoffe 5931e38
Attempt to use repeat count correctly in examples
hunhoffe 22ec2f0
Merge branch 'main' into port-examples-dma-task
hunhoffe bdc73f0
Does not fix things, but update understanding of repeat count
hunhoffe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# dma_transpose/aie2.py -*- Python -*- | ||
# | ||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates | ||
import numpy as np | ||
import sys | ||
|
||
from aie.dialects.aie import * | ||
from aie.dialects.aiex import * | ||
from aie.extras.context import mlir_mod_ctx | ||
from aie.helpers.dialects.ext.scf import _for as range_ | ||
|
||
N = 4096 | ||
M = 64 | ||
K = 64 | ||
|
||
if len(sys.argv) == 3: | ||
M = int(sys.argv[1]) | ||
K = int(sys.argv[2]) | ||
N = M * K | ||
|
||
tensor_ty = np.ndarray[(M, K), np.dtype[np.int32]] | ||
|
||
|
||
def my_passthrough(): | ||
with mlir_mod_ctx() as ctx: | ||
|
||
@device(AIEDevice.npu1_1col) | ||
def device_body(): | ||
# Tile declarations | ||
ShimTile = tile(0, 0) | ||
ComputeTile2 = tile(0, 2) | ||
|
||
# AIE-array data movement with object fifos | ||
of_in = object_fifo("in", ShimTile, ComputeTile2, 2, tensor_ty) | ||
of_out = object_fifo("out", ComputeTile2, ShimTile, 2, tensor_ty) | ||
object_fifo_link(of_in, of_out) | ||
|
||
# Set up compute tiles | ||
|
||
# Compute tile 2 | ||
@core(ComputeTile2) | ||
def core_body(): | ||
for _ in range_(sys.maxsize): | ||
pass | ||
|
||
# To/from AIE-array data movement | ||
@runtime_sequence(tensor_ty, tensor_ty, tensor_ty) | ||
def sequence(A, B, C): | ||
# The strides below are configured to read across all rows in the same column | ||
# Stride of K in dim/wrap 2 skips an entire row to read a full column | ||
in_task = dma_configure_task_for(of_in, issue_token=True) | ||
with bds(in_task) as bd: | ||
with bd[0]: | ||
shim_dma_bd( | ||
A, | ||
sizes=[1, 1, K, M], | ||
strides=[1, 1, 1, K], | ||
) | ||
EndOp() | ||
|
||
out_task = dma_configure_task_for(of_out, issue_token=True) | ||
with bds(out_task) as bd: | ||
with bd[0]: | ||
shim_dma_bd(C, sizes=[1, 1, 1, N]) | ||
EndOp() | ||
|
||
dma_start_task(in_task, out_task) | ||
dma_await_task(in_task, out_task) | ||
|
||
print(ctx.module) | ||
|
||
|
||
my_passthrough() |
12 changes: 12 additions & 0 deletions
12
programming_examples/basic/dma_transpose/run_makefile_alt.lit
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// (c) Copyright 2024 Advanced Micro Devices, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// REQUIRES: ryzen_ai, peano | ||
// | ||
// RUN: mkdir -p test_alt | ||
// RUN: cd test_alt | ||
// RUN: make -f %S/Makefile clean | ||
// RUN: env use_alt=1 make -f %S/Makefile | ||
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s | ||
// CHECK: PASS! | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm if these
EndOp
s are still necessary? I believe I've seen other places where the block terminators could be left off and that would clean this up, but it may not be possible here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can confirm though trying this in an example:
EndOp
is currently necessary.Error without it is:
However, seen in the linked test, it seems like the
EndOp
is not necessary if you callnext_bd
but I haven't fully investigated: https://github.com/Xilinx/mlir-aie/blob/main/test/python/dma_tasks.pyI think with some additional time, I could clean this up. However, the python bindings I'm working on autogenerate the dma_task code, so the user will never see this anyways. At the moment, I don't see the
EndOp
cleanup as an urgent task at this time (but it should probably be done eventually).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because aie.next_bd is also a terminator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next_bd is also a terminator so that makes sense. I agree that this isn't important, just was curious.