Оптимизация этого цикла для достижения лучшей производительности в CUDA.C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 Оптимизация этого цикла для достижения лучшей производительности в CUDA.

Сообщение Гость »


I would like to optimize this cycle because my performance are so bad. For each iteration I call the kernel that just separate nodes in two lists, the list that contain the nodes that have at least an edge pointing to the list of current leaves, and the list cointaining the other nodes, and i go ahead until I reach the root node. So I have so much allocation and deallocation but I don't know if it is the better way to do that (surely not):

Код: Выделить всё

    bool flag = true;
while(flag){

int counterNonLeaves = 0;

if(index == 0){
counterNonLeaves = (numNodes - allLen[index]);
blockSize = min(128, counterNonLeaves);
blockCount = (counterNonLeaves + blockSize - 1) / blockSize;
}
else{
counterNonLeaves = (allLen[index-1] - allLen[index]) - 1;
blockSize = min(128, counterNonLeaves);
blockCount = (counterNonLeaves + blockSize - 1) / blockSize;
}

// Local structures
Vertex* d_localNonLeaves;
Vertex* d_localLeaves;
Vertex* d_oldLeaves;
Vertex* d_oldNonLeaves;
int* lastLen;
cudaMalloc((void**)&d_localNonLeaves, (counterNonLeaves/2) * sizeof(Vertex));
cudaMalloc((void**)&d_localLeaves, ((counterNonLeaves/2)+1) * sizeof(Vertex));
cudaMalloc((void**)&d_oldLeaves, allLen[index] * sizeof(Vertex));
cudaMalloc((void**)&d_oldNonLeaves, (allLen[index]-1) * sizeof(Vertex));
cudaMalloc((void**)&lastLen, sizeof(int));
cudaMemset(lastLen, 0, 1 * sizeof(int));

// I take the current reference of "leaves" and "nonLeaves"
copyArrayHostToDevice(maxBis[index], d_oldLeaves, allLen[index]);
copyArrayHostToDevice(nonLeaves, d_oldNonLeaves, (allLen[index]-1));

index++;

maxBis = (Vertex**)realloc(maxBis, (index+1) * sizeof(Vertex*));
maxBis[index] = (Vertex*)malloc(((counterNonLeaves/2)+1) * sizeof(Vertex));
allLen = (int*)realloc(allLen, (index+1) * sizeof(int));
nonLeaves = (Vertex*)realloc(nonLeaves, (counterNonLeaves/2) * sizeof(Vertex));

// Second kernel
paige_tarjan_kernel(d_localNonLeaves, counterNonLeaves, d_localLeaves, d_oldLeaves, d_oldNonLeaves, allLen[index-1], lastLen);
cudaDeviceSynchronize();

// Copy back to the host
cudaMemcpy(&allLen[index], lastLen, sizeof(int), cudaMemcpyDeviceToHost);
copyArrayDeviceToHost(d_localLeaves, maxBis[index], allLen[index]);
copyArrayDeviceToHost(d_localNonLeaves, nonLeaves, (counterNonLeaves/2));

// Check to see if I arrived at the end of the cycle
if(allLen[index] == 1){
index++;
flag = false;
}

cudaFree(d_localNonLeaves);
cudaFree(d_localLeaves);
cudaFree(d_oldLeaves);
cudaFree(d_oldNonLeaves);
cudaFree(lastLen);
}
Assume that before this has been done a first preprocess operation that stored in

Код: Выделить всё

maxBis[0]
the starting leaves, and in

Код: Выделить всё

nonLeaves
the other nodes.


Источник: https://stackoverflow.com/questions/781 ... ce-in-cuda
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»