This shows you the differences between two versions of the page.
playground [2009/05/15 17:07] jjp |
playground [2015/08/23 13:59] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include " | ||
- | #include " | ||
- | #include " | ||
- | #include " | ||
- | const std::string SortingBenchmark:: | ||
- | #define ALGORITHMS_COUNT 5 | ||
- | |||
- | SortingBenchmark:: | ||
- | { | ||
- | mConsoleOutput = consoleOutput; | ||
- | #ifdef SQLITE3 | ||
- | if(sqlite3_open(dataBase, | ||
- | { | ||
- | fprintf(stderr, | ||
- | sqlite3_close(mDataBase); | ||
- | exit(1); | ||
- | } | ||
- | |||
- | char* createTableCmd = " | ||
- | sqlite3_exec(mDataBase, | ||
- | #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++) | ||
- | { | ||
- | fillRandomly(data, | ||
- | |||
- | for (int alg = 0; alg < ALGORITHMS_COUNT; | ||
- | { | ||
- | for (int k = 0; k < repeat; k++) | ||
- | { | ||
- | double gpuTime, totalTime; | ||
- | memcpy(dataCopy, | ||
- | memcpy(dataIntCopy, | ||
- | |||
- | sort(dataCopy, | ||
- | |||
- | saveResult(gpuTime, | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | delete [] data; | ||
- | delete [] dataCopy; | ||
- | delete [] dataIntCopy; | ||
- | } | ||
- | |||
- | void SortingBenchmark:: | ||
- | { | ||
- | const int size = 65536; | ||
- | int ddata[size]; | ||
- | size_t memSize = size * sizeof(int); | ||
- | cudaMalloc((void**) &ddata, memSize); | ||
- | cudaFree(ddata); | ||
- | } | ||
- | |||
- | void SortingBenchmark:: | ||
- | { | ||
- | #ifdef SQLITE3 | ||
- | char command[2048]; | ||
- | sprintf(command," | ||
- | int rc = sqlite3_exec(mDataBase, | ||
- | |||
- | // 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:: | ||
- | { | ||
- | struct timeval starttime, endtime; | ||
- | gettimeofday(& | ||
- | |||
- | switch (algorithm) | ||
- | { | ||
- | case 0: break; | ||
- | case 1: cudppRadixMergeSortf(data, | ||
- | case 2: cudppRadixSortf(data, | ||
- | case 3: hybridsort(data, | ||
- | case 4: gpuqsort(dataAsInt, | ||
- | } | ||
- | |||
- | gettimeofday(& | ||
- | *totalTime = (endtime.tv_sec - starttime.tv_sec)*1000.0 + (endtime.tv_usec - starttime.tv_usec)/ | ||
- | } | ||
- | |||
- | void SortingBenchmark:: | ||
- | { | ||
- | for (int i = 0; i < size; i++) data[i] = (float) rand(); | ||
- | } |