#!amber # Copyright 2024 The Amber Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This benchmark tests the latency cached memory # Configs to manually modify: # - kStride (prime number) : Caching behavior for pseudo random access # - number of loop unrolls : latency of single thread SHADER compute cached_memory_random GLSL #version 430 layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; layout(set = 0, binding = 0) buffer BlockA { uint data[]; } ssbo_read; layout(set = 0, binding = 1) buffer BlockB { uint data[]; } ssbo_write; uint ReadStrided(uint iter_val, uint ii){ // iter_val param will always be zero // Suggested strides (prime) 1, 3, 47, 14627 const uint kStride = 1u; const uint kSizeMask16M = 0xFFFFFF; return ssbo_read.data[(iter_val + (ii * kStride)) & kSizeMask16M]; } void main() { uint iter_val = ssbo_read.data[gl_GlobalInvocationID.x]; for(uint i = 0;i<10000;i+=10){ // 10x iter_val = ReadStrided(iter_val, i); iter_val = ReadStrided(iter_val, i+1); iter_val = ReadStrided(iter_val, i+2); iter_val = ReadStrided(iter_val, i+3); iter_val = ReadStrided(iter_val, i+4); iter_val = ReadStrided(iter_val, i+5); iter_val = ReadStrided(iter_val, i+6); iter_val = ReadStrided(iter_val, i+7); iter_val = ReadStrided(iter_val, i+8); iter_val = ReadStrided(iter_val, i+9); } ssbo_write.data[gl_GlobalInvocationID.x] = iter_val; } END BUFFER buf_read DATA_TYPE uint32 SIZE 16777216 FILL 0 BUFFER buf_write DATA_TYPE uint32 SIZE 1048576 FILL 0 PIPELINE compute pipeline ATTACH cached_memory_random BIND BUFFER buf_read AS storage DESCRIPTOR_SET 0 BINDING 0 BIND BUFFER buf_write AS storage DESCRIPTOR_SET 0 BINDING 1 END REPEAT 333 RUN TIMED_EXECUTION pipeline 1 1 1 END