Skip to content

Ignoring subspan byte offset when converting to SPIR-V causes segfault on SwiftShader #5372

Closed

Description

@hanhanW

I found that we can not run the module on SwiftShader, and this only happens in Linalg on tensors. Will attach more information later.

Activity

  1. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor

    Verified that the root cause is #5328

    I checkout to d3eb8e4, and it worked.
    I checkout to 56307e1, and it crashed.

    To repro:

    Set up SwiftShader env:

    git clone https://swiftshader.googlesource.com/SwiftShader
    cd SwiftShader/build
    cmake ..
    cmake --build . --parallel
    export VK_ICD_FILENAMES=/path/to/SwiftShader/Linux/vk_swiftshader_icd.json 
    

    Compile to IREE module: iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv ~/input.mlir -o a.vmfb -iree-flow-dispatch-linalg-on-tensors=true -iree-codegen-spirv-experimental-linalg-on-tensors=true

    Run iree-run-module --module_file=a.vmfb --driver=vulkan --entry_function=call --function_inputs=1x16000xf32=0

    The input.mlir is at https://gist.githubusercontent.com/hanhanW/dafdd5ae914f866e592e124428467aed/raw/1d751b55e550b9b2d8a18a8533ff813440fec2f9/keyword_spotting_tests_fake-mobilenet-v2.mlir

    (coming from #5313, and found that we can repro it with the same MLIR file)

    cc @MaheshRavishankar

  2. added
    hal/vulkan
    on Apr 9, 2021
  3. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    I don't have swiftshader built - can you provide more information about the crash? (backtrace, etc)
    Knowing whether the crash is in a Vulkan API call or whether it is in the execution of the SPIR-V will help narrow down where the error is. If the only issue is with Vulkan then I suspect SPIR-V codegen.

  4. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    Also, any logs from the validation layers?

  5. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor

    I actually can only see zsh: abort build-tracy/iree/tools/iree-run-module --module_file=a.vmfb --driver=vulkan so I did not attach it.

    But now I found something interesting in stderr: https://gist.githubusercontent.com/hanhanW/07fe9063a98b7d649f700649f641e608/raw/68ef06db0359839b7dc55783865c903024028494/gistfile1.txt

    This looks new to me?

    E ../iree/hal/vulkan/debug_reporter.cc:42] Validation Error: [ VUID-VkPipelineLayoutCreateInfo-descriptorType-03024 ] Object 0: handle = 0xe09228, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xeb2bfadc | vkCreatePipelineLayout(): max per-stage storage buffer bindings count (3) exceeds device maxPerStageDescriptorUpdateAfterBindStorageBuffers limit (0). The Vulkan spec states: The total number of descriptors with a descriptorType of VK_DESCRIPTOR_TYPE_STORAGE_BUFFER and VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC accessible to any given shader stage across all elements of pSetLayouts must be less than or equal to VkPhysicalDeviceDescriptorIndexingProperties::maxPerStageDescriptorUpdateAfterBindStorageBuffers (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkPipelineLayoutCreateInfo-descriptorType-03024)
    

    What env should I set to get more information?

  6. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor

    I'm not sure if this is useful. Some log from dmesg.

    [4445975.081730] sbverify[3313181]: segfault at 7fa2f2fba7c4 ip 0000564a86ebfd40 sp 00007ffc655c20a0 error 4 in sbverify[564a86ebe000+8
    000]                                                                                                                                   [4445975.081740] Code: 48 8d 50 78 49 89 57 40 48 8d 50 58 49 89 57 18 e9 8e fa ff ff 0f 1f 44 00 00 8b 72 20 4c 01 f6 49 89 77 60 0f 8
    4 cf fa ff ff <66> 81 7e 04 00 02 0f 85 c3 fa ff ff 66 83 7e 06 02 0f 85 b8 fa ff
    [4480766.935169] Thread<00>[3484787]: segfault at 158330e7e3c0 ip 00007fde9c442337 sp 00007fdea4c74488 error 4 in memfd:swiftshader_jit
     (deleted)[7fde9c442000+1000]
    [4480766.935178] Code: d8 c5 e1 72 f3 02 c4 e1 f8 90 d1 62 f2 7d 0a 92 24 18 49 8b 44 24 10 c4 c2 51 40 dd c5 e1 fe d8 c5 e1 72 f3 02 c
    4 e1 f8 90 d1 <62> f2 7d 0a 92 2c 18 c5 d0 59 dc c4 c2 41 40 e3 c5 d9 fe c0 c5 f1
    [4480829.640970] Thread<02>[3488952]: segfault at 1784f0e7e4c0 ip 00007f691a71e337 sp 00007f6921f4d488 error 4 in memfd:swiftshader_jit
     (deleted)[7f691a71e000+1000]
    [4480829.640981] Code: d8 c5 e1 72 f3 02 c4 e1 f8 90 d1 62 f2 7d 0a 92 24 18 49 8b 44 24 10 c4 c2 51 40 dd c5 e1 fe d8 c5 e1 72 f3 02 c
    4 e1 f8 90 d1 <62> f2 7d 0a 92 2c 18 c5 d0 59 dc c4 c2 41 40 e3 c5 d9 fe c0 c5 f1
    [4480829.641057] Thread<00>[3488950]: segfault at 1784f0e7e3c0 ip 00007f691a71e337 sp 00007f6922f50488 error 4
    [4480829.641060] Thread<03>[3488953]: segfault at 1784f0e7e540 ip 00007f691a71e337 sp 00007f6921749488 error 4
    [4480829.641062]  in memfd:swiftshader_jit (deleted)[7f691a71e000+1000]
    [4480829.641063]  in memfd:swiftshader_jit (deleted)[7f691a71e000+1000]
    [4480829.641068] Code: d8 c5 e1 72 f3 02 c4 e1 f8 90 d1 62 f2 7d 0a 92 24 18 49 8b 44 24 10 c4 c2 51 40 dd c5 e1 fe d8 c5 e1 72 f3 02 c
    4 e1 f8 90 d1 <62> f2 7d 0a 92 2c 18 c5 d0 59 dc c4 c2 41 40 e3 c5 d9 fe c0 c5 f1
    [4480829.641070] Code: d8 c5 e1 72 f3 02 c4 e1 f8 90 d1 62 f2 7d 0a 92 24 18 49 8b 44 24 10 c4 c2 51 40 dd c5 e1 fe d8 c5 e1 72 f3 02 c
    4 e1 f8 90 d1 <62> f2 7d 0a 92 2c 18 c5 d0 59 dc c4 c2 41 40 e3 c5 d9 fe c0 c5 f1
    [4480951.699175] Thread<00>[3498991]: segfault at 569330e7e3c0 ip 00007fd7aa92d337 sp 00007fd7b315f488 error 4
    [4480951.699183] Thread<12>[3499003]: segfault at 569330e7e1c0 ip 00007fd7aa92d337 sp 00007fd7ad13d488 error 4
    [4480951.699185]  in memfd:swiftshader_jit (deleted)[7fd7aa92d000+1000]
    
  7. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    Hmm that may be an indicator - it's weird it lists maxPerStageDescriptorUpdateAfterBindStorageBuffers as we aren't using that feature. It's possible this is a bug in swiftshader or the validation layers. 3 bindings should be fine as maxPerStageDescriptorStorageBuffers == 16.

    That maxPerStageDescriptorUpdateAfterBindStorageBuffers property comes in Vulkan 1.2, which swiftshader only half supports. It's possible that our hack here is triggering, assuming you aren't running this on android:
    https://github.com/google/iree/blob/99c8eaca7ffc4a776dd4d0a0f5d82ab5c12d5376/iree/hal/vulkan/registration/driver_module.cc#L52-L59

    Try always forcing it to 1.1 (the ANDROID path)?

    The final error is suspicious as well - have you ever seen that anywhere else? I know we have some error like it, but that one looks worse than normal.

  8. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    [4480951.699175] Thread<00>[3498991]: segfault at 569330e7e3c0 ip 00007fd7aa92d337 sp 00007fd7b315f488 error 4
    [4480951.699183] Thread<12>[3499003]: segfault at 569330e7e1c0 ip 00007fd7aa92d337 sp 00007fd7ad13d488 error 4
    [4480951.699185] in memfd:swiftshader_jit (deleted)[7fd7aa92d000+1000]

    ah yeah, so this is in their JIT'ed SPIRV - so either it's our generated SPIRV that is bad (accessing bad memory) or the above binding weirdness is feeding bad memory into the JIT. I wouldn't expect those warnings to start appearing with the linked PR - it doesn't change anything but some binding indices - there's no runtime or buffer allocation changes. Do you get those warnings before the PR? (I don't see anything similar with my local latest Vulkan SDK)

  9. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor

    Let me checkout to previous one, rebuild, and circle back to you

  10. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    I'll do an IR dump and see if I spot anything weird.

  11. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor
  12. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    Good thinking! Swiftshader can maybe be run with ASAN as well (I did it way back in the day but forget what it entailed - maybe @ScottTodd remembers?)

  13. 7 remaining items

  14. hanhanW commented on Apr 9, 2021

    @hanhanW
    ContributorAuthor

    @antiagainst could you take a look at binding stuff?

  15. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    There is a bug! it will always return unavailable. ;-)

    🤦 I'll fix that :P

  16. antiagainst commented on Apr 9, 2021

    @antiagainst
    Member

    It looks like this may be spir-v codegen ignoring the binding offset and creating multiple aliased bindings instead.

    Ah, yes. Thanks @hanhanW and @benvanik for pinpointing the issue! I'll take a look and fix.

  17. self-assigned this
    on Apr 9, 2021
  18. benvanik commented on Apr 9, 2021

    @benvanik
    Collaborator

    We could probably try turning off this pass (or adding a flag for it) for the spirv case until it's fixed, though then other models are likely to fail with too many bindings errors as they were before. Will let y'all decide the best path there :)

  19. MaheshRavishankar commented on Apr 9, 2021

    @MaheshRavishankar
    Collaborator

    Lets fix the bug on the SPIR-V path. It shouldnt be too much of a lift here. We will need this to switch to linalg on tensors.

  20. changed the title [-]Segmentation fault when running MobileNet V2 on SwiftShader[/-] [+]Ignoring subspan byte offset when converting to SPIR-V causes segfault on SwiftShader[/+] on Apr 12, 2021
  21. added
    codegen/spirv
    on Apr 14, 2021
  22. antiagainst commented on Apr 14, 2021

    @antiagainst
    Member

    Fixed via #5403.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

codegen/spirvhal/vulkan

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions