Skip to content

Commit

Permalink
Add issue_token attribute to IpuDmaMemcpyNdOp (#1209)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Levental <[email protected]>
  • Loading branch information
jtuyls and makslevental authored Apr 10, 2024
1 parent 904fa10 commit 066ce8f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
13 changes: 11 additions & 2 deletions include/aie/Dialect/AIEX/IR/AIEX.td
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,15 @@ def AIE_IpuDmaMemcpyNdOp: AIEX_Op<"ipu.dma_memcpy_nd", [
let summary = "half dma operator";

let description = [{
nd half dma operator
An nd half dma operator.

Programs a DMA on coordinates (`x`, `y`) to access a memory `memref` with an access
pattern specified by `offsets`, `sizes` and `strides` or `static_offsets`, `static_sizes`
and `static_strides`. The operator references the target channel through the `metadata`
symbol and specifies a descriptor `id` to be used, which will become the `bd_id` to be used
when lowered further. The `issue_token` attribute specifies whether the execution of this
operation should issue a token which can be received and read for synchronization purposes.
This `issue_token` attribute is set to `false` by default for `MM2S` for backward compatibility and **is always set to true for** `S2MM` channels.
}];

let arguments = (
Expand All @@ -485,7 +493,8 @@ def AIE_IpuDmaMemcpyNdOp: AIEX_Op<"ipu.dma_memcpy_nd", [
ConfinedAttr<DenseI64ArrayAttr, [DenseArrayCount<4>]>:$static_sizes,
ConfinedAttr<DenseI64ArrayAttr, [DenseArrayCount<3>]>:$static_strides,
FlatSymbolRefAttr:$metadata,
I64Attr:$id
I64Attr:$id,
DefaultValuedOptionalAttr<BoolAttr, "false">:$issue_token
);

let assemblyFormat = [{
Expand Down
5 changes: 4 additions & 1 deletion lib/Dialect/AIEX/Transforms/AIEDmaToIpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ struct DmaToIpuPattern : OpConversionPattern<IpuDmaMemcpyNdOp> {
// repeat_count
repeat_count = IntegerAttr::get(i32ty, sizes[3] - 1);

// issue_token
// Set the issue_token
issue_token = BoolAttr::get(ctx, op.getIssueToken());
// Earlier, all S2MM channels were implicitly assumed to issue a token.
// This logic is kept for now for backward compatibility.
if (!isMM2S)
issue_token = BoolAttr::get(ctx, true);

Expand Down
36 changes: 36 additions & 0 deletions test/Conversion/DmaToIpu/dma_to_ipu_issue_token.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===- dma_to_ipu_issue_token.mlir -----------------------------*- MLIR -*-===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// RUN: aie-opt -aie-dma-to-ipu %s | FileCheck %s

// TODO - more
// CHECK-LABEL: test1
// CHECK: aiex.ipu.writebd_shimtile
// CHECK-SAME: ddr_id = 0 : i32
// CHECK-SAME: valid_bd = 1 : i32
// CHECK: aiex.ipu.write32
// CHECK-SAME: value = 2147483649
// CHECK: aiex.ipu.writebd_shimtile
// CHECK-SAME: ddr_id = 1 : i32
// CHECK: aiex.ipu.write32
// CHECK-SAME: value = 0
module {
aie.device(ipu) {
memref.global "public" @toMem : memref<16xi32>
memref.global "public" @fromMem : memref<16xi32>
func.func @test1(%arg0: memref<16xi32>, %arg1: memref<16xi32>) {
aiex.ipu.dma_memcpy_nd(0, 0, %arg0[0, 0, 0, 0][1, 1, 16, 16][0, 0, 64]) { metadata = @toMem, id = 1 : i64, issue_token = true } : memref<16xi32>
aiex.ipu.dma_memcpy_nd(0, 1, %arg1[0, 0, 0, 16][1, 1, 16, 16][0, 0, 64]) { metadata = @fromMem, id = 0 : i64 } : memref<16xi32>
return
}
aie.shim_dma_allocation @fromMem (MM2S, 0, 0)
aie.shim_dma_allocation @toMem (S2MM, 0, 0)
}
}

0 comments on commit 066ce8f

Please sign in to comment.