cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
326 stars 92 forks source link

Support FIFOs as pass-by-reference argument to HCL module #306

Open hecmay opened 4 years ago

hecmay commented 4 years ago

This PR will enhance .to()'s support on inter-function FIFO streaming.

As an example, in the dummy program, func_A is the sequential producer and func_B is the consumer. We want to implement intermediate tensor inputB as a FIFO to pass data between these two functions. The expected HCL program:

@hcl.def_()
def func_A(A, B):
        with hcl.for_(1, 10) as i:
            B[i] = A[i] + 1
@hcl.def_()
def func_B(B, C):
        with hcl.for_(1, 10) as i:
            C[i] = B[i]

func_A(inputA, inputB)
func_B(inputB, inputC)

s.to(func_A.inputB, func_B.inputB, depth=1)

The output HLS code:

void func_A(int* A, stream<int>& B) {
    for (i,, 0 ,10) {
        B.write(A[i] + 1);
    }
}
void func_B(stream<int>& B, int* C) {
    for (i,, 0 ,10) {
        C[i] = B.read();
    }
}
hsl::stream<int> B;
func_A(A, B);
func_B(B, C);