Count the cache-line transactions needed for a group of memory accesses. Each lane requests access_width_bytes consecutive bytes from its starting address. For lane i, ai is the start address, W is access_width_bytes, L is cache_line_bytes, and si and ei are its first and last touched line IDs. Floor rounds down.
si=⌊Lai⌋. ei=⌊Lai+W−1⌋.Each distinct touched line costs one transaction. Let U be the number of distinct requested byte addresses across all lanes and C be the number of touched lines:
useful_byte_fraction=CLU.Overlapping requests count shared bytes only once. Return a dictionary containing line_ids as a sorted one-dimensional NumPy int64 array of length C, transaction_count as a Python integer, and useful_byte_fraction as a Python float.
Input: byte_addresses = [0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0],"transaction_count":1,"useful_byte_fraction":1}
Explanation: The 32 adjacent four-byte requests cover exactly one 128-byte cache line, so every transferred byte is useful.
Input: byte_addresses = [0,1024,2048,3072], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0,8,16,24],"transaction_count":4,"useful_byte_fraction":0.03125}
Input: byte_addresses = [126], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0,1],"transaction_count":2,"useful_byte_fraction":0.015625}
Python sets discard duplicate byte addresses.
np.unique returns sorted distinct line IDs.
Accepts: array
Accepts: number
Accepts: number
Count the cache-line transactions needed for a group of memory accesses. Each lane requests access_width_bytes consecutive bytes from its starting address. For lane i, ai is the start address, W is access_width_bytes, L is cache_line_bytes, and si and ei are its first and last touched line IDs. Floor rounds down.
si=⌊Lai⌋. ei=⌊Lai+W−1⌋.Each distinct touched line costs one transaction. Let U be the number of distinct requested byte addresses across all lanes and C be the number of touched lines:
useful_byte_fraction=CLU.Overlapping requests count shared bytes only once. Return a dictionary containing line_ids as a sorted one-dimensional NumPy int64 array of length C, transaction_count as a Python integer, and useful_byte_fraction as a Python float.
Input: byte_addresses = [0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0],"transaction_count":1,"useful_byte_fraction":1}
Explanation: The 32 adjacent four-byte requests cover exactly one 128-byte cache line, so every transferred byte is useful.
Input: byte_addresses = [0,1024,2048,3072], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0,8,16,24],"transaction_count":4,"useful_byte_fraction":0.03125}
Input: byte_addresses = [126], access_width_bytes = 4, cache_line_bytes = 128
Output: {"line_ids":[0,1],"transaction_count":2,"useful_byte_fraction":0.015625}
Python sets discard duplicate byte addresses.
np.unique returns sorted distinct line IDs.
Accepts: array
Accepts: number
Accepts: number