All problems
Shared-Memory Bank Conflicts
Problem
Compute the bank conflict degree of a strided access pattern over 32 banks: threads map to banks via (thread * stride) % 32, so the number of threads per bank is gcd(stride, 32).
The signature is bank_conflicts(stride). Return an integer conflict factor.
Hint
Odd strides or padding a row by one element avoids conflicts entirely.
Test cases
case 1
in: [1]
expected: 1
case 2
in: [2]
expected: 2
case 3
in: [16]
expected: 16
case 4
in: [32]
expected: 32
case 5
in: [33]
expected: 1
Starter codePython
import math
def bank_conflicts(stride):
# Your code here
pass5 test cases · run your code against them in the editor