Skip to content

Consider removing GPUCommandBuffer.executionTime #2156

Closed

Description

@Kangz

When we initially discussed timestamp queries for WebGPU there was some concern that they were not implementable on all Metal devices, in particular iOS devices. On these devices the only way to time the execution of commands is MTLCommandBuffer:: gpuStartTime and gpuEndTime. That's why we added GPUCommandBuffer.executionTime to the specification.

Two issues change the basis for this decision a bit.

In #2046 the timestamp queries are changed such that they are implementable on a wider range of Metal devices. In particular @litherum noted that they work on semi-recent Apple GPUs, including iPhone ones, meaning that iOS now will at least sometimes get timestamp query support:

(Above, when I say "Apple Silicon devices", I'm referring to devices which support querying - I tested and verified iPhone 11, iPhone 12, and M1.)

In #1773 @toji raised the issue that some devices (at least Vulkan and maybe also some D3D12 ones) don't expose the functionality required to produce sensible values for GPUCommandBuffer.executionTime. It was meant to be the always-available option, but turns out that it isn't always available.

Given that timestamp-query will be supported on an extended range of devices and that executionTime can't be supported on all device, I don't think we need executionTime as the "ubiquitous" time measurement API. So it can be removed.

Activity

  1. added this to the V1.0 milestone on Oct 1, 2021
  2. Kangz commented on Oct 4, 2021

    @Kangz
    ContributorAuthor

    I assume @kvark meant to reply here instead of #1773:

    I did some investigation on which devices report 0 bits of precision in kainino0x/query-gpuinfo-data#1, and it appears to be Mali-GXX. They seem to otherwise not be filtered out. So the trade-off here is: if we have executionTime, we'll expose the Metal API almost directly, which is useful, and also implementable on most other platforms, except for Mali-G devices. If we don't have this API, we'll force the users to use an optional feature, and in addition they'd have to download the data by mapping the buffer.

    executionTime is implementable as soon as you have the optional timestamp-query, but it can be done just as easily by a user, and the code will written at most once per project. Exposing an API unconditionally while it is not implementable everywhere seems wrong. We could also make executionTime an optional feature. I'm happy to write a shim for executionTime if you think that's necessary for developer nicety.

  3. kvark commented on Oct 4, 2021

    @kvark
    Contributor

    The API in #2046 requires at least macOS 11 and iOS 14, while gpu start/end times are available on all Apple devices. So if we go this route, there will be a set of Apple devices that could otherwise give you the executionTime but would not have a way to expose this.

  4. Kangz commented on Oct 4, 2021

    @Kangz
    ContributorAuthor

    Why does it require macOS 11? You can implement timestamp queries on previous versions of macOS.

    So if we go this route, there will be a set of Apple devices that could otherwise give you the executionTime but would not have a way to expose this.

    I'd happily trade less API surface for tiny missing reach of something like executionTime given it cannot be implemented on all of the WebGPU targets anyway (looking at Vulkan on Mali and potentially other chips, but also GLES in the future etc)

  5. Kangz commented on Oct 4, 2021

    @Kangz
    ContributorAuthor

    MTLCounterSets are supported from macOS 10.15 https://developer.apple.com/documentation/metal/mtldevice/3081739-countersets?language=objc the supportsCounterSampling is something that was added in 11.0 as (at least my understanding) a decrease in features because the M1 doesn't support sampling timestamps at all locations previously used mac GPUs can.

  6. kainino0x commented on Oct 5, 2021

    @kainino0x
    Contributor

    GPUStartTime and GPUEndTime give results in "host time". I'm unclear on whether that means it's timed from the CPU or just converted to host time, but can we possibly paper over those Mali devices by implementing executionTime from the CPU?

  7. Kangz commented on Oct 8, 2021

    @Kangz
    ContributorAuthor

    I think it means it gives you a timestamp you can compare with other CPU timestamps, but I don't think this means that we can do the same thing on Vulkan because we don't get interrupts immediately when works finishes (there can be a lot of latency), nor when it starts.

  8. litherum commented on Oct 12, 2021

    @litherum
    Contributor

    When viewed through the lens of this issue, there are 3 classes Metal devices:

    1. Devices which do not support MTLCommonCounterSet.timestamp, or for which MTLDevice.supportsCounterSampling() returns false for every input
    2. Devices that do support MTLCommonCounterSet.timestamp but MTLDevice.supportsCounterSampling() only reports true for MTLCounterSamplingPoint.atStageBoundary
    3. Other devices (aka devices that support MTLCommonCounterSet.timestamp and where MTLDevice.supportsCounterSampling() returns true for other locations)

    GPUCommandBuffer.executionTime is necessary to get timing information on the first class of devices.

  9. litherum commented on Oct 12, 2021

    @litherum
    Contributor

    I did some investigation on which devices report 0 bits of precision in kainino0x/query-gpuinfo-data#1, and it appears to be Mali-GXX

    How common are these devices? It would be unfortunate if a sizable chunk of devices had to report bogus answers for GPUCommandBuffer.executionTime.

    Maybe another question - on these devices, is it possible to get any timing at all anywhere anyhow?

  10. litherum commented on Oct 12, 2021

    @litherum
    Contributor

    GPUStartTime and GPUEndTime give results in "host time".

    It's the time of an event which happened on the GPU, recorded as a timestamp relative to the CPU's timeline.

  11. Kangz commented on Oct 12, 2021

    @Kangz
    ContributorAuthor

    How common are these devices? It would be unfortunate if a sizable chunk of devices had to report bogus answers for GPUCommandBuffer.executionTime.

    Maybe another question - on these devices, is it possible to get any timing at all anywhere anyhow?

    Unfortunately these devices represent a sizeable chunk of Android Vulkan devices. ARM GPUs are used in many MediaTek SOCs AFAIK. On these devices I don't think there's any way to get valid GPU timestamps (except by faking them with best-guess CPU timestamps), which is why I think we should remove executionTime.

    @kainino0x also mentioned that in D3D12 there might not always be valid bits for timestamps but I can't find that in the doc. @RafaelCintron can there be D3D12 devices with no support for timestamp queries?

  12. Kangz commented on Oct 18, 2021

    @Kangz
    ContributorAuthor

    Looking at the Vulkan spec following today's call:

    timestampValidBits is the unsigned integer count of meaningful bits in the timestamps written via vkCmdWriteTimestamp. The valid range for the count is 36..64 bits, or a value of 0, indicating no support for timestamps. Bits outside the valid range are guaranteed to be zeros.

    There are no other guarantees in Vulkan. Even in WebGL disjoint timer queries are an extension. Same for OpenGL ES (never promoted to core).

  13. Kangz commented on Oct 22, 2021

    @Kangz
    ContributorAuthor

    Based on the comment above I think we should still remove executionTime as sad as it is.

  14. litherum commented on Oct 22, 2021

    @litherum
    Contributor

    I think the question is "of the devices which have 0 bits of precision for timestamps, do they also support disjoint timer queries?"

  15. Kangz commented on Oct 22, 2021

    @Kangz
    ContributorAuthor

    Disjoint timer queries also have a 0 guaranteed bits of precision (and you are supposed to query them). @vonture confirmed there are many ARM devices that have essentially no timestamps in GLES. (that matches the same thing in Vulkan).

  16. kainino0x commented on Oct 25, 2021

    @kainino0x
    Contributor

    Resolution: Remove executionTime. Don't need to bump it to an optional feature; we already have timestamp queries.
    Developers on platforms that can't support any kind of timing should try to use platform or vendor profiling tools (like xcode or whatever) instead.

  17. added a commit that references this issue on Oct 25, 2021
    b1d2ba4
  18. added a commit that references this issue on Nov 1, 2021
    695a36c
  19. added a commit that references this issue on Nov 4, 2021
    21cea71
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions