Add UBO Read Bandwidth profiler (#4270)
Summary:
Pull Request resolved: https://github.com/pytorch/executorch/pull/4270
This diff introduces a profiler that obtains the maximum and minimum bandwidth for reading unique addresses from UBOs, using the following shader, where A is a UBO and B is a writeonly buffer.
void main() {
vec4 sum = vec4(0);
const uint workgroup_width = local_group_size * niter * ${NUNROLL};
uint offset = (gl_WorkGroupID[0] * workgroup_width + gl_LocalInvocationID[0]) & addr_mask;
int i = 0;
for (; i < niter; ++i)
{
sum *= A[offset];
offset = (offset + local_group_size) & addr_mask;
...
...
sum *= A[offset];
offset = (offset + local_group_size) & addr_mask;
}
vec4 zero = vec4(i>>31);
B[gl_LocalInvocationID[0]] = sum + zero;
}
The address mask allows us to control how many unique addresses we are accessing. If the number of unique vectors we want to read is 3, the offset will jump between three unique addresses throughout the iterations, giving us the bandwidth for that specific size of data. If the size of the unique data read is larger than the work group size, then each run will have its own block of data to read, defined by the initial offset calculation, where the offset is obtained through the workgroup ID and the local invocation ID.
Finally, we make sure to use the `sum` and `i ` variables so that the compiler's optimizer does not flatten the loops.
For a Samsung S22, the bandwidth behaves like this. We can see a decline proportional to the size of the buffer, until it plateaus at 32KB.
{F1759559978}
Comparing it with the Readonly profiler, we can immediately see the superiority in reading speed for UBOs, whenever the hardware is available
Samsung S22
{F1759560675}
Redmi Note
{F1759445004}
Reviewed By: copyrightly
Differential Revision: D59776899
fbshipit-source-id: 0f93186833bbe3610c5b5bf68cda519a7b467aca E
Esteban Padilla Cerdio committed
a4deccaf7a60b3966791c0ceb40c11f36669ba14
Parent: c72190a
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
on 7/18/2024, 2:44:49 PM