Skip to content

Commit

Permalink
Add NoC Mcast Ops in D2M (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesousa-TT committed Nov 25, 2024
1 parent d330f00 commit 417da06
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
62 changes: 62 additions & 0 deletions include/ttmlir/Dialect/TTKernel/IR/TTKernelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,68 @@ def TTKernel_CastToL1PtrOp : TTKernel_Op<"reinterpret_cast<volatile tt_l1_ptr ui
let results = (outs TTKernel_L1AddrPtr:$l1_ptr);
}

//===----------------------------------------------------------------------===//
// TTKernel Multicast NoC operations
//===----------------------------------------------------------------------===//

def TTKernel_GetNocMulticastAddrOp : TTKernel_Op<"get_noc_multicast_addr"> {
let summary = "GetNocMulticastAddr";
let description = [{
GetNocMulticastAddr
}];

let arguments = (ins I32:$noc_x_start, I32:$noc_y_start, I32:$noc_x_end, I32:$noc_y_end, I32:$addr, Optional<I8>:$noc);
let results = (outs TTKernel_NocAddr:$mcastNocAddr);
}

def TTKernel_NocAsyncWriteMulticastOnePacketOp : TTKernel_Op<"noc_async_write_multicast_one_packet"> {
let summary = "NocAsyncWriteMulticastOnePacket";
let description = [{
NocAsyncWriteMulticastOnePacket
this issues only a single packet with size <= NOC_MAX_BURST_SIZE (ie maximum packet size)
}];

let arguments = (ins I32:$srcLocalL1Addr, TTKernel_NocAddr:$dstNocAddrMulticast, I32:$size, I32:$num_dests, OptionalAttr<BoolAttr>:$linked, OptionalAttr<BoolAttr>:$multicast_path_reserve, Optional<I8>:$noc);
}

def TTKernel_NocAsyncWriteMulticastOp : TTKernel_Op<"noc_async_write_multicast"> {
let summary = "NocAsyncWriteMulticast";
let description = [{
Initiates an asynchronous write from a source address in L1 memory on the
Tensix core executing this function call to a rectangular destination grid.
The destinations are specified using a uint64_t encoding referencing an
on-chip grid of nodes located at NOC coordinate range
(x_start,y_start,x_end,y_end) and a local address created using
*get_noc_multicast_addr* function. Also, *see noc_async_write_barrier*.

The destination nodes can only be a set of Tensix cores + L1 memory address.
The destination nodes must form a rectangular grid. The destination L1
memory address must be the same on all destination nodes.

With this API, the multicast sender cannot be part of the multicast
destinations. If the multicast sender has to be in the multicast
destinations (i.e. must perform a local L1 write), the other API variant
*noc_async_write_multicast_loopback_src* can be used.

Note: The number of destinations needs to be non-zero. Besides that,
there is no restriction on the number of destinations, i.e. the
multicast destinations can span the full chip. However, as mentioned
previously, the multicast source cannot be part of the destinations. So, the
maximum number of destinations is 119.
}];

let arguments = (ins I32:$srcLocalL1Addr, TTKernel_NocAddr:$dstNocAddrMulticast, I32:$size, I32:$num_dests, OptionalAttr<BoolAttr>:$linked, OptionalAttr<BoolAttr>:$multicast_path_reserve, Optional<I8>:$noc);
}

def TTKernel_NocAsyncWriteMulticastLoopbackSrcOp : TTKernel_Op<"noc_async_write_multicast_loopback_src"> {
let summary = "NocAsyncWriteMulticastLoopbackSrc";
let description = [{
NocAsyncWriteMulticastLoopbackSrc
}];

let arguments = (ins I32:$srcLocalL1Addr, TTKernel_NocAddr:$dstNocAddrMulticast, I32:$size, I32:$num_dests, OptionalAttr<BoolAttr>:$linked, OptionalAttr<BoolAttr>:$multicast_path_reserve, Optional<I8>:$noc);
}

//===----------------------------------------------------------------------===//
// TTKernel Misc operations
//===----------------------------------------------------------------------===//
Expand Down
9 changes: 8 additions & 1 deletion lib/Conversion/TTKernelToEmitC/TTKernelToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class TTMetalToEmitCOpaqueRewriter : public OpConversionPattern<SourceOp> {
} else if constexpr (std::is_same_v<SourceOp, ttkernel::GetArgValOp>) {
SmallVector<Attribute, 1> template_args;

template_args.push_back(emitc::OpaqueAttr::get(op.getContext(), "uint32_t"));
template_args.push_back(
emitc::OpaqueAttr::get(op.getContext(), "uint32_t"));

return ArrayAttr::get(op.getContext(), template_args);
}
Expand Down Expand Up @@ -369,6 +370,12 @@ class ConvertTTKernelToEmitCPass
TTMetalToEmitCOpaqueRewriter<ttkernel::NocAsyncReadBarrierOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::NocAsyncWriteOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::NocAsyncWriteBarrierOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::GetNocMulticastAddrOp>,
TTMetalToEmitCOpaqueRewriter<
ttkernel::NocAsyncWriteMulticastOnePacketOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::NocAsyncWriteMulticastOp>,
TTMetalToEmitCOpaqueRewriter<
ttkernel::NocAsyncWriteMulticastLoopbackSrcOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::UnaryOpInitCommonOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::CopyTileOp>,
TTMetalToEmitCOpaqueRewriter<ttkernel::ExpTileInitOp>,
Expand Down

0 comments on commit 417da06

Please sign in to comment.