view src/parallel_execution/examples/bitonicSort/CUDAbitonicSwap.cu @ 432:6bb391fc9e12

Work CudaExec
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Oct 2017 02:09:14 +0900
parents 764c92c3b181
children
line wrap: on
line source

extern "C" {
    struct Integer {
        int value;
    };
    struct SortArray {
        struct Integer *array;
        int loopCounter;
        int block;
        int first;
        int prefix;
    };
    __global__ void bitonicSwap(struct Integer* array, struct SortArray* sortArray) {
        int block = sortArray->block;
        int first = sortArray->first;
        int prefix = sortArray->prefix;
        int i = 0;
C_bitonicSwap:
        if (i < prefix) {
            int index = i + (blockIdx.x * blockDim.x + threadIdx.x) * prefix;
            int position = index/block;
            int index1 = index+block*position;
            int index2 = (first == 1)? ((block<<1)*(position+1))-(index1%block)-1 : index1+block;
            if (array[index2].value < array[index1].value) {
                struct Integer tmp = array[index1];
                array[index1] = array[index2];
                array[index2] = tmp;
            }
            i++;
            goto C_bitonicSwap;
        }
    }
}