Skip to content

Commit

Permalink
passthrough kernel example working again
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Sep 17, 2024
1 parent 3dc55ac commit e08b022
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
4 changes: 2 additions & 2 deletions programming_examples/basic/dma_transpose/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

# TODO: clean up placement
# TODO: logic to put dummy core if link has core location but core not specified
worker_program = MyWorker(None, [], coords=(0, 2))
my_link = MyObjectFifoLink([of_in.second], [of_out.first], coords=(0, 2))
worker_program = MyWorker(None, [], coords=(0, 2), intermediate=AnyMemtile)
# my_link = MyObjectFifoLink([of_in.second], [of_out.first], coords=(0, 2))

# TODO: take memref_type for input/output instead?
inout_program = SimpleFifoInOutProgram(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,27 @@ def sequence_fn(A, B, C, inA, inB, outC):
[inA.first, inB.first, outC.second],
coords=(0, 0),
)

# AnyMemtile
c = LogicalCore()
c2 = c.neighbor()

worker_program = MyWorker(
core_fn, [memA.second, memB.second, memC.first, zero, matmul], coords=(0, 2)
core_fn,
[memA.second, memB.second, memC.first, zero, matmul],
AnyCore, # coords=(0, 2)
)

my_program = MyProgram(
NPU1Col1(),
worker_programs=[worker_program],
links=[inALink, inBLink, outCLink],
inout_program=inout_program,
placer=SequentialPlace(), # GraphBasedPlacer() # CoreOnlyPlace() -> anything memtile has to be decided by Programmer
)

# g = my_program.get_dataflow_graph()

my_program.resolve_program()


Expand Down
45 changes: 45 additions & 0 deletions programming_examples/basic/passthrough_kernel/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,48 @@ def core_fn(of_in, of_out, passThroughLine):
NPU1Col1(), worker_programs=[worker_program], inout_program=inout_program
)
my_program.resolve_program()

"""
Brainstorming on FifoDepth:
Depth:
* MyObjectFifo(n, line_type)
* Expect strictly == or < n for actual depth
* MyObjectFifo([n, m], line_type)
* object_fifo(prod, [cons1, cons2], elem_depth=[prod_depth, cons_depth1, cons_depth2])
* We have examples where sometimes cons1 close, cons2 is far (skip connection - have as far as 7). If gave 1 single depth of 7 -- too much.
* Need to choose which depths to force/not_force
* MyObjectFifo(line_type)
* Expect highest some n+1 ??
* MyObjectFifo(n, line_type, force_depth=True)
* ALWAYS n
m = MyObjectFifo()
m.first.enforce_depth()
Can write a number or array. Number is treated flexibly. Array is treated strictly.
Force may lead to deadlock.
Not clean case:
* How to enforce depths with broadcast when not shared mem? Created
Depth (Cases):
* object_fifo(prod, [cons1, cons2], elem_depth=[prod_depth, cons_depth1, cons_depth2])
* object_fifo(prod, [cons1, cons2], elem_depth=[(prod_depth, is_force), (cons_depth1, is_force), (cons_depth2, is_force)])
* object_fifo(prod, [cons1, cons2], forced_elem_depth=[])
* object_fifo(prod, cons, elem_depth=[prod_depth, cons_depth])
* if prod_depth != cons_depth -> cannot use shared? Or just discard one of the depths?
Maybe (I don't like this):
* object_fifo(prod, cons, depth?)
* object_fifo((prod, depth), (cons, depth))
TODO: ObjectFifo Skip Connection Analysis, adjusts depth for you based on that.
TODO: Maybe fusing kernels?
"""
8 changes: 4 additions & 4 deletions python/api/dataflow/inout/simplefifoinout.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def __init__(
out_strides: Optional[list[int]] = None,
dtype: np.generic = np.uint8,
):
assert bytes_in % np.prod(fifo_in.obj_type[0]) == 0
assert bytes_out % np.prod(fifo_out.obj_type[0]) == 0
assert bytes_in % np.prod(fifo_in.obj_type.shape) == 0
assert bytes_out % np.prod(fifo_in.obj_type.shape) == 0
assert bytes_in > 0
assert bytes_out > 0

Expand Down Expand Up @@ -91,8 +91,8 @@ def resolve(
loc: ir.Location = None,
ip: ir.InsertionPoint = None,
) -> None:
tensor_in_ty = MyTensorType(self.bytes_in, self.dtype).memref_type
tensor_out_ty = MyTensorType(self.bytes_out, self.dtype).memref_type
tensor_in_ty = MyTensorType(self.dtype, [self.bytes_in]).memref_type
tensor_out_ty = MyTensorType(self.dtype, [self.bytes_out]).memref_type

@runtime_sequence(tensor_in_ty, tensor_out_ty)
def sequence(inTensor, outTensor):
Expand Down
6 changes: 3 additions & 3 deletions python/api/dataflow/objectfifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __init__(
name: str = None,
end1: MyObjectFifoEndpoint = None,
end2: MyObjectFifoEndpoint = None,
dimensionsToStream=list[list[int]], # TODO(erika): needs a type
dimensionsFromStreamPerConsumer=list[list[int]], # TODO(erika): needs a type
dimensionsToStream=None, # TODO(erika): needs a type
dimensionsFromStreamPerConsumer=None, # TODO(erika): needs a type
):
self.__depth = depth
self.__obj_type = obj_type
Expand Down Expand Up @@ -86,7 +86,7 @@ def resolve(
if self.__op == None:
assert self.end1 != None, "ObjectFifo missing endpoint 1"
assert self.end2 != None, "ObjectFifo missing endpoint 2"
assert self.__memref_type != None, "ObjectFifo missing memref_type"
assert self.__obj_type != None, "ObjectFifo missing object type"
self.__op = object_fifo(
self.name,
self.end1.get_tile().op,
Expand Down
11 changes: 3 additions & 8 deletions python/api/kernels/binkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ def resolve(
if self.__op == None:
resolved_inout_types = []
for t in self.__inout_types:
try:
if isinstance(t, MyTensorType):
dtype = t.memref_type
else:
dtype = np_dtype_to_mlir_type(t)
except Exception:
dtype = get_arg_types(t)
if dtype is None:
# Interpret as a dummy memref
dtype = MemRefType.get(
shape=t[0], element_type=np_dtype_to_mlir_type(t[1])
)
resolved_inout_types.append(dtype)
self.__op = external_func(self.__name, inputs=resolved_inout_types)

Expand Down
4 changes: 3 additions & 1 deletion python/api/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ def dtype(self) -> np.generic:

def __eq__(self, other):
# TODO: may want to be equal to numpy datatypes as well??
return self.__my_numpy_type == other.__my_numpy_type
if other:
return self.__my_numpy_type == other.__my_numpy_type
return False
2 changes: 1 addition & 1 deletion python/api/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class MyWorker(MyObjectFifoEndpoint):
def __init__(
self,
core_fn: Optional[Callable[[Union[ObjectFifoHandle, MyKernel], None]]],
core_fn: Optional[Callable[[Union[ObjectFifoHandle, MyKernel]], None]],
fn_args: list[Union[ObjectFifoHandle, MyKernel]] = [],
coords: tuple[int, int] = None,
):
Expand Down

0 comments on commit e08b022

Please sign in to comment.