tt-mlir: [Bounty $500] Implement specific op includes generation

Implement proper creation of emitc::IncludeOps, taking into account differences between unary and binary op kernel includes, which of them exist in general, which are specific to unary vs binary (if any) and which are specific to the concrete op.

For example, exp call needs compute_kernel_api/eltwise_unary/exp.h included.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I see exp and other defined in include/ttmlir/Dialect/TTIR/IR/TTIROps.td, should I also include ops in this file?

No TTIR is a different dialect that doesn’t need these kernel includes.

Hey @wusatosi this all sounds great!! Thank you for the detailed writeup.

what’s the desired approach for testing this going to be like? Am I expected to create a lit test for each of the operation?

TBH I’m not sure we need this level of testing, I think just our usual testing of the ops will transitively cover this because compilation will fail otherwise! 😃

I think it’s probably OK to try and put together a PR and just ensure that existing CI passes. It’s understood that it’ll be an ongoing effort to manage these header lists esp as metal evolves and refactors things.

I was gonna work on fixing this as part of my PR until I saw the comment in the code that link to this issue lol.

@wusatosi In case you haven’t found out yet, for unary SFPU ops we should include sfpu_split_includes.h and emit the macro that corresponds to the op(s) at hand just before the inclusion.

Hey just an update I am still working on this.

@wusatosi thanks for picking this one up! I think the task has a few parts to it:

  • Inside of lib/Target/TTKernel/TTKernelToCpp.cpp there’s a helper class called ScopedModuleHelper, you’ll see today we just unconditionally emit a bunch of includes there depending on the ThreadType.
  • We should make a static map, maybe in a new header include/ttmlir/Target/TTKernel/TTKernelIncludesMap.h, that maps op.getCallee() -> [StringRef includes].
  • Within ScopedModuleHelper we loop over the whole region and collect all required headers into a set, sort it in alphanumeric order and then emit the includes via verbatim op.

Example of the static map (unsure if DenseMap is best here, but for now let’s go with that):

static DenseMap<StringRef, ArrayRef<StringRef>> requiredHeadersMap = {
  {"tilize_block", {"compute_kernel_api/tile_move_copy.h"}},
};

@vroubtsovTT / @xanderchin to review, if you have some ideas on how this should work.

is this P2 because it has dependencies on something else? Could this become a bounty?

I’ve marked it as P2, probably everything marked as P2 will be punted out of this milestone into the next.