Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IR][dataflow] Add explicit stream type in MLIR #249

Merged
merged 3 commits into from
Nov 6, 2024
Merged

Conversation

chhzh123
Copy link
Member

@chhzh123 chhzh123 commented Nov 6, 2024

Description

This PR adds an explicit stream type (stream<T>) in the Allo-MLIR dialect to replace the original memref implementation. Specifically, three operations are added:

  1. allo.stream_construct(): Create a new stream object
  2. allo.stream_get(%stream): Get data from a stream
  3. allo.stream_put(%stream, %data): Put data into a stream

The dataflow interface uses these operations to construct the IR. Now it can support declaring an array in a stream, which may be useful for DMA transmission. Also, we added codengen support to the HLS backend to generate these operations using hls::stream

Examples

module {
  func.func @producer_0(%arg0: memref<16x16xf32>, %arg1: !allo.stream<f32, 2>) attributes {stypes = "_g"} {
    affine.for %arg2 = 0 to 16 {
      affine.for %arg3 = 0 to 16 {
        %0 = affine.load %arg0[%arg2, %arg3] {from = "A"} : memref<16x16xf32>
        %alloc = memref.alloc() {name = "out"} : memref<f32>
        affine.store %0, %alloc[] {to = "out"} : memref<f32>
        %1 = affine.load %alloc[] {from = "out"} : memref<f32>
        allo.stream_put(%arg1, %1) : !allo.stream<f32, 2> contains f32
      } {loop_name = "j"}
    } {loop_name = "i", op_name = "S_i_j_0"}
    return
  }
  func.func @consumer_0(%arg0: memref<16x16xf32>, %arg1: !allo.stream<f32, 2>) attributes {stypes = "_g"} {
    %cst = arith.constant 1.000000e+00 : f32
    affine.for %arg2 = 0 to 16 {
      affine.for %arg3 = 0 to 16 {
        %0 = allo.stream_get(%arg1) {name = "data"} : !allo.stream<f32, 2> -> f32
        %1 = arith.addf %0, %cst : f32
        affine.store %1, %arg0[%arg2, %arg3] {to = "B"} : memref<16x16xf32>
      } {loop_name = "j"}
    } {loop_name = "i", op_name = "S_i_j_0"}
    return
  }
  func.func @top(%arg0: memref<16x16xf32>, %arg1: memref<16x16xf32>) attributes {dataflow} {
    %0 = allo.stream_construct() {dst = "consumer", src = "producer"} : !allo.stream<f32, 2>
    call @producer_0(%arg0, %0) : (memref<16x16xf32>, !allo.stream<f32, 2>) -> ()
    call @consumer_0(%arg1, %0) {last} : (memref<16x16xf32>, !allo.stream<f32, 2>) -> ()
    return
  }
}

Checklist

  • PR's title starts with a category (e.g. [Bugfix], [IR], [Builder], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage (It would be better to provide ~2 different test cases to test the robustness of your code)
  • Code is well-documented

@chhzh123 chhzh123 merged commit 85ff5e7 into main Nov 6, 2024
1 check passed
@chhzh123 chhzh123 deleted the stream_type branch November 6, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant