-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathaie2.py
71 lines (53 loc) · 1.98 KB
/
aie2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# passthrough_dmas/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 sys
from aie.dialects.aie import *
from aie.dialects.aiex import *
from aie.dialects.scf import *
from aie.extras.dialects.ext import memref, arith
from aie.extras.context import mlir_mod_ctx
N = 4096
dev = AIEDevice.npu1_1col
col = 0
if len(sys.argv) > 1:
N = int(sys.argv[1])
if len(sys.argv) > 2:
if sys.argv[2] == "npu":
dev = AIEDevice.npu1_1col
elif sys.argv[2] == "xcvc1902":
dev = AIEDevice.xcvc1902
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[2]))
if len(sys.argv) > 3:
col = int(sys.argv[3])
def my_passthrough():
with mlir_mod_ctx() as ctx:
@device(dev)
def device_body():
memRef_ty = T.memref(1024, T.i32())
# Tile declarations
ShimTile = tile(col, 0)
ComputeTile2 = tile(col, 2)
# AIE-array data movement with object fifos
of_in = object_fifo("in", ShimTile, ComputeTile2, 2, memRef_ty)
of_out = object_fifo("out", ComputeTile2, ShimTile, 2, memRef_ty)
object_fifo_link(of_in, of_out)
# Set up compute tiles
# Compute tile 2
@core(ComputeTile2)
def core_body():
for _ in for_(sys.maxsize):
yield_([])
# To/from AIE-array data movement
tensor_ty = T.memref(N, T.i32())
@FuncOp.from_py_func(tensor_ty, tensor_ty, tensor_ty)
def sequence(A, B, C):
npu_dma_memcpy_nd(metadata="out", bd_id=0, mem=C, sizes=[1, 1, 1, N])
npu_dma_memcpy_nd(metadata="in", bd_id=1, mem=A, sizes=[1, 1, 1, N])
print(ctx.module)
my_passthrough()