-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add buffer cacheline size metric (#4228)
Summary: Pull Request resolved: #4228 This diff introduces a metric to GPUInfo that calculates the cacheline size of the buffer data pathway. In this experiment, all threads read from the cache with a varying stride. Reading two values from the same cacheline is cheap because the whole line is fetched as a block, regardless of which data we actually want. By varying the separation between the addresses of these two values, there will be a point where the shader will be forced to fetch two separate cachelines, which will have an effect in latency that we can detect. [This article](https://igoro.com/archive/gallery-of-processor-cache-effects/) has more information on the topic. Each run of the shader fetches the two values from different points in memory. The shader also has a seemingly redundant variable `zero` that will force the compiler to avoid optimizing the for loop. The experiment will look like this: {F1754670481} Some useful concept definitions: NITER: The number of iterations that would take the lowest stride to run in 1000 microseconds. All experiments will then run this number of times. This is to have a timing baseline and avoid timing errors. PITCH: A number of bytes of separation between cache lines that ensures that all concurrent groups are being used, and therefore a fetch from two different cache lines is sure to have a latency increase. STRIDE: The actual size of the cache line that will be obtained experimentally. Increasing this until it reaches the cache line size should show a latency increase, giving us the result we look for. Reviewed By: jorgep31415 Differential Revision: D59649561 fbshipit-source-id: 2e82250d55929868982d17d1f405270897dcf9f4
- Loading branch information
1 parent
dd7fa6a
commit 6903715
Showing
4 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
backends/vulkan/tools/gpuinfo/glsl/buf_cacheline_size.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#version 450 core | ||
|
||
#define PRECISION ${PRECISION} | ||
|
||
layout(std430) buffer; | ||
|
||
|
||
${layout_declare_buffer(0, "r", "source", DTYPE)} | ||
${layout_declare_buffer(1, "w", "destination", DTYPE)} | ||
|
||
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; | ||
|
||
layout(constant_id = 3) const int niter = 1; | ||
layout(constant_id = 4) const int stride = 1; | ||
layout(constant_id = 5) const int pitch = 1; | ||
|
||
void main() { | ||
float c = 0; | ||
for (int i = 0; i < niter; ++i) { | ||
const int zero = i >> 31; | ||
c += source[zero + pitch * gl_GlobalInvocationID[0]]; | ||
c += source[zero + stride + pitch * gl_GlobalInvocationID[0]]; | ||
} | ||
destination[0] = c; | ||
} |
12 changes: 12 additions & 0 deletions
12
backends/vulkan/tools/gpuinfo/glsl/buf_cacheline_size.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
buf_cacheline_size: | ||
parameter_names_with_default_values: | ||
DTYPE: float | ||
STORAGE: buffer | ||
shader_variants: | ||
- NAME: buf_cacheline_size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters