User Tools

Site Tools


playground

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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:
-#include <algorithm> +<code>#include <cstring> 
-#include <cstring> +
-#include <math.h>+
 #include <stdio.h> #include <stdio.h>
 +
 #include <stdlib.h> #include <stdlib.h>
-#include <sys/time.h> 
-#include "SortingBenchmark.h" 
-#include "hybridsort/inc/hybridsort.h" 
-#include "cudpp/radixsort/inc/gpuradixsort.h" 
-#include "gpuqsort/inc/gpuqsort.h" 
  
-const std::string SortingBenchmark::algNames[] = { "bitonic", "radix", "radix_merge", "hybrid", "quick" }; +#include "cutil.h"
-#define ALGORITHMS_COUNT 5+
  
-SortingBenchmark::SortingBenchmark(const char* dataBase, bool consoleOutput) +#include "cudpp/cudpp.h"
-+
- mConsoleOutput = consoleOutput; +
-#ifdef SQLITE3 +
- if(sqlite3_open(dataBase, &mDataBase)) +
-+
- fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(mDataBase)); +
- sqlite3_close(mDataBase); +
- exit(1); +
- }+
  
- char* createTableCmd = "CREATE TABLE results (size int, algorithm varchar, totalTime float, gpuTime float, uid int);"; +void cudppSort(unsigned int* dataunsigned int sizedouble* timedouble* transferTimebool merge)
- sqlite3_exec(mDataBasecreateTableCmd0, 0&mSqlError)+
-#endif +
-}+
  
-void SortingBenchmark::runBenchmark(int size, int numSeq, int repeat, int uid) 
 { {
- 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 int timertransferTimer;
-+
- fillRandomly(datasize);+
  
- for (int alg = 0; alg < ALGORITHMS_COUNT; alg++) + cutCreateTimer(&timer); 
- + cutCreateTimer(&transferTimer);
- for (int k = 0; k < repeat; k++) +
-+
- double gpuTime, totalTime+
- memcpy(dataCopy, data, sizeof(float) * size); +
- memcpy(dataIntCopy, data, sizeof(float) * size);+
  
- sort(dataCopy, dataIntCopy, size, &gpuTime, &totalTime, alg);+ cutStartTimer(transferTimer);
  
- saveResult(gpuTime, totalTime, size, algNames[alg].c_str(), uid); 
- } 
- } 
- } 
-  
- delete [] data; 
- delete [] dataCopy; 
- delete [] dataIntCopy; 
-} 
  
-void SortingBenchmark::warmUp() + unsigned int* ddata1 0;
-+
-  const int size 65536; +
-  int ddata[size]; +
-  size_t memSize = size * sizeof(int); +
-  cudaMalloc((void**) &ddata, memSize); +
-  cudaFree(ddata)  +
-}+
  
-void SortingBenchmark::saveResult(double gpuTime, double totalTime, int size, const charalgorithm, int uid+ unsigned int* ddata2 = 0; 
-{  + 
-#ifdef SQLITE3 + size_t memSize = size * sizeof(unsigned int); 
- char command[2048]+ 
- sprintf(command,"insert into results values (%d,\"%s\",%f,%f,%d);\n",size, algorithmtotalTimegpuTimeuid); + 
- int rc = sqlite3_exec(mDataBasecommand00, &mSqlError);+ 
 + cudaMalloc((void**) &ddata1, memSize)
 + 
 + cudaMalloc((void**) &ddata2memSize); 
 + 
 + cudaMemcpy(ddata1datamemSizecudaMemcpyHostToDevice); 
 + 
 + 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(&sortplan, config, size, 10);   
 + 
 + 
 + 
 + cudppSort(sortplanddata2ddata1, size); 
 + 
 + cudaThreadSynchronize(); 
 + 
 + cutStopTimer(timer); 
 + 
 + cutStartTimer(transferTimer); 
 + 
 + 
 + 
 + cudaMemcpy(dataddata2memSizecudaMemcpyDeviceToHost);   
 + 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, "SQL error: %s\n", mSqlError); 
- sqlite3_free(mSqlError); 
- sqlite3_close(mDataBase); 
- exit(1); 
- } 
-#endif 
- if (mConsoleOutput) 
- printf("Size: %d Algorithm: %s Total time: %f Gpu time: %f\n", size, algorithm, totalTime, gpuTime); 
 } }
  
-void SortingBenchmark::sort(float* data, unsigned int* dataAsIntint size, doublegpuTime, double* totalTime, int algorithm)+ 
 +int main(int argcchar *argv[] 
 { {
- struct timeval starttime, endtime; 
- gettimeofday(&starttime,0); 
   
- switch (algorithm)+ 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("\nCUDPP Radix with sync..\n"); 
 + for (int i = 0; i < 5; i++)
  {  {
- case 0: break; + cudppSort(data, size, &time, &transferTime); 
- case 1: cudppRadixMergeSortf(data, size, gpuTime); break+ printf("Time%ftransfer time%f\n"timetransferTime); 
- case 2cudppRadixSortf(datasize, gpuTime); break; + //time = 0.0transferTime = 0.0;
- case 3hybridsort(datasizegpuTime); break+
- case 4: gpuqsort(dataAsInt, size, gpuTime)break;+
  }  }
-  
- gettimeofday(&endtime,0);  
- *totalTime = (endtime.tv_sec - starttime.tv_sec)*1000.0 + (endtime.tv_usec - starttime.tv_usec)/1000.0;  
-} 
  
-void SortingBenchmark::fillRandomly(float* data, int size) + delete [] data; 
-{ + 
- for (int i = 0; i < size; i++) data[i] = (float) rand()+ return 0;  
-}+ 
 +}</code>
playground.1242400052.txt.gz · Last modified: 2015/08/23 14:03 (external edit)