-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][spirv] Error when using -convert-scf-to-spirv
with message Failure to legalize unresolved materialization
#61042
Comments
@llvm/issue-subscribers-mlir |
@llvm/issue-subscribers-mlir-spirv |
-convert-scf-to-spirv
with message Failure to legalize unresolved materialization
-convert-scf-to-spirv
with message Failure to legalize unresolved materialization
Hi @sweead, Thanks for reporting the issue. The IR used the old SPIR-V dialect prefix, so I upgraded it to something that can be processed by mlir today: #map0 = affine_map<(d0, d1) -> (d0, d1)>
#map1 = affine_map<(d0, d1) -> (d0)>
module attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>} {
func.func @test_argmax(%arg0: tensor<14x19xf32>) {
%c0_i32 = arith.constant 0 : i32
%cst = arith.constant -3.40282347E+38 : f32
%0 = bufferization.to_memref %arg0 : memref<14x19xf32>
%1 = memref.alloc() {alignment = 128 : i64} : memref<14xi32>
linalg.fill ins(%c0_i32 : i32) outs(%1 : memref<14xi32>)
%2 = memref.alloc() {alignment = 128 : i64} : memref<14xf32>
linalg.fill ins(%cst : f32) outs(%2 : memref<14xf32>)
%3 = memref.alloc() {alignment = 128 : i64} : memref<14xi32>
memref.copy %1, %3 : memref<14xi32> to memref<14xi32>
%4 = memref.alloc() {alignment = 128 : i64} : memref<14xf32>
memref.copy %2, %4 : memref<14xf32> to memref<14xf32>
linalg.generic {indexing_maps = [#map0, #map1, #map1], iterator_types = ["parallel", "reduction"]} ins(%0 : memref<14x19xf32>) outs(%3, %4 : memref<14xi32>, memref<14xf32>) {
^bb0(%arg1: f32, %arg2: i32, %arg3: f32):
%5 = linalg.index 1 : index
%6 = arith.index_cast %5 : index to i32
%7 = arith.cmpf ogt, %arg1, %arg3 : f32
%8 = arith.select %7, %arg1, %arg3 : f32
%9 = arith.select %7, %6, %arg2 : i32
linalg.yield %9, %8 : i32, f32
}
return
}
} I can reproduce the error, taking a look... |
@antiagainst I think it's another example of us doing conversion on ops within a loop without checking that the surrounding loop construct is supported (currently |
We have an existing TODO in the surrounding code: // TODO: Change SPIR-V conversion to be progressive and remove the following
// patterns.
mlir::arith::populateArithToSPIRVPatterns(typeConverter, patterns);
populateFuncToSPIRVPatterns(typeConverter, patterns);
populateMemRefToSPIRVPatterns(typeConverter, patterns);
populateBuiltinFuncToSPIRVPatterns(typeConverter, patterns); I guess this would entail introducing some level of nesting in how we run these helper patterns, e.g., |
Yeah, like you noticed, SPIR-V currently expects some higher-level conversions to happen first. If this shows up in some real-world scenario you have to make sure to break down higher-level ops using other dialect conversions before running |
With the current conversion pass structure, this is working as intended -- we report a conversion error and don't crash. We have an easier spirv conversion pass pipeline in mind that should cover similar usecases. |
Hello, I ran into an error when using
mlir-opt -convert-scf-to-spirv
on the following mixed IR.To be specific, IR was successfully lowered to the
cf
dialect via-convert-scf-to-cf
.I'm not sure if this is a bug, it seems the problem is with type conversions.
IR:
error message:
The text was updated successfully, but these errors were encountered: