Skip to content
Snippets Groups Projects
Commit 0a7c6fab authored by Xuan Thang Nguyen's avatar Xuan Thang Nguyen
Browse files

check on task amount

parent 94b7e2d0
No related branches found
No related tags found
No related merge requests found
...@@ -156,7 +156,7 @@ __global__ void cudaInitTask(ArrayView<TASK, Devices::Cuda> cuda_tasks, ...@@ -156,7 +156,7 @@ __global__ void cudaInitTask(ArrayView<TASK, Devices::Cuda> cuda_tasks,
//----------------------------------------------------------- //-----------------------------------------------------------
//----------------------------------------------------------- //-----------------------------------------------------------
const int threadsPerBlock = 512, maxBlocks = 1 << 15; //32k const int threadsPerBlock = 512, maxBlocks = 1 << 15; //32k
const int g_maxTasks = 1 << 10; const int g_maxTasks = 1 << 14;
const int minElemPerBlock = threadsPerBlock; const int minElemPerBlock = threadsPerBlock;
class QUICKSORT class QUICKSORT
...@@ -212,7 +212,8 @@ public: ...@@ -212,7 +212,8 @@ public:
template <typename Function> template <typename Function>
void QUICKSORT::sort(const Function &Cmp) void QUICKSORT::sort(const Function &Cmp)
{ {
while (tasksAmount > 0)
while (tasksAmount > 0 && tasksAmount*2 < maxTasks)
{ {
int elemPerBlock = getElemPerBlock(); int elemPerBlock = getElemPerBlock();
int blocksCnt = initTasks(elemPerBlock); int blocksCnt = initTasks(elemPerBlock);
...@@ -240,10 +241,21 @@ void QUICKSORT::sort(const Function &Cmp) ...@@ -240,10 +241,21 @@ void QUICKSORT::sort(const Function &Cmp)
processNewTasks(); processNewTasks();
iteration++; iteration++;
} }
if(tasksAmount > 0)
{
cudaQuickSort2ndPhase<Function, 128>
<<<tasksAmount, threadsPerBlock>>>(arr, aux, Cmp,
iteration % 2 == 0? cuda_newTasks : cuda_tasks
);
}
cudaQuickSort2ndPhase<Function, 128> if(totalTask - tasksAmount > 0)
<<<cuda_2ndPhaseTasksAmount.getElement(0), threadsPerBlock>>>(arr, aux, Cmp, cuda_2ndPhaseTasks); {
cudaQuickSort2ndPhase<Function, 128>
<<<totalTask - tasksAmount, threadsPerBlock>>>(arr, aux, Cmp, cuda_2ndPhaseTasks);
}
cudaDeviceSynchronize(); cudaDeviceSynchronize();
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment