CUDA. Threads "disappearing" in sequential executions

Asked

Viewed 15 times

2

I have been working on a project using CUDA to perform a segmentation operation. In my project I have some conditions if which modify a matrix by adding a 1 to the index of this matrix according to the wire. My problem is that when I read this matrix later to check which indexes have the number 1, I get different indexes for each run.

In my code, I have some if's that could cause the Wasp Divergence problem. However, I used some _syncthreads() in the code, all out of if's, not to occur deadlocks, but the problem persists.

 __global__ void BoundaryCUDA(arguments){

  unsigned char aux;
  int limite = 0;
  int row = blockDim.x * blockIdx.x + threadIdx.x;

  if ((row > 117808 && row < 118231) || (row > 176818 && row < 177241 ) || ( row > 235828 && row < 236251 ) || ( row > 294838 && row < 295261 ) || ( row > 353848 && row < 354271 ) || ( row > 412858 && row < 413281 ) || ( row > 471868 && row < 472291 ) || ( row > 530878 && row < 531301) ){
  }
  else{
    if(row > 59010 && row < 531090 && (row+1)%210!=0 && (row)%210 !=0){

        if (((pmatriz2_c[row-largura_c] - pmatriz2_c[row+largura_c])!=0) || ((pmatriz2_c[row+1] - pmatriz2_c[row-1])!=0) || ((pmatriz2_c[row+largura_c*altura_c] - pmatriz2_c[row-largura_c*altura_c])!=0)){

          limite =(((int)matrizLS_c[row]-(int)c1_c)*((int)matrizLS_c[row]-(int)c1_c)-2*((int)matrizLS_c[row]-(int)c0_c)*((int)matrizLS_c[row]-(int)c0_c));
          if(limite < 0) pmatriz_c[row] = 1;
          if(limite > 0) pmatriz_c[row] = 0;
        }
        aux=pmatriz_c[row];
        if(aux){
          atomicAdd(c3_c,(unsigned long long)matrizLS_c[row]);
          atomicAdd(j,1);
        }
         else {
          atomicAdd(c2_c,(unsigned long long)matrizLS_c[row]);
          atomicAdd(p,1);
        }
    }
  }
__syncthreads();
}

BoundaryCUDA<<<550,1024>>>()

The numbers below is the result of the pmatriz_c index that met the line condition if(limit < 0) pmatrix_c[row] = 1; of three consecutive runs, with no change between them. The numbers show which threads met the condition. The incoming data and number of threads are not changed.

214359 214360 214361 214362 214363 214567 214568 214569 214570 214571 214572 214573 214574 214575 214776 214777 214778 
214779 214780 214781 214782 214783 214784 214785 214786 214986 214987 214988 214989 214990 214991 214992 214993 214994 
214995 214996 215196 215197 215198 215199 215200 215201 215202 215203 215204 215205 215206 215407 215408 215409 215410 
215411 215412 215413 215414 215415 215619 215620 215621 215622 215623 273159 273160 273161 273162 273163 273367 273368 
273369 273370 273371 273372 273373 273374 273375 273576 273577 273578 273579 273580 273581 273582 273583 273584 273585 
273586 273785 273786 273787 273788 273789 273790 273791 273792 273793 273794 273795 273796 273797 273995 273996 273997 
273998 273999 274000 274001 274002 274003 274004 274005 274006 274007 274205 274206 274207 274208 274209 274210 274211 
274212 274213 274214 274215 274216 274217 274416 274417 274418 274419 274420 274421 274422 274423 274424 274425 274426 
274627 274628 274629 274630 274631 274632 274633 274634 274635 274839 274840 274841 274842 274843 332167 332168 332169 
332170 332171 332172 332173 332174 332175 332376 332377 332378 332379 332380 332381 332382 332383 332384 332385 332386 
332585 332586 332596 332597 332795 332796 332806 332807 333005 333006 333016 333017 333215 333216 333226 333227 333425 
333426 333436 333437 333636 333637 333638 333639 333640 333641 333642 333643 333644 333645 333646 333847 333848 333849 
333850 333851 333852 333853 333854 333855 391179 391180 391181 391182 391183 391387 391388 391389 391390 391391 391392 
391393 391394 391395 391596 391597 391598 391599 391600 391601 391602 391603 391604 391605 391606 391805 391806 391807 
391808 391809 391810 391811 391812 391813 391814 391815 391816 391817 392015 392016 392017 392018 392019 392020 392021 
392022 392023 392024 392025 392026 392027 392225 392226 392227 392228 392229 392230 392231 392232 392233 392234 392235 
392236 392237 392436 392437 392438 392439 392440 392441 392442 392443 392444 392445 392446 392647 392648 392649 392650 
392651 392652 392653 392654 392655 392859 392860 392861 392862 392863 450399 450400 450401 450402 450403 450607 450608 
450609 450610 450611 450612 450613 450614 450615 450816 450817 450818 450819 450820 450821 450822 450823 450824 450825 
450826 451026 451027 451028 451029 451030 451031 451032 451033 451034 451035 451036 451236 451237 451238 451239 451240 
451241 451242 451243 451244 451245 451246 451447 451448 451449 451450 451451 451452 451453 451454 451455 451659 451660 
451661 451662 451663 593912 593913 593914 
counter> 363 
214363 214568 214569 214571 214573 214574 214776 214778 214779 214780 214781 214782 214783 214784 214785 214986 214987 
214989 214992 214994 214995 215196 215197 215200 215201 215204 215206 215411 215412 215413 215414 273162 273367 273368 
273369 273372 273374 273578 273579 273580 273582 273583 273586 273785 273786 273787 273788 273790 273792 273794 273797 
273996 273998 274000 274001 274003 274004 274005 274006 274007 274206 274208 274209 274210 274211 274212 274213 274216 
274217 274416 274417 274418 274419 274420 274422 274423 274424 274425 274629 274632 274634 274840 332167 332169 332170 
332171 332173 332376 332377 332378 332381 332384 332385 332386 332586 332796 332806 333017 333215 333226 333227 333425 
333437 333637 333639 333640 333643 333645 333849 333853 333855 391179 391180 391181 391182 391387 391389 391390 391393 
391596 391599 391600 391602 391604 391606 391805 391808 391809 391813 391815 391816 392015 392017 392020 392021 392022 
392023 392024 392025 392027 392225 392226 392228 392230 392231 392233 392234 392235 392236 392237 392441 392442 392443 
392446 392647 392648 392649 392651 392655 392861 392863 450402 450607 450608 450610 450611 450612 450614 450615 450821 
450822 450823 450824 450826 451030 451036 451236 451238 451239 451241 451243 451244 451451 451454 451663 593912 593913 
593914 
counter> 188 
214361 214362 214363 214567 214572 214573 214574 214782 214783 214786 214986 214988 214992 214995 215196 215198 215202 
215203 215204 215206 215407 215408 215410 215411 215412 215413 215414 215415 273160 273161 273162 273163 273367 273368 
273370 273371 273372 273373 273374 273375 273576 273577 273581 273582 273583 273785 273786 273789 273793 273797 273995 
273996 273997 273998 274004 274005 274205 274206 274207 274210 274216 274217 274416 274417 274420 274421 274629 274630 
274631 274632 274633 274634 274635 274839 274841 274842 274843 332167 332168 332169 332170 332171 332172 332173 332385 
332386 332585 332596 332597 332795 332796 332806 333006 333016 333017 333215 333216 333226 333227 333425 333426 333646 
333847 333853 333854 333855 391182 391183 391388 391389 391394 391395 391596 391601 391602 391603 391604 391605 391606 
391805 391806 391810 391811 391812 391813 391814 391815 391816 392015 392016 392017 392019 392021 392022 392225 392226 
392227 392228 392229 392231 392233 392234 392235 392436 392441 392443 392647 392648 392649 392650 392651 392654 392859 
392860 392861 392862 392863 450399 450400 450401 450607 450615 450816 450817 450820 450822 450825 450826 451027 451029 
451031 451032 451033 451236 451237 451238 451239 451242 451244 451245 451447 451448 451454 451661 451662 451663 593912 
593913 593914 
counter> 189 

The number of threads and ID’s of each thread that are executed are different between sequential runs. The first numbers of the three sets, for example, are different.

There’s a cudaDeviceSynchronize(); after the CUDA function aiming to decrease the Wasp Divergence.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.