This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
playground [2008/11/02 12:43] cabalistic angelegt |
playground [2015/08/23 13:59] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | 4 8 | + | < |
- | 1 0 | + | |
- | 1 0 | + | |
- | 1 2 | + | |
- | 1 3 | + | |
- | 1 4 | + | |
- | 2 0 | + | |
- | 3 0 | + | |
- | 4 0 | + | |
- | 0 0 | + | |
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | |||
+ | #include " | ||
+ | |||
+ | void cudppSort(unsigned int* data, unsigned int size, double* time, double* transferTime, | ||
+ | |||
+ | { | ||
+ | |||
+ | unsigned int timer, transferTimer; | ||
+ | |||
+ | cutCreateTimer(& | ||
+ | cutCreateTimer(& | ||
+ | |||
+ | cutStartTimer(transferTimer); | ||
+ | |||
+ | |||
+ | unsigned int* ddata1 = 0; | ||
+ | |||
+ | unsigned int* ddata2 = 0; | ||
+ | |||
+ | size_t memSize = size * sizeof(unsigned int); | ||
+ | |||
+ | |||
+ | |||
+ | cudaMalloc((void**) & | ||
+ | |||
+ | cudaMalloc((void**) & | ||
+ | |||
+ | cudaMemcpy(ddata1, | ||
+ | |||
+ | cutStopTimer(transferTimer); | ||
+ | |||
+ | cudaThreadSynchronize(); | ||
+ | cutStartTimer(timer); | ||
+ | |||
+ | |||
+ | |||
+ | CUDPPConfiguration config; | ||
+ | |||
+ | |||
+ | |||
+ | if (merge) | ||
+ | |||
+ | config.algorithm = CUDPP_SORT_RADIX; | ||
+ | |||
+ | else | ||
+ | |||
+ | config.algorithm = CUDPP_SORT_RADIX_GLOBAL; | ||
+ | |||
+ | |||
+ | |||
+ | config.datatype = CUDPP_UINT; | ||
+ | |||
+ | |||
+ | |||
+ | CUDPPHandle sortplan = 0; | ||
+ | |||
+ | CUDPPResult result = cudppPlan(& | ||
+ | |||
+ | |||
+ | |||
+ | cudppSort(sortplan, | ||
+ | |||
+ | cudaThreadSynchronize(); | ||
+ | |||
+ | cutStopTimer(timer); | ||
+ | |||
+ | cutStartTimer(transferTimer); | ||
+ | |||
+ | |||
+ | |||
+ | cudaMemcpy(data, | ||
+ | cudaFree(ddata1); | ||
+ | |||
+ | cudaFree(ddata2); | ||
+ | result = cudppDestroyPlan(sortplan); | ||
+ | |||
+ | cutStopTimer(transferTimer); | ||
+ | |||
+ | *time = cutGetTimerValue(timer); | ||
+ | *transferTime = cutGetTimerValue(transferTimer); | ||
+ | |||
+ | |||
+ | cutDeleteTimer(timer); | ||
+ | |||
+ | cutDeleteTimer(transferTimer); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | int main(int argc, char *argv[]) | ||
+ | |||
+ | { | ||
+ | |||
+ | int size = 10000000; | ||
+ | float* data = new float[size]; | ||
+ | for (int i = 0; i < size; i++) | ||
+ | data[i] = float(rand()); | ||
+ | |||
+ | double time = 0.0; | ||
+ | double transferTime = 0.0; | ||
+ | printf(" | ||
+ | for (int i = 0; i < 5; i++) | ||
+ | { | ||
+ | cudppSort(data, | ||
+ | printf(" | ||
+ | //time = 0.0; transferTime = 0.0; | ||
+ | } | ||
+ | |||
+ | delete [] data; | ||
+ | |||
+ | return 0; | ||
+ | |||
+ | }</ |