This is an archive of the discontinued LLVM Phabricator instance.

[mlir] [bufferization] Fix dealloc errors.
AbandonedPublic

Authored by cxy-1993 on Apr 7 2023, 8:09 AM.

Details

Summary

This patch solves problem that bufferization pass generate dealloc on inappropriate location.

Let me know if you need RFC on this patch, thanks for your time.

In fact, this patch can not pass test. If input IR is:

 mlir
#map = affine_map<(d0) -> (d0 * 5)>                                                
func.func @ternimator_use_not_deallocated(%arg0: tensor<10x10xf32>) -> tensor<10x10xf32> {
  %0 = scf.forall (%arg1, %arg2) in (2, 2) shared_outs(%arg3 = %arg0) -> (tensor<10x10xf32>) {
    %1 = bufferization.alloc_tensor() : tensor<5x5xf32>                            
    %2 = affine.apply #map(%arg1)                                                  
    %3 = affine.apply #map(%arg2)                                                  
    scf.forall.in_parallel {                                                       
      tensor.parallel_insert_slice %1 into %arg3[%2, %3] [5, 5] [1, 1] : tensor<5x5xf32> into tensor<10x10xf32>
    }                                                                              
  }                                                                                
  return %0 : tensor<10x10xf32>                                                    
}

when bufferize with param:

-one-shot-bufferize="allow-unknown-ops copy-before-write"

will add copy before tensor.parallel_insert_slice and cause failure. Please kindly show me how to solve this problem, thanks.

Diff Detail

Event Timeline

cxy-1993 created this revision.Apr 7 2023, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2023, 8:09 AM
cxy-1993 requested review of this revision.Apr 7 2023, 8:09 AM

This is tricky... I think the ParallelInsertSliceOp should not bufferize to a memory write. Then, a copy would never be inserted there. I.e., ParallelInsertSliceOpInterface::bufferizesToMemoryWrite should always return false. Can you give that a try and see if it fails any tests? I haven't fully thought this through yet and may be missing something...

Can you try this patch: https://reviews.llvm.org/D148408. I ran into a similar issue today and I think this should fix it.

Can you try this patch: https://reviews.llvm.org/D148408. I ran into a similar issue today and I think this should fix it.

Thanks for your reply, Sorry for not replying to the message in time.
This patch have solved my problem, thanks.

As https://reviews.llvm.org/D148408 , is any op contains in a terminator region (e.g. : tensor.parallel_insert_slice ) should move user before terminator after bufferize?

cxy-1993 abandoned this revision.Apr 15 2023, 7:44 PM