#include #include #define HIP_ASSERT(x) (assert((x)==hipSuccess)) __global__ void gpu_ballot(hipLaunchParm lp, unsigned int* device_ballot, int Num_Warps_per_Block,int pshift) { int tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x; const unsigned int warp_num = hipThreadIdx_x >> pshift; atomicAdd(&device_ballot[warp_num+hipBlockIdx_x*Num_Warps_per_Block],__popcll(__ballot(tid - 245))); } int main(int argc, char *argv[]) { int warpSize, pshift; hipDeviceProp_t devProp; hipDeviceGetProperties(&devProp, 0); if(strncmp(devProp.name,"Fiji",1)==0) {warpSize =64; pshift =6;} else {warpSize =32; pshift =5;} unsigned int Num_Threads_per_Block = 512; unsigned int Num_Blocks_per_Grid = 1; unsigned int Num_Warps_per_Block = Num_Threads_per_Block/warpSize; unsigned int Num_Warps_per_Grid = (Num_Threads_per_Block*Num_Blocks_per_Grid)/warpSize; unsigned int* host_ballot = (unsigned int*)malloc(Num_Warps_per_Grid*sizeof(unsigned int)); unsigned int* device_ballot; HIP_ASSERT(hipMalloc((void**)&device_ballot, Num_Warps_per_Grid*sizeof(unsigned int))); int divergent_count =0; for (int i=0; i