cornell-zhang / heterocl

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

Connect SODA stencil node with FIFO channels in VHLS backend #296

Closed hecmay closed 3 years ago

hecmay commented 3 years ago

Problem Description

The .stencil() primitive generates a Stencil IR node in HCL program, which will later be handled SODA compiler to generate high performance stencil kernels with optimized dataflow architecture. Here is an example of usage:

def jacobi(input_image, output_image):
    def jacobi_kernel(y, x):
        return (input_image[y+1, x-1] +
                input_image[y  , x  ] +
                input_image[y+1, x  ] +
                input_image[y+1, x+1] +
                input_image[y+2, x  ]) / 5

    return hcl.update(output_image, jacobi_kernel, name=output_image.name)

s = hcl.create_schedule([input_image, output_image], jacobi)
s[jacobi.output].stencil()

The generated HLS code:

void default_function(float input[480][640], float output[480][640]) {
  #include "soda_stencil.h"
  soda_input_output_kernel(input, output);
}

Right now, stencil kernel takes arrays as input arguments by default. The goal to generate stencil kernel with hls::stream input and outputs when .stencil() primitive is used along with to() for the stencil stage.

Target

Expected input program

s = hcl.create_schedule([input_image, output_image], jacobi)
s[jacobi.output].stencil()
s.to(x, s[jacobi.output])
s.to(jacobi.output.y, output)

Expected output

void default_function(hls::stream<float>& input, hls::stream<float> &output) {
  #include "soda_stencil.h"
  soda_input_output_kernel(input, output);
}
hecmay commented 3 years ago

Support added in PR #350

hecmay commented 3 years ago

Test case: https://github.com/cornell-zhang/heterocl/blob/heteroflow/tests/test_schedule_stream.py#L362