-
Notifications
You must be signed in to change notification settings - Fork 94
/
single_buffer.py
57 lines (47 loc) · 1.7 KB
/
single_buffer.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
#
# 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 AMD Inc.
import numpy as np
from aie.dialects.aie import *
from aie.dialects.aiex import *
from aie.helpers.dialects.ext.scf import _for as range_
from aie.extras.context import mlir_mod_ctx
def single_buffer():
with mlir_mod_ctx() as ctx:
@device(AIEDevice.npu1_1col)
def device_body():
data_ty = np.ndarray[(16,), np.dtype[np.int32]]
# Tile declarations
ComputeTile2 = tile(0, 2)
ComputeTile3 = tile(0, 3)
# AIE-array data movement with object fifos
# Input
of_in = object_fifo(
"in", ComputeTile2, ComputeTile3, 1, data_ty
) # single buffer
# Set up compute tiles
# Compute tile 2
@core(ComputeTile2)
def core_body():
# Effective while(1)
for _ in range_(8):
elem_out = of_in.acquire(ObjectFifoPort.Produce, 1)
for i in range_(16):
elem_out[i] = 1
of_in.release(ObjectFifoPort.Produce, 1)
# Compute tile 3
@core(ComputeTile3)
def core_body():
# Effective while(1)
for _ in range_(8):
elem_in = of_in.acquire(ObjectFifoPort.Consume, 1)
of_in.release(ObjectFifoPort.Consume, 1)
res = ctx.module.operation.verify()
if res == True:
print(ctx.module)
else:
print(res)
single_buffer()