This is an archive of the discontinued LLVM Phabricator instance.

[mlir][memref] Add runtime verification for memref::CastOp
ClosedPublic

Authored by springerm on Nov 24 2022, 7:12 AM.

Details

Summary

Verify unranked -> ranked casts and casts of dynamic sizes/offset/strides to static ones.

Depends On D138647

Diff Detail

Event Timeline

springerm created this revision.Nov 24 2022, 7:12 AM
springerm requested review of this revision.Nov 24 2022, 7:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2022, 7:12 AM
springerm updated this revision to Diff 480028.Dec 5 2022, 2:29 AM

minor update

springerm updated this revision to Diff 484808.Dec 22 2022, 5:46 AM

minor update

Looks good to me. But can we add more tests. For example, the case below, here c2 should be verified by your code but c3 should fail, right?

func.func @c1(%m: memref<?x?xf32>) -> memref<*xf32> {
  %0 = memref.cast %m : memref<?x?xf32> to memref<*xf32>
  return %0 : memref<*xf32>
}
func.func @c2(%m: memref<*xf32>) -> memref<?x?xf32> {
  %0 = memref.cast %m : memref<*xf32> to memref<?x?xf32>
  return %0 : memref<?x?xf32>
}
func.func @c3(%m: memref<*xf32>) -> memref<?xf32> {
  %0 = memref.cast %m : memref<*xf32> to memref<?xf32>
  return %0 : memref<?xf32>
}
func.func @main() {
  %a = memref.alloc() : memref<5x5xf32>
  %c = memref.cast %a : memref<5x5xf32> to memref<?x?xf32>
  %res = func.call @c1(%c) : (memref<?x?xf32>) -> memref<*xf32> 
  func.call @c2(%res) : (memref<*xf32>) -> (memref<?x?xf32>)
  func.call @c3(%res) : (memref<*xf32>) -> (memref<?xf32>)
  return
}

Also, runtime error text does not tell me which code/location fails. It prints the following text for example. I am not sure you can print the location correctly, but can we at least print the problematic IR?
memref::CastOp: rank mismatch

springerm updated this revision to Diff 486825.Jan 6 2023, 5:22 AM

address comments

guraypp accepted this revision.Jan 6 2023, 5:32 AM

Error messages are now very clear, thanks!

This revision is now accepted and ready to land.Jan 6 2023, 5:32 AM
This revision was landed with ongoing or failed builds.Jan 6 2023, 5:39 AM
This revision was automatically updated to reflect the committed changes.