cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
40 stars 17 forks source link

[Pass] FixedPointToInteger causes RuntimeError when accepting non-memref function argument types #29

Closed chhzh123 closed 2 years ago

chhzh123 commented 2 years ago

As the title says, the following program causes the error. There is a non-memref type %arg2:index in the function argument.

module {
  func @top(%arg0: memref<10xi32>, %arg1: memref<10xi32>) attributes {extra_itypes = "ss", extra_otypes = ""} {
    %0 = hcl.create_loop_handle "loop_0" : !hcl.LoopHandle
    affine.for %arg2 = 0 to 10 {
      affine.for %arg3 = 0 to 10 {
        call @Stage_update_B(%arg0, %arg1, %arg3) {inputs = "compute_0,compute_1,"} : (memref<10xi32>, memref<10xi32>, index) -> ()
      } {loop_name = "loop_1"}
    } {loop_name = "loop_0"}
    %1 = hcl.create_loop_handle "loop_1" : !hcl.LoopHandle
    return
  }
  func @Stage_update_B(%arg0: memref<10xi32>, %arg1: memref<10xi32>, %arg2: index) attributes {extra_itypes = "sss"} {
    %0 = affine.load %arg0[%arg2] {from = "compute_0"} : memref<10xi32>
    %c1_i32 = arith.constant 1 : i32
    %1 = arith.addi %0, %c1_i32 : i32
    affine.store %1, %arg1[%arg2] {to = "compute_1"} : memref<10xi32>
    return
  }
}

This results from the incorrect type checking implementation. We should use isa<...> to test if a type is a specific type, and use cast<...> to actually cast the type.

zzzDavid commented 2 years ago

Thanks for the test case. This issue is because FixedPointToInteger pass assumed all arguments are memrefs. I just fixed this issue and added a corresponding test case.

chhzh123 commented 2 years ago

Similar bug in this line.