Skip to content

GPU benchmarks do not reflect the real performance. #5248

Closed

Description

@hanhanW

We are using batch mode (which was introduced in #5012) to benchmark MobileBert and MobileNetV2. This can help us to amortize overhead. However, the numbers are much smaller in many cases, especially when increasing the batch size. We think that this is because of missing barriers. Instead of duplicating hal.command_buffer.dispatch ops, we should probably submit the command buffer multiple times. If this works, it will address the issue (see #5052) of enabling batch mode on Pixel 4.

The below snippet is from @antiagainst

I think it's likely because we duplicate dispatches without inserting any barriers. That essentially means increasing the number of warps for each dispatch to help filling the GPU. After dividing by the repeat count, we are getting a better number than it should be. There are certain dispatches in both models that are just working on small scale problem size; increasing warp count hides and "improves" the latency for them. Instead of duplicating dispatches, I think we want to submit the command buffer multiple times and average at that level. It will help to keep the original dispatch structure intact.

Activity

  1. added
    compiler/dialects
    performance ⚡
    on Mar 30, 2021
  2. self-assigned this
    on Mar 30, 2021
  3. hanhanW commented on Mar 30, 2021

    @hanhanW
    ContributorAuthor

    This also blocks adding mobile-bert f16 version to Mako benchmark, see #5204

    One sample run with batch_size=16 for MobilBert f16.

    -------------------------------------------------------------------------------------------
    Benchmark                                                 Time             CPU   Iterations
    -------------------------------------------------------------------------------------------
    BM_serving_default/process_time/real_time               157 ms         37.7 ms           16
    BM_serving_default/process_time/real_time              90.3 ms         29.8 ms           16
    BM_serving_default/process_time/real_time              91.3 ms         31.5 ms           16
    BM_serving_default/process_time/real_time              87.7 ms         27.8 ms           16
    BM_serving_default/process_time/real_time              89.5 ms         27.6 ms           16
    BM_serving_default/process_time/real_time              88.8 ms         28.5 ms           16
    BM_serving_default/process_time/real_time              90.1 ms         29.6 ms           16
    BM_serving_default/process_time/real_time              90.2 ms         29.8 ms           16
    BM_serving_default/process_time/real_time              90.4 ms         29.9 ms           16
    BM_serving_default/process_time/real_time               150 ms         30.9 ms           16
    BM_serving_default/process_time/real_time              89.9 ms         29.6 ms           16
    BM_serving_default/process_time/real_time              89.9 ms         29.6 ms           16
    BM_serving_default/process_time/real_time              89.7 ms         29.9 ms           16
    BM_serving_default/process_time/real_time               150 ms         31.5 ms           16
    BM_serving_default/process_time/real_time              89.5 ms         29.5 ms           16
    BM_serving_default/process_time/real_time              91.1 ms         30.9 ms           16
    BM_serving_default/process_time/real_time               148 ms         29.0 ms           16
    BM_serving_default/process_time/real_time              86.7 ms         26.6 ms           16
    BM_serving_default/process_time/real_time              86.5 ms         26.2 ms           16
    BM_serving_default/process_time/real_time              87.5 ms         27.2 ms           16
    BM_serving_default/process_time/real_time_mean          102 ms         29.7 ms           20
    BM_serving_default/process_time/real_time_median       90.0 ms         29.6 ms           20
    BM_serving_default/process_time/real_time_stddev       25.6 ms         2.44 ms           20
    
  4. antiagainst commented on Mar 30, 2021

    @antiagainst
    Member

    To submit the command buffer multiple times, I think we just need to drop the OneShot when creating the command buffer, and extend hal.ex.submit_and_wait to take multiple command buffers. Seems quite straightforward. @benvanik please correct me if I missed something. :D

  5. benvanik commented on Mar 30, 2021

    @benvanik
    Collaborator

    I believe only one-shot command buffers are supported right now, though I've been meaning to support reusable ones. It requires some work on the CPU side to make work.

    I'm doing some other cleanup on the HAL and can work on removing the submit_and_wait and replacing it with proper submission, in which case you'd be able to submit multiple command buffers (the same multiple times, or multiple ones that were recorded). I'll file an issue!

  6. benvanik commented on Mar 30, 2021

    @benvanik
    Collaborator

    filed: #5249 #5250

  7. benvanik commented on Mar 30, 2021

    @benvanik
    Collaborator

    (oh to clarify on those issues - I wanted to track them but I consider those/this issue lower priority than getting tracy support for vulkan working - I've always warned that this approach to measuring individual dispatches as being deceptive and brittle, and for pure interactive profiling the tracy approach will work better)

  8. benvanik commented on Mar 31, 2021

    @benvanik
    Collaborator

    Update as I integrate tracy timestamps: tracy will only work with oneshot command buffers (as it must record timestamps unique per submission) - since tracing is most interesting for performance work it would not be great to require reusable command buffers for the benchmarks :)

    Re-recording the command buffer would be a workaround. If the pass for benchmarking found all flow streams and put them in an scf.for that would (probably, when all of that's implemented) work.

    Or we just create some benchmarks by hand and leave the automation of per-dispatch microbenchmarks out (my vote :)

  9. benvanik commented on Mar 31, 2021

    @benvanik
    Collaborator

    update to the update: I think with some trickery tracy could work with reusable command buffers - it'd be a bigger implementation though and I won't be able to do it in the first go (of the same style of complexity as the timeline semaphore emulation).

  10. antiagainst commented on Mar 31, 2021

    @antiagainst
    Member

    (oh to clarify on those issues - I wanted to track them but I consider those/this issue lower priority than getting tracy support for vulkan working - I've always warned that this approach to measuring individual dispatches as being deceptive and brittle, and for pure interactive profiling the tracy approach will work better)

    Point taken. IMO, there are two different use scenarios:

    1. Having an overall number to show where we are regarding GPU performance on certain models. This is primarily for per-commit automated benchmarking and status tracking. There should be no manual work involved.
    2. Looking at the details of all the dispatches in a model and figure out what's the performance bottleneck and why some regression reported by 1. There are manual work involved for sure because we need somebody staring at the charts/figures. :)

    I see Tracy provides a great solution to 2. This issue is mostly for 1. Both are great to have. :)

  11. antiagainst commented on Sep 3, 2021

    @antiagainst
    Member

    With #5919 and batching we have a temporary solution reflecting the kernel execution time for existing models. So closing this for now.

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

Metadata

Metadata

Assignees

Labels

compiler/dialectsperformance ⚡

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions