Repository navigation
Description
What happened?
I'm trying to compile mobilebertsquad.tflite.mlir from our benchmark suites for WebGPU and see this error:
error: entry point 'd0' references multiple variables that use the same resource binding @group(0), @binding(1)
Here are the relevant .mlir and .spvasm files: https://gist.github.com/ScottTodd/6af59563826719340f659dd0554edd40
Steps to reproduce your issue
- Download
mobilebertsquad.tflite.mlirfrom our benchmark infra. I downloaded files from Oct 28, so maybe around https://buildkite.com/iree/iree-benchmark-android/builds/4621 - Run
iree-compile mobilebertsquad.tflite.mlir --iree-hal-target-backends=webgpu --iree-input-type=tosa - Observe the error
What component(s) does this issue relate to?
Compiler
Version information
webgpu branch, 4116d5a
Additional context
I was able to compile this using an older version of IREE's compiler, so this might be a regression? With the version that I compiled, I saw this runtime error: Tint WGSL reader failure: :44:211 error: value cannot be represented as 'f32' x__resource_var_0_1_.field0[(x_83 + select(x_131, (4294967295u - x_131), x_128))] = select(select(select(select(select(vec4<f32>(1.17549435e-38f, 1.17549435e-38f, 1.17549435e-38f, 1.17549435e-38f), vec4<f32>(0x1p+128f, 0x1p+128f, 0x1p+128f, 0x1p+128f), (x_99 > vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f))), (fma(fma(vec4<f32>(0.0131435f, 0.0131435f, 0.0131435f, 0.0131435f), x_104, vec4<f32>(0.03668965f, 0.03668965f, 0.03668965f, 0.03668965f)), (x_105 * x_105), fma(fma(vec4<f32>(0.168738902f, 0.168738902f, 0.168738902f, 0.168738902f), x_104, vec4<f32>(0.499705136f, 0.499705136f, 0.499705136f, 0.499705136f)), x_105, fma(vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f), x_104, vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f)))) * bitcast<vec4<f32>>(((x_112 + vec4<u32>(127u, 127u, 127u, 127u)) << vec4<u32>(23u, 23u, 23u, 23u)))), ((bitcast<vec4<i32>>(x_112) <= bitcast<vec4<i32>>(vec4<u32>(127u, 127u, 127u, 127u))) & (bitcast<vec4<i32>>(x_112) >= bitcast<vec4<i32>>(vec4<u32>(4294967169u, 4294967169u, 4294967169u, 4294967169u))))), vec4<f32>(0x1p+128f, 0x1p+128f, 0x1p+128f, 0x1p+128f), (x_99 == vec4<f32>(0x1p+128f, 0x1p+128f, 0x1p+128f, 0x1p+128f))), vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f), (x_99 == vec4<f32>(-0x1p+128f, -0x1p+128f, -0x1p+128f, -0x1p+128f))), x_99, vec4<bool>(false, false, false, false));
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
benvanik commentedon Nov 4, 2022
This may be the pass @antiagainst enabled on all but apple the other day? (may need to add a
&& !webgpu)antiagainst commentedon Nov 4, 2022
Ha, okay, this is hitting the same aliased resources issue that we have been fighting when targeting Apple platforms via MoltenVK.
SPIR-V spec allows multiple resources bound to the same (set, binding) slot; real GPU drivers are all fine with that AFAICT. However SPIRV-Cross does not support aliased resources too. So I wrote a
UnifyAliasedResourcePass(code and test) to try to do various type casting and re-indexing to eliminate those aliased resources. However as recently I found there is a correctness issue with that pass so I limited it to only Apple platforms for now. I will spend some time later to figure that out and fix it so we can reuse here.Better, it would be nice if Tint can support such cases. @dneto0 as FYI.
dneto0 commentedon Nov 14, 2022
WGSL does not allow aliasing (group,binding). https://gpuweb.github.io/gpuweb/wgsl/#resource-interface
It does allow the same subresource (buffer or texture layer) to be bound to different (group,binding) points. But it's a "dynamic error" if at least one of them is writable. There's no way to synchronize those within the same shader, not even in Vulkan. (You would need a "domain" operation but that only occurs with API-side actions, and there is no way to invoke one inside the shader).
Cherry-pick llvm/llvm-project@e672f512 & llvm/llvm-project@234d2e27 (#…
antiagainst commentedon Nov 28, 2022
#11302 enables the UnifyAliasedResource pass for WebGPU so various model should compile now I believe. As said in the previous comment that there is a bug in the pass that I still need to figure out. Though that should only affect non-32 bit cases I believe; as 32-bit float cases are already used by various models running on Vulkan via MoltenVK.
ScottTodd commentedon Nov 28, 2022
Confirmed, this fixes compiling
mobilebertsquad.tflite.mlir🎉(there is still an issue with push constant emulation and Uniform storage, but this aliasing issue is fixed)
Fix WebGPU failure and disable newly failing test due to iree-org#11054
Fix WebGPU failure and disable newly failing test due to iree-org#11054
ScottTodd commentedon Aug 8, 2023
This might have regressed at some point. With this test program: https://github.com/openxla/iree/blob/4efb89474821cbce40e40e5b5502d027a91688ec/experimental/web/sample_webgpu/multiple_results.mlir#L1-L8
I see these errors at 1a0b3fd:
I've been wanting to add more test cases for various program structures (multiple inputs, multiple outputs, control flow, etc.)... wish I did that before this regressed 🙃
ScottTodd commentedon Aug 10, 2023
From running a bisect, it looks like that test program regressed with 3459833 (#13711). I'll dig in further... maybe the workaround for this issue doesn't apply for small/scalar computations after that change.
Work around scalar support bug in webgpu compilation. (#14629)
Work around scalar support bug in webgpu compilation. (iree-org#14629)