Skip to content

GPU kernels get stopped after 2 seconds on Pixel 4 when in batch mode benchmarking #5052

Closed

Description

@hanhanW

Describe the bug
I tried to run batch mode benchmarking on MobileNetV2. With tracy, I know that it actually takes ~60ms to finish one inference on Pixel 4 on GPU. If I benchmark the model with size=32, it reports ~60 ms. However, I found something weird when setting the size larger. I found that a launch of GPU kernel always gets stopped after 2 seconds on Pixel 4. The launch will always end at 2 seconds if I set the size >= 64.

This only happens on Pixel 4 (or andoird). For desktop, it can take more than 2 seconds to finish the work.

image

For CPU, it can also takes more than 2 seconds to finish the work.
image

To Reproduce

$ build-tracy/iree/tools/iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv ~/mobilenet_v2.mlir -o a.vmfb --iree-hal-benchmark-dispatch-repeat-count=5
$ adb push a.vmfb /data/local/tmp
$ adb shell LD_LIBRARY_PATH=/data/local/tmp/ taskset 80 /data/local/tmp/iree-benchmark-module \
  --flagfile=/data/local/tmp/mobilenet_v2_flagfile \
  --module_file=/data/local/tmp/a.vmfb \
  --driver=vulkan \
  --batch_size=5

It can be reproduced by any models. I simplified the command to default config and verified that it can be repro with above instructions. By default it runs in ~1 sec. Making it 5 still make the program end in 2 seconds.

Activity

  1. added
    platform/android 🤖
    hal/vulkan
    on Mar 10, 2021
  2. antiagainst commented on Mar 10, 2021

    @antiagainst
    Member

    Interesting. Probably due to some emulated timeline semaphore weirdness. We don't have native timeline semaphore support on Pixel4 so enumerated timeline semaphore is chosen there.

  3. changed the title [-]GPU kernels get stopped after 2 seconds on Pixel 4[/-] [+]GPU kernels get stopped after 2 seconds on Pixel 4 when in batch mode benchmarking[/+] on Mar 10, 2021
  4. ScottTodd commented on Mar 10, 2021

    @ScottTodd
    Member

    You could use emulated timeline semaphores on non-Android to investigate that theory.

    My first thought was some other Vulkan ICD timeout. If a particular dispatch takes too long, we may need to split it up into several dispatches.

  5. antiagainst commented on Mar 10, 2021

    @antiagainst
    Member

    +1 to what @ScottTodd said. You can force timeline semaphore on by --vulkan_force_timeline_semaphore_emulation.

  6. hanhanW commented on Mar 10, 2021

    @hanhanW
    ContributorAuthor

    I tried it on desktop. Looks like it is not the issue of emulated timeline semaphores. It takes 4 seconds to finish the work.

    image

  7. ThomasRaoux commented on Mar 10, 2021

    @ThomasRaoux
    Contributor

    Are you getting a VK_ERROR_DEVICE_LOST return if trying to call vulkan after the 2s? OS usually has a watchdog that will reset the device if it thinks the GPU is hung.

  8. benvanik commented on Mar 10, 2021

    @benvanik
    Collaborator

    Is the issue just that the work is finishing faster than you expect? you aren't inserting barriers between the dispatches (which is fine), which means all will run concurrently, and you may just be completing it fast :)

    Try running on CPU with more than 1 thread enabled and you should see the same - 2 threads should run 2x faster, etc.

  9. hanhanW commented on Mar 10, 2021

    @hanhanW
    ContributorAuthor

    I get this error if I run with --benchmark_repetitions=2

    F ../iree/hal/vulkan/emulated_semaphore.cc:140] Check failed: outstanding_semaphores_.empty() Destroying an emulated timeline semaphore without first waiting on outstanding signals
    Aborted
    
  10. hanhanW commented on Mar 10, 2021

    @hanhanW
    ContributorAuthor

    Is the issue just that the work is finishing faster than you expect? you aren't inserting barriers between the dispatches (which is fine), which means all will run concurrently, and you may just be completing it fast :)

    Try running on CPU with more than 1 thread enabled and you should see the same - 2 threads should run 2x faster, etc.

    No, I think the issue is not the work is finishing faster than I expect. It should converge to a number when batch_size gets larger. But it always stops after 2 seconds.

  11. benvanik commented on Mar 10, 2021

    @benvanik
    Collaborator

    so to clarify cause there's a lot going on in here: this reproduces on desktop with native semaphores? if so, do the vulkan debug layers print out anything?

  12. hanhanW commented on Mar 10, 2021

    @hanhanW
    ContributorAuthor

    No. So far I can only repro it on Pixel 4.

  13. hanhanW commented on Mar 11, 2021

    @hanhanW
    ContributorAuthor

    This looks like a Pixel 4 specific issue. Maybe it only happens on my Pixel 4...

    Below is the result from S10, which looks good to me.
    image

  14. nihui commented on Mar 11, 2021

    @nihui

    hi, I think it is the adreno driver that stops too long tasks. There may be an internal watchdog inside the driver.
    For practical uses, do not encode very large command, split into several small commands as a workaround.

  15. antiagainst commented on Mar 11, 2021

    @antiagainst
    Member

    Thanks @nihui for the insights! Now we know 2s is the kill threshold for Pixel 4 or Qualcomm SoC. :) Yes, this is just duplicating dispatches in a command buffer for benchmarking purposes, so that we can hide overhead. It is not meant for production usage.

  16. hanhanW commented on Mar 11, 2021

    @hanhanW
    ContributorAuthor

    Thanks, I will keep this in mind when setting benchmarking configurations!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    hal/vulkanplatform/android 🤖

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions