Skip to content

MobileBert Performance Regression on Pixel 4 CPU at 8d74bfa28dd35203fba700aa1f1d88c200c848cd #4686

Closed

Description

@hanhanW

Describe the bug
We were at 957 ms (with default pipeline) in 3d3657a and we got 2637 ms in 8d74bfa

It seems that the HAL rewrite stuff is the root cause.

To Reproduce
git checkout to 3d3657a build the module and run on an Android phone. Or download the artifacts from: https://buildkite.com/iree/iree-android-benchmark/builds/1776#5d1cacba-d4df-4f95-83a0-f985c16a35e2

You will get 957 ms result.

git checkout to 8d74bfa and do the above instructions. You will get 26xx ms result.
https://buildkite.com/iree/iree-android-benchmark/builds/1777#acf6b7e3-25d8-423e-a94f-89ca4165686b

I suspect that this is because of runtime overhead, and we probably can repro it on desktop as well.

@benvanik @ScottTodd @asaadaldien

Activity

  1. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    This is the expected regression from disabling executable linking that was fixed in 1321588. I'll get a trace from my desktop to confirm the current main is fine - if you have traces from the android devices then you can check them.

  2. ScottTodd commented on Feb 2, 2021

    @ScottTodd
    Member

    If I'm reading Mako's (sparse and confusing) UI correctly, this is the benchmark run at the commit that re-enabled linking: https://mako.dev/run?run_key=4838305951645696&~cpu=1&~vmla=1&~vlk=1 (see Hover Text: | 1321588580053ba26d75a3dc495572508cda0bc3). That still shows a performance regression.

  3. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    Ugh yeah I freaking hate that UI. VMLA and SPIR-V didn't regress, only dylib - which still makes me suspect linking-related. Still trying to confirm.

  4. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    Nope, trace looks great to me - I'm not sure I trust that graph.

    Single executable:
    image

    And the time is now only 263ms for execution thanks to threading:
    image

  5. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    And the same timing I was getting before with --dylib_worker_count=1 (single threaded):
    image

  6. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    Would need a new trace captured at main from an Android device to say anything more concrete, but I suspect benchmarking issues/age.

  7. hanhanW commented on Feb 2, 2021

    @hanhanW
    ContributorAuthor

    The pictures look really awesome! I will try to get them from an Android device. (I haven't tried tracy on Android yet) Which tool did you use to run the model? Was it iree-run-module or iree-benchmark-module or other tool?

    I'm curious that what are outside EvaluateFunctions? Is it an end-to-end run, or there are other things?
    We benchmarked the model with iree-benchmark-module tool, and the numbers were come from the report. Do we want to exclude something from the measurement?

    https://github.com/google/iree/blob/3679141eb4e0cc0db4cc21239ef23df293126b6f/iree/tools/iree-benchmark-module-main.cc#L60-L79

  8. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    This was iree-run-mlir - because I'm lazy and when switching branches/etc it's much easier to not have to recompile models/etc and just have one command to run - but otherwise it's the same as iree-translate + iree-run-module :)

    The numbers I quoted were the ones that actually matter (total execution time), vs init/shutdown. Total end to end (on my machine) is ~440ms with threading and no significant change from prior to the rewrite (it's still decompressing the dylib and allocating a thousand buffers/etc).
    image

    iree-benchmark-module is measuring this end to end time of a single invocation, which excludes the __init and shutdown so just this highlighted region of 380ms:
    image

    Which is basically buffer allocation, command buffer recording, actual command buffer execution time, and cleanup. The only thing the hal rewrite (which included multithreading) changes is that it reduces the overhead of per-command recording and makes the command buffer execution time much lower due to threading - the same number of buffers are allocated, same number number of commands are recorded, etc.

    So if you see a time increase on Android (at main, after the linking fix went in) it's likely just something tunable (like, we are only using one thread because the thread selection logic is TODO, or we are using 32 threads on a 4 core machine and oversubscribing, etc etc). Traces are the best way to see what's happening.

  9. benvanik commented on Feb 2, 2021

    @benvanik
    Collaborator

    (my goal, once I can flush this tflite stuff from my queue, is to take the buffer allocation/free time to 0, and then future changes will cache the command buffer recording such that each invocation is pure command buffer execution time - until then, treat everything besides the actual command buffer execution as a fixed cost that will go to ~zero!)

  10. asaadaldien commented on Feb 3, 2021

    @asaadaldien
    Contributor

    So if you see a time increase on Android (at main, after the linking fix went in) it's likely just something tunable (like, we are only using one thread because the thread selection logic is TODO, or we are using 32 threads on a 4 core machine and oversubscribing, etc etc). Traces are the best way to see what's happening.

    Is the multithreaded HAL on by default now ?

  11. benvanik commented on Feb 3, 2021

    @benvanik
    Collaborator

    Yep! It's untuned in many ways (like, a lot of ways), but if there are things that get dispatched with multiple workgroups they should parallelize. I'm waiting to do a big tuning push until we have more workloads to test with that are properly distributed - and I think tuning distribution is a good next step after the initial linalg-on-tensors port is in. We can do another little mini burndown :)

  12. asaadaldien commented on Feb 3, 2021

    @asaadaldien
    Contributor

    Thanks @hanhanW for tracking this. As @benvanik mentioned the best way to capture two traces and 1:1 compare them. We can also start by looking at traces executing single op (e.g matmul) and see if there is a significant increase at vm_iree_invoke and slice it

  13. asaadaldien commented on Feb 3, 2021

    @asaadaldien
    Contributor

    Yep! It's untuned in many ways (like, a lot of ways), but if there are things that get dispatched with multiple workgroups they should parallelize. I'm waiting to do a big tuning push until we have more workloads to test with that are properly distributed - and I think tuning distribution is a good next step after the initial linalg-on-tensors port is in. We can do another little mini burndown :)

    I think that might be the regression then =). On ARM with little cores, different cache behaviors..eg its easy to go down 2.7x doing by parallelization without tuning.
    To have a fair comparison we need to still execute the benchmarks on single thread (Core - 7).

  14. benvanik commented on Feb 3, 2021

    @benvanik
    Collaborator

    (also, there's zero ambiguity with a trace - in general for things like this we should trace first and then analyze)

  15. hanhanW commented on Feb 5, 2021

    @hanhanW
    ContributorAuthor

    I got some trace here. I complied the module and run

    adb shell TRACY_NO_EXIT=1 /data/local/tmp/iree-run-module \
      --module_file=/data/local/tmp/a.vmfb \
      --driver=dylib \
      --function_inputs=1x384xi32=0,1x384xi32=0,1x384xi32=0 \
      --entry_function=serving_default
    

    With taskset 80

    Multi-thread (2.53 sec)

    image

    Single-thread (880 ms)

    image

    Without taskset 80

    Multi-thread (2.48 sec)

    image

    Single-thread (1.12 sec)

    image

  16. hanhanW commented on Feb 5, 2021

    @hanhanW
    ContributorAuthor

    It looks like we don't have regression, the old config is still 880 ms (which is single thread with + taskset 80).

  17. hanhanW commented on Feb 5, 2021

    @hanhanW
    ContributorAuthor

    @asaadaldien @benvanik Do you want me to make it benchmark on single thread + taskset 80? It is run on multi thread by default after merging 8d74bfa.

  18. self-assigned this
    on Feb 5, 2021
  19. added
    performance ⚡
    and removed on Feb 5, 2021
  20. benvanik commented on Feb 5, 2021

    @benvanik
    Collaborator

    Yep yep - #4654 is tracking doing better thread count/affinity selection (right now it's literally 🤷 :) which should help this.

    Having both benchmarks would be useful - as we start to tune workgroup distribution we need to be able to see what the timings are. Single threaded is useful for benchmarking the insides of single kernel invocations in isolation and multi-threaded is useful for benchmarking the interaction between invocations of kernels.

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

Metadata

Metadata

Assignees

Labels

performance ⚡

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions