llvm / llvm/circt

[Handshake] Allow handshake ops to be used outside of a `handshake.func` (?)

Open
#5,949 0 comments 0 reactions 0 assignees View on GitHub
Handshake
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

I've been thinking about whether it's reasonable to restrict `handshake` operations to having `handshake.func`s as their parent op. I think the main argument for doing so currently is avoiding confusion between e.g. `func.func` and `handshake.func`, with regards to the whole _"every SSA value is a handshake channel"_ (i.e. fine-grained dataflow).

However, it's exactly that latter part which I'm questioning. We may want to use handshake within _any_ region which has fine-grained dataflow semantics. In other words, would it make more sense to say that Handshake ops should have something like `ParentOf<"FineGrainedDataflowRegionOpInterface">` (note: this isn't currently feasible, since interfaces can't be used in `ParentOf`, but a capability that many dialects need about... so probably will be possible soon).

This would mean that I could bring my own op, which implements this interface, and use handshake (and handshake lowerings) to transform my custom fine-grained dataflow operation into the more explicit, low-level format that DC represents:

```mlir
// myDialect.fgdf implements FineGrainedDataflowRegionOpInterface for its inner region
%out = myDialect.fgdf(%a : !myDialect.MyType, %b : !myDialect.MyType) -> (out : !nyDialect.MyType) {
^bb0(%a_ : i32, %b_ : i32)
// this is a fine-grained dataflow region wherein we can reason about using
// handshake operations and semantics.
%res = arith.addi %a_, %b_ : i32
return %res : i32
}

// -------------------------------------------------------------------------- //

// This means that we can use handshake-style lowering to lower the above to:
%in0 = myDialect.to_dc %a : !myDialect.MyType -> !dc.value
%in1 = myDialect.to_dc %b : !myDialect.MyType -> !dc.value

%token, %output = dc.unpack %in0 : !dc.value
%token_0, %output_1 = dc.unpack %in1 : !dc.value
%0 = dc.join %token, %token_0
%1 = arith.addi %output, %output_1 : i32
%2 = dc.pack %0, %1 : i32

%out = myDialect.from_dc %2 : !dc.value -> !myDialect.MyType
hw.output %out : !myDialect.MyType
```

tl;dr: i want to use handshake ops outside of `handshake.func`.

CC @Dinistro @mikeurbach @RamirezLucas @teqdruid

Contributor guide

No contributing guide indexed for this repository

Research direction

No files or tests are identified in the issue. Start by reviewing the Handshake operation restrictions around handshake.func and the proposed ParentOf<"FineGrainedDataflowRegionOpInterface"> capability; done would require an agreed design for using Handshake operations in custom fine-grained dataflow regions and their DC lowering.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.