Skip to content

Commit

Permalink
Save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Oct 15, 2024
1 parent b52c6ec commit 181368a
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 114 deletions.
7 changes: 7 additions & 0 deletions programming_examples/basic/passthrough_kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ build/aie_trace__lineBased_8b_${data_size}.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${data_size} ${trace_size} > $@

build/iron2_aie2_lineBased_8b_${data_size}.mlir: ${srcdir}/iron2_aie2.py
mkdir -p ${@D}
python3 $< ${data_size} 0 > $@

mlir_diff: build/aie2_lineBased_8b_${data_size}.mlir build/iron2_aie2_lineBased_8b_${data_size}.mlir
diff build/aie2_lineBased_8b_${data_size}.mlir build/iron2_aie2_lineBased_8b_${data_size}.mlir

build/passThrough.cc.o: passThrough.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import sys

from aie.api.io.iocoordinator import IOCoordinator
from aie.api.dataflow.iofifo import IOObjectFifo
from aie.api.kernels import BinKernel
from aie.api.dataflow.objectfifo import ObjectFifo
from aie.api.kernels.binkernel import BinKernel
from aie.api.program import Program
from aie.api.worker import Worker
from aie.api.phys.devices import NPU1Col1
from aie.api.phys.device import NPU1Col1
from aie.extras.dialects.ext.scf import _for as range_
from aie.helpers.datatiler import DataTiler
from aie.extras.util import DataTiler

try:
vector_size = int(sys.argv[1])
Expand All @@ -30,16 +30,17 @@
vector_type = np.ndarray[(vector_size,), np.dtype[np.uint8]]

io = IOCoordinator()
a_in = io.input(vector_type)
b_out = io.output(vector_type)
a_in = io.inout_data(vector_type)
b_out = io.inout_data(vector_type)

of_in = IOObjectFifo(2, line_type, io)
of_out = IOObjectFifo(2, line_type, io)
of_in = ObjectFifo(2, line_type)
of_out = ObjectFifo(2, line_type)

tiler = DataTiler(vector_type)
for t in io.tile_loop(tiler):
of_in.fill(t, a_in, coords=(0, 0))
of_out.drain(t, b_out, coords=(0, 0))
tile_iter = io.tile_loop(tiler)
for t in tile_iter:
io.fill(of_in.first, t, a_in, coords=(0, 0))
io.drain(of_out.second, t, b_out, coords=(0, 0))

passthrough_fn = BinKernel(
"passThroughLine",
Expand All @@ -57,9 +58,9 @@ def core_fn(of_in, of_out, passThroughLine):
of_out.release(1)


my_worker = Worker(core_fn, [of_in, of_out, passthrough_fn], coords=(0, 2))
my_worker = Worker(core_fn, [of_in.second, of_out.first, passthrough_fn], coords=(0, 2))
my_program = Program(NPU1Col1(), io, workers=[my_worker])
module = my_program.resovle_program()
module = my_program.resolve_program()
module.validate()
print(module)

Expand Down
15 changes: 0 additions & 15 deletions programming_examples/basic/passthrough_pykernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,11 @@ build/aie.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${PASSTHROUGH_SIZE} > $@

build/aie_experimental.mlir: ${srcdir}/aie2_experimental.py
mkdir -p ${@D}
python3 $< ${PASSTHROUGH_SIZE} > $@

mlir_diff: build/aie.mlir build/aie_experimental.mlir
diff build/aie.mlir build/aie_experimental.mlir

build/final_${data_size}.xclbin: build/aie.mlir
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=insts_${data_size}.txt $(<:%=../%)

build/experimental_final_${data_size}.xclbin: build/experimental_aie.mlir
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=experimental_insts_${data_size}.txt $(<:%=../%)

${targetname}_${data_size}.exe: ${srcdir}/test.cpp
rm -rf _build
mkdir -p _build
Expand All @@ -59,8 +47,5 @@ run: ${targetname}_${data_size}.exe build/final_${data_size}.xclbin build/insts_
run_py: build/final_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} python3 ${srcdir}/test.py -s ${data_size} -x build/final_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE

run_experimental: build/experimental_final_${data_size}.xclbin build/experimental_insts_${data_size}.txt
${powershell} python3 ${srcdir}/test.py -s ${data_size} -x build/final_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE

clean:
rm -rf build _build ${targetname}*.exe

This file was deleted.

3 changes: 1 addition & 2 deletions python/api/dataflow/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

from abc import abstractmethod
from ..phys.tile import Tile
from ..resolvable import Resolvable


class ObjectFifoEndpoint(Resolvable):
class ObjectFifoEndpoint:
@property
@abstractmethod
def tile(self) -> Tile | None: ...
29 changes: 0 additions & 29 deletions python/api/dataflow/iofifo.py

This file was deleted.

6 changes: 4 additions & 2 deletions python/api/dataflow/objectfifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ def resolve(

def _set_endpoint(self, endpoint: ObjectFifoEndpoint, first: bool = True) -> None:
if first:
assert self.end1 == None, "ObjectFifo already assigned endpoint 1"
assert (
self.end1 == None or self.end1 == endpoint
), f"ObjectFifo already assigned endpoint 1 ({self.end1})"
self.end1 = endpoint
else:
assert self.end2 == None, "ObjectFifo already assigned endpoint 2"
# TODO: need rules about shim tiles here
self.end2.append(endpoint)

def _acquire(
Expand Down
97 changes: 67 additions & 30 deletions python/api/io/iocoordinator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Address circular dependency between IOCoordinator and InOutData
from __future__ import annotations

import numpy as np

# Address circular dependency between IOCoordinator and ObjectFifoHandle
from __future__ import annotations
from ...extras.util import DataTiler
from ..dataflow.objectfifo import ObjectFifoHandle
from ..dataflow.endpoint import ObjectFifoEndpoint
from ..phys.tile import Tile

from ..dataflow.iofifo import IOObjectFifo
from .shimpolicy import SingleShimPolicy, DistributeShimPolicy, ShimPlacementPolicy
from .syncpolicy import (
SubtileLoopSyncPolicy,
Expand All @@ -21,36 +25,52 @@ class DataTileSpecifier:
pass


class InputData:
class InOutData:
def __init__(self, input_type: type[np.ndarray]):
self.input_type = input_type


class OutputData:
def __init__(self, output_type: type[np.ndarray]):
self.output_type = output_type
class IOEndpoint(ObjectFifoEndpoint):
def __init__(self, column: int, row: int) -> IOEndpoint:
self.__tile = Tile(column, row)

@property
def tile(self) -> Tile | None:
return self.__tile

def __eq__(self, other: object) -> bool:
if not isinstance(other, IOEndpoint):
return NotImplemented
return self.tile() == other.tile()

def __str__(self) -> str:
return f"IOEndpoint({self.tile()})"


class IOIterator:
def __iter__(
def __init__(
self,
io_coord: IOCoordinator,
data_tile_iterator: DataTiler,
yield_final=False,
yield_every=False,
):
) -> IOIterator:
self.io_coord = io_coord
self.data_tile_iterator = data_tile_iterator
self.yield_final = yield_final
self.yield_every = yield_every
self.first = True

def __iter__(self):
return self

def __next__(self):
tile_next = next(self.data_tile_iterator)
if not self.first:
self.first = False
if self.yield_every:
self.io_coord._insert_sync("every")
else:
self.first = False
if tile_next == None:
if self.yield_final:
self.io_coord._insert_sync("final")
Expand All @@ -63,35 +83,52 @@ def __init__(
self,
shim_policy: ShimPlacementPolicy = SingleShimPolicy,
sync_policy: DMASyncPolicy = SingleSyncPolicy,
):
self.shim_policy = shim_policy
self.sync_policy = sync_policy
self.inputs = []
self.outputs = []
self.ops = []

def input(self, input_type: type[np.ndarray]) -> InputData:
self.inputs.append(InputData(input_type))
return self.inputs[-1]
) -> IOCoordinator:
self.__shim_policy = shim_policy
self.__sync_policy = sync_policy
self.__inout_data = []
self.__ops = []
self.__fifos = set()

def output(self, output_type: type[np.ndarray]) -> OutputData:
self.outputs.append(InputData(output_type))
return self.outputs[-1]
def inout_data(self, input_type: type[np.ndarray]) -> InOutData:
self.__inout_data.append(InOutData(input_type))
return self.__inout_data[-1]

def fill(
self, in_fifo: IOObjectFifo, data_tile: DataTileSpecifier, source: InputData
self,
in_fifo: ObjectFifoHandle,
data_tile: DataTileSpecifier,
source: InOutData,
coords: tuple[int, int] | None = None,
) -> None:
assert source in self.inputs
self.ops.append("DMA fill({in_fifo}, {data_tile}, {source})")
assert source in self.__inout_data
if coords:
column, row = coords
io_endpoint = IOEndpoint(column, row)
in_fifo.set_endpoint(io_endpoint)
self.__fifos.add(in_fifo)
self.__ops.append("DMA fill({in_fifo}, {data_tile}, {source})")

def drain(
self, out_fifo: IOObjectFifo, data_tile: DataTileSpecifier, dest: OutputData
self,
out_fifo: ObjectFifoHandle,
data_tile: DataTileSpecifier,
dest: InOutData,
coords: tuple[int, int] | None = None,
) -> None:
assert dest in self.outputs
self.ops.append("DMA drain({out_fifo}, {data_tile}, {source})")
assert dest in self.__inout_data
if coords:
column, row = coords
io_endpoint = IOEndpoint(column, row)
out_fifo.set_endpoint(io_endpoint)
self.__fifos.add(out_fifo)
self.__ops.append("DMA drain({out_fifo}, {data_tile}, {source})")

def get_fifos(self) -> list[ObjectFifoHandle]:
return self.__fifos.copy()

def tile_loop(self, iter: DataTiler) -> IOIterator:
return IOIterator(self, iter)

def _insert_sync(self, sync_str):
self.ops.append(f"Sync HERE({sync_str})")
self.__ops.append(f"Sync HERE({sync_str})")
13 changes: 12 additions & 1 deletion python/api/phys/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,16 @@ def op(self) -> TileOp:

@op.setter
def op(self, op: TileOp):
assert self.__op == None
assert self.__op == None or self.__op == op
self.__op = op

def __eq__(self, other: object) -> bool:
if not isinstance(other, Tile):
return NotImplemented
return self.col == other.col and self.row == other.row

def __str__(self) -> str:
return f"Tile({self.col}, {self.row})"

def __hash__(self):
return hash(str(self))
Loading

0 comments on commit 181368a

Please sign in to comment.