Search code examples
multithreadingcudaopenclnvidiabank-conflict

What is a bank conflict? (Doing Cuda/OpenCL programming)


I have been reading the programming guide for CUDA and OpenCL, and I cannot figure out what a bank conflict is. They just sort of dive into how to solve the problem without elaborating on the subject itself. Can anybody help me understand it? I have no preference if the help is in the context of CUDA/OpenCL or just bank conflicts in general in computer science.


Solution

  • For Nvidia (and AMD for that matter) GPUs the local memory is divided into memory banks. Each bank can only address one dataset at a time, so if a half warp tries to load/store data from/to the same bank the access has to be serialized (this is a bank conflict). For GT200 GPUs there are 16 banks (32 banks for Fermi), 16 or 32 banks for AMD GPUs (57xx or higher: 32, everything below: 16), which are interleaved with a granularity of 32 bit (so bytes 0-3 are in bank 1, 4-7 in bank 2, ..., 64-69 in bank 1 and so on). For a better visualization it basically looks like this:

    Bank    |      1      |      2      |      3      |     ...     |      16     |
    Address |  0  1  2  3 |  4  5  6  7 |  8  9 10 11 |     ...     | 60 61 62 63 |
    Address | 64 65 66 67 | 68 69 70 71 | 72 73 74 75 |     ...     |     ...     |
    ...
    

    So if each thread in a half warp accesses successive 32-bit values there are no bank conflicts.

    An exception from this rule (every thread must access its own bank) is broadcasting: if all threads access the same address, the value is only read once and broadcasted to all threads (for GT200 it has to be all threads in the half warp accessing the same address, IIRC Fermi and AMD GPUs can do this for any number of threads accessing the same value).