Skip to content

Some WebGPU storage classes are mismatched/invalid #10145

Closed

Description

@ScottTodd

Simple e2e repro, and I'm also adding a lit test hitting this in #10134:

iree-compile tests/e2e/xla_ops/reduce.mlir -o /dev/null --iree-input-type=mhlo --iree-hal-target-backends=webgpu
...
Tint reported 1 error(s) for a SPIR-V program, see diagnostics:
error: cannot initialize let of type 'ptr<storage, u32, read>' with value of type 'ptr<storage, u32, read_write>'

Here's the --mlir-print-ir-after-all and spirv asm (--iree-hal-dump-executable-intermediates-to) for the lit test:
https://gist.github.com/ScottTodd/7ee5c5086f0281ee79d3cfb3490223bf
Compared to a successful compile of a different smoketest:
https://gist.github.com/ScottTodd/1053548cd938b396bd99c3dcd2e05440

One idea was to restore the "memory access" attributes to our interface bindings across flow->stream->hal (see #7734). Looking at the sort of IR that triggers this, I'm also skeptical of the map-memref-spirv-storage-class pass and how that ends up being used via SPIR-V -> WGSL. Is this unique to codegen, or an issue in flow/stream/hal?

Activity

  1. added
    bug 🐞
    codegen/spirv
    platform/web 🌐
    on Aug 19, 2022
  2. self-assigned this
    on Aug 19, 2022
  3. ScottTodd commented on Aug 22, 2022

    @ScottTodd
    MemberAuthor

    I'm trying to narrow down where the working and broken programs are differing, and I think it's in implicit / inferred storage classes, since what's explicitly included in the .spvasm files seems pretty similar. Tint has some code like DefaultAccessForStorageClass(), and I imagine there is some analysis of reads and writes that is being ran if we aren't explicit (but I haven't traced through the code to see where that's all happening).

    Should we be passing through the NonWritable / NonReadable decorations?
    https://registry.khronos.org/SPIR-V/specs/1.0/SPIRV.html#_a_id_decoration_a_decoration

    I could go through and add back the memory access attributes across IREE's dialects, but I first want to pin down how our generated spirv should change (then work backwards from that through the dialects).

  4. benvanik commented on Aug 22, 2022

    @benvanik
    Collaborator

    +1 to digging in, and those decorations would be nice. We'll need access info anyway for the host side as we need to define the access type on the binding: https://www.w3.org/TR/webgpu/#enumdef-gpubufferbindingtype needs read-only-storage or storage and it's used for making implementations aware of data hazards.

  5. antiagainst commented on Aug 22, 2022

    @antiagainst
    Member

    Yeah the above error seems to indicate there are deduction logic inside Tint that should be improved. Those NonWritable/NonReadable is not required for SPIR-V to be valid. Though we can certainly add them using a pass if it helps address the issue; that's not very hard. SPIR-V has this goal of trying to do analysis offline and "attach" the results to avoid driver compilers spending cycles doing that, this actually matches that. (Though driver compilers may not necessary believe in what's coming from the original SPIR-V, so yeah, hard to see the exact effect..)

  6. ScottTodd commented on Aug 22, 2022

    @ScottTodd
    MemberAuthor

    I see some similar looking issues filed on Tint: https://bugs.chromium.org/p/tint/issues/list?q=storage&can=2

    I can try manually adding decorations to the .spvasm that I've been testing with to see if Tint prefers that (thankfully we can hack at IR and dumped files and run passes / tools in isolation - we don't need to jump straight to writing compiler code to test these theories).

  7. dneto0 commented on Aug 23, 2022

    @dneto0

    Looking quickly at the SPIR-V assembly, this looks like a Tint bug. The wrong type is being deduced for the pointer for that let

  8. dneto0 commented on Aug 23, 2022

    @dneto0
  9. ScottTodd commented on Aug 23, 2022

    @ScottTodd
    MemberAuthor

    Ah, nice find, and thanks for looking :)

    Can I work around this somehow? I'm fine with making edits to Tint's source for hacking, mostly looking to flush out what else might be blocking us.

  10. moved this to Done in IREEon Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐞codegen/spirvplatform/web 🌐

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions