This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
playground [2009/05/15 17:07] jjp |
playground [2015/08/23 13:59] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | # | + | <code># |
- | #include < | + | |
- | #include < | + | |
#include < | #include < | ||
+ | |||
#include < | #include < | ||
- | #include < | ||
- | #include " | ||
- | #include " | ||
- | #include " | ||
- | #include " | ||
- | const std::string SortingBenchmark:: | + | # |
- | #define ALGORITHMS_COUNT 5 | + | |
- | SortingBenchmark:: | + | #include |
- | { | + | |
- | mConsoleOutput = consoleOutput; | + | |
- | #ifdef SQLITE3 | + | |
- | if(sqlite3_open(dataBase, | + | |
- | { | + | |
- | fprintf(stderr, | + | |
- | sqlite3_close(mDataBase); | + | |
- | exit(1); | + | |
- | } | + | |
- | char* createTableCmd = " | + | void cudppSort(unsigned |
- | sqlite3_exec(mDataBase, createTableCmd, 0, 0, & | + | |
- | #endif | + | |
- | } | + | |
- | void SortingBenchmark:: | ||
{ | { | ||
- | float* data = new float[size]; | ||
- | float* dataCopy = new float[size]; | ||
- | unsigned int* dataIntCopy = new unsigned int[size]; | ||
- | |||
- | warmUp(); | ||
- | for (int i = 0; i < numSeq; i++) | + | unsigned |
- | { | + | |
- | fillRandomly(data, size); | + | |
- | for (int alg = 0; alg < ALGORITHMS_COUNT; | + | cutCreateTimer(&timer); |
- | { | + | cutCreateTimer(& |
- | for | + | |
- | { | + | |
- | double gpuTime, totalTime; | + | |
- | memcpy(dataCopy, data, sizeof(float) * size); | + | |
- | memcpy(dataIntCopy, | + | |
- | sort(dataCopy, dataIntCopy, | + | cutStartTimer(transferTimer); |
- | saveResult(gpuTime, | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | delete [] data; | ||
- | delete [] dataCopy; | ||
- | delete [] dataIntCopy; | ||
- | } | ||
- | void SortingBenchmark:: | + | unsigned |
- | { | + | |
- | const int size = 65536; | + | |
- | int ddata[size]; | + | |
- | size_t memSize = size * sizeof(int); | + | |
- | cudaMalloc((void**) &ddata, memSize); | + | |
- | cudaFree(ddata); | + | |
- | } | + | |
- | void SortingBenchmark:: | + | unsigned |
- | { | + | |
- | #ifdef SQLITE3 | + | size_t memSize = size * sizeof(unsigned |
- | char command[2048]; | + | |
- | sprintf(command," | + | |
- | int rc = sqlite3_exec(mDataBase, command, 0, 0, & | + | |
+ | cudaMalloc((void**) & | ||
+ | |||
+ | cudaMalloc((void**) &ddata2, memSize); | ||
+ | |||
+ | cudaMemcpy(ddata1, data, memSize, cudaMemcpyHostToDevice); | ||
+ | |||
+ | 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, ddata2, ddata1, size); | ||
+ | |||
+ | cudaThreadSynchronize(); | ||
+ | |||
+ | cutStopTimer(timer); | ||
+ | |||
+ | cutStartTimer(transferTimer); | ||
+ | |||
+ | |||
+ | |||
+ | cudaMemcpy(data, ddata2, memSize, cudaMemcpyDeviceToHost); | ||
+ | cudaFree(ddata1); | ||
+ | |||
+ | cudaFree(ddata2); | ||
+ | result = cudppDestroyPlan(sortplan); | ||
+ | |||
+ | cutStopTimer(transferTimer); | ||
+ | |||
+ | *time = cutGetTimerValue(timer); | ||
+ | *transferTime = cutGetTimerValue(transferTimer); | ||
+ | |||
+ | |||
+ | cutDeleteTimer(timer); | ||
+ | |||
+ | cutDeleteTimer(transferTimer); | ||
- | // Exit if we failed to insert data. | ||
- | if (rc!=SQLITE_OK) | ||
- | { | ||
- | fprintf(stderr, | ||
- | sqlite3_free(mSqlError); | ||
- | sqlite3_close(mDataBase); | ||
- | exit(1); | ||
- | } | ||
- | #endif | ||
- | if (mConsoleOutput) | ||
- | printf(" | ||
} | } | ||
- | void SortingBenchmark:: | + | |
+ | int main(int argc, char *argv[]) | ||
{ | { | ||
- | struct timeval starttime, endtime; | ||
- | gettimeofday(& | ||
- | switch | + | 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++) | ||
{ | { | ||
- | case 0: break; | + | cudppSort(data, size, &time, & |
- | case 1: cudppRadixMergeSortf(data, size, gpuTime); break; | + | printf(" |
- | case 2: cudppRadixSortf(data, size, gpuTime); break; | + | //time = 0.0; transferTime = 0.0; |
- | case 3: hybridsort(data, size, gpuTime); break; | + | |
- | case 4: gpuqsort(dataAsInt, | + | |
} | } | ||
- | |||
- | gettimeofday(& | ||
- | *totalTime = (endtime.tv_sec - starttime.tv_sec)*1000.0 + (endtime.tv_usec - starttime.tv_usec)/ | ||
- | } | ||
- | void SortingBenchmark:: | + | delete [] data; |
- | { | + | |
- | for (int i = 0; i < size; i++) data[i] = (float) rand(); | + | return |
- | } | + | |
+ | }</ |