Dialect Resources dropped when compiling to flow
- Dominant language
- C++
- Stars
- 3.9k
- Forks
- 1k
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 47
Description
### What happened?
Dialect resources are dropped when coming to flow.
### Steps to reproduce your issue
Starting with this IR
```
module {
util.global private @constant {inlining_policy = #util.inline.never} = dense_resource : tensor<4xf32>
func.func @abs(%arg0: tensor<4xf32>) -> tensor<4xf32> {
%constant = util.global.load immutable @constant : tensor<4xf32>
%0 = arith.addf %arg0, %constant : tensor<4xf32>
return %0 : tensor<4xf32>
}
}
{-#
dialect_resources: {
builtin: {
constant.4xf32: "0x0800000054A3B53ED6C0B33E55D1A2BDE5D2BB3E"
}
}
#-}
```
I try to compile using
```
/iree-compile --compile-to=flow drtest.mlir
```
The output I get is
```
module {
util.global private @constant {inlining_policy = #util.inline.never} = dense_resource : tensor<4xf32>
flow.executable private @abs_dispatch_0 {
flow.executable.export public @abs_dispatch_0_elementwise_4_f32 workgroups() -> (index, index, index) {
%x, %y, %z = flow.dispatch.workgroup_count_from_slice
flow.return %x, %y, %z : index, index, index
}
builtin.module {
func.func @abs_dispatch_0_elementwise_4_f32(%arg0: !flow.dispatch.tensor>, %arg1: !flow.dispatch.tensor>, %arg2: !flow.dispatch.tensor>) {
%0 = flow.dispatch.tensor.load %arg0, offsets = [0], sizes = [4], strides = [1] : !flow.dispatch.tensor> -> tensor<4xf32>
%1 = flow.dispatch.tensor.load %arg1, offsets = [0], sizes = [4], strides = [1] : !flow.dispatch.tensor> -> tensor<4xf32>
%2 = tensor.empty() : tensor<4xf32>
%3 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%0, %1 : tensor<4xf32>, tensor<4xf32>) outs(%2 : tensor<4xf32>) {
^bb0(%in: f32, %in_0: f32, %out: f32):
%4 = arith.addf %in, %in_0 : f32
linalg.yield %4 : f32
} -> tensor<4xf32>
flow.dispatch.tensor.store %3, %arg2, offsets = [0], sizes = [4], strides = [1] : tensor<4xf32> -> !flow.dispatch.tensor>
return
}
}
}
util.func public @abs(%arg0: !hal.buffer_view) -> !hal.buffer_view attributes {iree.abi.stub, iree.reflection = {iree.abi.declaration = "sync func @abs(%input0: tensor<4xf32>) -> (%output0: tensor<4xf32>)"}} {
%constant = util.global.load immutable @constant : tensor<4xf32>
%0 = hal.tensor.import %arg0 "input0" : !hal.buffer_view -> tensor<4xf32>
%1 = flow.dispatch @abs_dispatch_0::@abs_dispatch_0_elementwise_4_f32(%0, %constant) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
%2 = hal.tensor.export %1 "output0" : tensor<4xf32> -> !hal.buffer_view
util.return %2 : !hal.buffer_view
}
```
This is missing the dialect resources.
### What component(s) does this issue relate to?
Compiler
### Version information
8fcab13973631e64b1fb0d6e7afb2efb3087a8b5
### Additional context
_No response_
Contributor guide
Research direction
Reproduce the issue with iree-compile --compile-to=flow using the IR and dialect_resources shown in the report. Trace the flow compilation path and its handling of dialect resources; done means the emitted Flow IR preserves the resource data and remains compilable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100