Skip to content

bank conflicts #7

@MeyerFabian

Description

@MeyerFabian

Did some testing with your/harris prefix sum code. I'm wondering if cuda does something different here:

#define CONFLICT_FREE_OFFSET(index) ((index) >> LOG_NUM_BANKS + (index) >> (2*LOG_NUM_BANKS))

Should be changed to:

#define CONFLICT_FREE_OFFSET(index) (((index) >> LOG_NUM_BANKS) + ((index) >> (2*LOG_NUM_BANKS)))

due to C++ Operator Precedence of + over >>.
Ran this code to test it:

#include <iostream>
#define NUM_BANKS 32 
#define LOG_NUM_BANKS 5

#define CONFLICT_FREE_OFFSET_ONCE(n) ((n) >> LOG_NUM_BANKS)
#define CONFLICT_FREE_OFFSET_TWICE(n) (((n) >> LOG_NUM_BANKS) + ((n) >> (2 * LOG_NUM_BANKS)))
#define CONFLICT_FREE_OFFSET_HARRIS(n) ((n) >> LOG_NUM_BANKS + (n) >> (2 * LOG_NUM_BANKS))

int main(){
    for(int i=0 ; i<1024;i++){
        int ai = i;
        int bi = i+1024;

        std::cout<< i << " bankOffsetA: " <<  CONFLICT_FREE_OFFSET_ONCE(ai)<< " bankOffsetB: " << CONFLICT_FREE_OFFSET_ONCE(bi) <<" Fluids" <<std::endl;
        std::cout<< i << " bankOffsetA: " <<  CONFLICT_FREE_OFFSET_TWICE(ai)<< " bankOffsetB: " << CONFLICT_FREE_OFFSET_TWICE(bi) <<" Test" <<std::endl;
        std::cout<< i << " bankOffsetA: " <<  CONFLICT_FREE_OFFSET_HARRIS(ai)<< " bankOffsetB: " << CONFLICT_FREE_OFFSET_HARRIS(bi) <<" Harris" <<std::endl;        
        std::cout<<std::endl;
        
    }
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions