1#!amber 2# Copyright 2024 The Amber Authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16 17# This benchmark tests the latency cached memory 18# Configs to manually modify: 19# - kStride (prime number) : Caching behavior for pseudo random access 20# - number of loop unrolls : latency of single thread 21 22SHADER compute cached_memory_random GLSL 23#version 430 24 25layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 26 27layout(set = 0, binding = 0) buffer BlockA { 28 uint data[]; 29} ssbo_read; 30 31layout(set = 0, binding = 1) buffer BlockB { 32 uint data[]; 33} ssbo_write; 34 35uint ReadStrided(uint iter_val, uint ii){ 36 // iter_val param will always be zero 37 // Suggested strides (prime) 1, 3, 47, 14627 38 const uint kStride = 1u; 39 const uint kSizeMask16M = 0xFFFFFF; 40 return ssbo_read.data[(iter_val + (ii * kStride)) & kSizeMask16M]; 41} 42 43void main() { 44 uint iter_val = ssbo_read.data[gl_GlobalInvocationID.x]; 45 for(uint i = 0;i<10000;i+=10){ 46 // 10x 47 iter_val = ReadStrided(iter_val, i); 48 iter_val = ReadStrided(iter_val, i+1); 49 iter_val = ReadStrided(iter_val, i+2); 50 iter_val = ReadStrided(iter_val, i+3); 51 iter_val = ReadStrided(iter_val, i+4); 52 iter_val = ReadStrided(iter_val, i+5); 53 iter_val = ReadStrided(iter_val, i+6); 54 iter_val = ReadStrided(iter_val, i+7); 55 iter_val = ReadStrided(iter_val, i+8); 56 iter_val = ReadStrided(iter_val, i+9); 57 } 58 ssbo_write.data[gl_GlobalInvocationID.x] = iter_val; 59} 60END 61 62BUFFER buf_read DATA_TYPE uint32 SIZE 16777216 FILL 0 63BUFFER buf_write DATA_TYPE uint32 SIZE 1048576 FILL 0 64 65PIPELINE compute pipeline 66 ATTACH cached_memory_random 67 BIND BUFFER buf_read AS storage DESCRIPTOR_SET 0 BINDING 0 68 BIND BUFFER buf_write AS storage DESCRIPTOR_SET 0 BINDING 1 69END 70 71REPEAT 333 72RUN TIMED_EXECUTION pipeline 1 1 1 73END 74 75