llvm / llvm/circt

[Handshake] Calling `handshake.instance` with a `memref`.

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

Description

Hello! I was wondering if any handshake expert can please help me on this question.

I’m working on a tool that targets `handshake` as its backend. Currently it generates memories using `handshake.extmemory` like this

```
handshake.func @f(%v0: i32, %ctrl : none, %extmem : memref<11 x i32>) -> (none) {
... handshake.extmemory ... (%extmem : memref<11 x i32>) ...
}
```

I’m trying to find a good way to test such output. One way I’ve attempted is to write a top-level handshake wrapper that calls the circuit above, and then hope that `hlstool` will "link" them correctly.

```
handshake.func @top(%v0: i32, %ctrl : none) -> (none) attributes {argNames = ["in0", "in1"], resNames = ["out0"]} {
%extmem = memref.alloc() : memref<11 x i32>
%out = instance @f(%v0, %ctrl, %extmem) : (i32, none, memref<11 x i32>) -> (none)
return %out : none
}
```

but `hlstool` complains that
```
error: 'handshake.instance' op incorrect number of operands for the referenced handshake function
%1 = instance @f(%v0, %ctrl, %extmem) : (i32, none, memref<11 x i32>) -> (none)
```
which I suspect is due to that `memref.alloc` doesn’t work in handshake, and `%extmem` gets lowered into multiple load/store ports.

I was wondering:
- Is there a way to make the `@top` function above work (i.e., allowing it to create a memory and call `@f` with it)?
- If that doesn't work, what's the recommended way to test circuits like `@f` above? Should I just lower it to Verilog and then simulate the memory in, e.g., cocotb?

Thank you so much!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by examining the `handshake.instance` diagnostic from `hlstool` and the shown `handshake.func`/`memref.alloc` examples. Check how `handshake.extmemory` and memref operands are lowered, then determine whether the top-level wrapper can be supported or whether the documented testing path is Verilog simulation with cocotb.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.