SIGN IN SIGN UP

Add Buffer Memory Bandwidth profiler (#4262)

Summary:
Pull Request resolved: https://github.com/pytorch/executorch/pull/4262

This diff introduces a profiler that obtains the maximum and minimum bandwidth for reading unique addresses from memory, using the following shader, where A and B are readonly and writeonly buffers, respectively.

  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 limitation when buffers reach 32 KB in size.

{F1759406621}

Reviewed By: SS-JIA

Differential Revision: D59687299

fbshipit-source-id: 5a97a2c2b0bf077c575de55d23061d5597ba385d
E
Esteban Padilla Cerdio committed
c72190ac5b4fbb0fd7bf8a2b2c7f8394be7f6f02
Parent: 544462d
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 7/18/2024, 2:44:49 PM