Skip to content

[MLIR][Ptr] Allocating and deallocating ptr memrefs #156006

@Dasor

Description

@Dasor

Hi, I'm using the ptr dialect to lower some custom code, at some point I get something like this (minimal example to showcase this issue, does nothing relevant)

module {
  func.func @kernel(%arg0: !ptr.ptr<#ptr.generic_space>) {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c128 = arith.constant 128 : index
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<128x!ptr.ptr<#ptr.generic_space>>
    scf.for %arg1 = %c0 to %c128 step %c1 {
      memref.store %arg0, %alloc[%arg1] : memref<128x!ptr.ptr<#ptr.generic_space>>
    }
    memref.dealloc %alloc : memref<128x!ptr.ptr<#ptr.generic_space>>
    return
  }
}

However when trying to lower those memrefs with --finalize-memref-to-llvm nothing changes. The issue is related to the TypeConverter as there is no conversion from !ptr.ptr to any llvm type so the DeallocOpLowering won't even run on this memrefs.

As I understood by looking at the docs here a ptr is just a struct with four uint32_t so I made a custom conversion on the TypeConverter but I'm getting and invalid free.

I've also seen that the ptr dialect is expected to grow soon so maybe this has already been addressed by someone. Tagging a couple of folks who seem active in this area:
@fabianmcg @joker-eph

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions