Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profiling support to the HAL API for use in benchmarks #45

Closed
benvanik opened this issue Oct 13, 2019 · 7 comments · Fixed by #10893
Closed

Add profiling support to the HAL API for use in benchmarks #45

benvanik opened this issue Oct 13, 2019 · 7 comments · Fixed by #10893
Assignees
Labels
enhancement ➕ New feature or request hal/api IREE's public C hardware abstraction layer API runtime Relating to the IREE runtime library

Comments

@benvanik
Copy link
Collaborator

We'll want a way to expose various metrics from the HAL implementations in a way that avoids excessive sequencer work. This could be accomplished by a begin/end profiling API and a resulting profile that contains cumulative, sampled, or averaged counter values per-backend. On Vulkan this may mean some vendor-specific performance counters in addition to timestamps inserted into command buffers.

@benvanik benvanik added the enhancement ➕ New feature or request label Oct 13, 2019
@benvanik benvanik added this to Ideas in Infrastructure and Benchmarking via automation Oct 13, 2019
@benvanik benvanik added this to Ideas in Runtime Optimization via automation Oct 13, 2019
@benvanik benvanik moved this from Ideas to To do in Infrastructure and Benchmarking Oct 13, 2019
@benvanik benvanik moved this from Ideas to To do in Runtime Optimization Oct 13, 2019
@benvanik benvanik added this to the Benchmarking Infrastructure milestone Oct 13, 2019
@benvanik benvanik added the runtime Relating to the IREE runtime library label Mar 19, 2020
@benvanik benvanik added this to Ideas in Runtime Development via automation Oct 14, 2020
@benvanik benvanik self-assigned this Nov 22, 2020
@benvanik benvanik added the hal/api IREE's public C hardware abstraction layer API label Nov 22, 2020
@benvanik
Copy link
Collaborator Author

1+ years on and progress is being made on this. New threading system will have statistics built-in and help me define the API we want to expose for this (likely something similar to feedback buffers).

@benvanik benvanik removed this from the Benchmarking Infrastructure milestone Nov 22, 2020
@benvanik benvanik added this to To do in 2021Q1 GPU Perf Burndown via automation Nov 22, 2020
@benvanik benvanik moved this from To do to Ideas in 2021Q1 GPU Perf Burndown Nov 22, 2020
@benvanik
Copy link
Collaborator Author

Maybe this year? :P
I think the first step is to get tracy recording Vulkan times and the task system appearing as a dedicated execution context in tracy as well. That will unblock performance investigations. I'm still not sure we have solid use cases for programmatic fine-grained profiling yet though those may be useful in parameter searches (though with all the usual caveats of applicability of timings they may not be).

@ThomasRaoux
Copy link
Contributor

Do you have some pointers on what would be needed to do to have tracy recoding Vulkan times and what would the result look like? On Android we have pretty much no useful tools for profiling within a command buffer. I hacked up some timestamp queries to be able to get a breakdown for mobile Bert but it is obviously not a sustainable solution. So this is probably our best bet to be able to do at least some basic profiling on phones and I can help out with implementation.

@benvanik
Copy link
Collaborator Author

I've got an old set of changes that enables Vulkan in tracy that I'll revive and get working. The issue I ran into last time (and what prevented me from committing it) was that tracy could not at the time render disjoint or overlapping zones, meaning that if there was any asynchronous or overlapping execution it would pad every zone out such that they were perfectly nested. I remember seeing that fiber support was getting added to tracy (in some form), and if it has landed then we can use that to allow the out-of-order zones. Otherwise, the tracy support only produces useful results if there's single dispatches between global barriers such that no two dispatches ever overlap and that's not very useful for anything but microbenchmarks (which could still be useful, but not general-purpose and with all the caveats of applicability microbenchmarks on GPUs have).

@benvanik
Copy link
Collaborator Author

Fiber support doesn't seem to have landed, but what we really want is wolfpld/tracy#149 - that's how I accomplished this in wtf and it worked really well. Unfortunately it looks like it's not planned work so I'm not sure what to do there.

With the new feature allowing multiple GPU context tracks I can at least split up queues such that queues can overlap, but within each queue the numbers you'll be getting will not account for overlap :(

@benvanik
Copy link
Collaborator Author

I'm going to avoid doing any HAL work here and instead just add Vulkan support directly to the Vulkan HAL. When we want programmatic queries we'll need to add explicit APIs to the HAL but for just seeing timing in tracy we can avoid that.

benvanik added a commit that referenced this issue Oct 25, 2022
TLDR: configure with `-DIREE_ENABLE_RENDERDOC_PROFILING=ON`, pass the
`--device_profiling_mode=queue` flag to the IREE tools, and launch the
tools from the RenderDoc UI in order to get a capture (or use
`renderdoccmd capture`):

![image](https://user-images.githubusercontent.com/75337/197648585-b34bd661-cfd1-4fbb-a6f9-2b73bec81b6a.png)

Things are set up to allow for other profiling modes in the future but
how best to integrate those is TBD. We can figure out how to scale this
with other tooling and on other backends but the rough shape of the API
should be compatible with the various backend APIs we target
(D3D/Metal/CUDA/Vulkan/perf/etc). Note that because RenderDoc will also
capture D3D the cmake flag is generic but both the Vulkan and D3D HAL
implementations will need to load it themselves (no real code worth
sharing as D3D naturally only needs the Windows API query path).

Docs have notes that I've verified on Windows. Someone looking to use
this on Android will need to figure that out and can add what they find.

Fixes #45. Forty five. Wow.
@powderluv
Copy link
Collaborator

this was the year!!! thanks @benvanik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ➕ New feature or request hal/api IREE's public C hardware abstraction layer API runtime Relating to the IREE runtime library
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants