Changeset 823 for soft/giet_vm/applications/rosenfeld/src-par
- Timestamp:
- Jun 14, 2016, 5:23:56 PM (8 years ago)
- Location:
- soft/giet_vm/applications/rosenfeld/src-par
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src-par/mca.c
r822 r823 98 98 99 99 100 // ----------------------------------------------- 100 // ------------------------------------------------ 101 101 void MCA_Set_Size(MCA * mca, int width, int height) 102 // ----------------------------------------------- 102 // ------------------------------------------------ 103 103 { 104 104 MCA_Set_Width(mca, width); … … 107 107 108 108 109 // ---------------------------------------------------- 109 // ----------------------------------------------------- 110 110 void MCA_Set_Dimension(MCA * mca, int width, int height) 111 // ---------------------------------------------------- 111 // ----------------------------------------------------- 112 112 { 113 113 MCA_Set_Width(mca, width); … … 116 116 117 117 118 // ------------------------------ 118 // ------------------------------- 119 119 void MCA_Set_NP(MCA * mca, int np) 120 // ------------------------------ 120 // ------------------------------- 121 121 { 122 122 mca->np = np; 123 123 } 124 125 126 // ------------------------------- 127 void MCA_Set_NR(MCA * mca, int nr) 128 // ------------------------------- 129 { 130 mca->nr = nr; 131 } 132 124 133 125 134 … … 146 155 // input 147 156 int np = mca->np; 157 int nr = mca->nr; 148 158 int width = mca->width; 149 159 int height = mca->height; … … 292 302 mca_par->e0 = e0_par; 293 303 mca_par->e1 = e1_par; 304 // à la premiÚre itération, on remet à 0 toute la table T 305 mca_par->ne_prev = e1_par; 294 306 mca_par->alpha = pw2; 295 307 mca_par->np = np; 308 mca_par->nr = nr; 296 309 // Pour les barriÚres pyramidales 297 310 mca_par->nb_level = nb_level; … … 311 324 mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border 312 325 313 if (p == 0) { 314 mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 315 mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y); 316 } 317 else { 318 mca_par->T = remote_ui32vector(e0_par, e1_par, x, y); 319 mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y); 320 } 326 mca_par->T = remote_ui32vector(e0_par, e1_par, x, y); 327 mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y); 321 328 322 329 mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y); … … 326 333 mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border 327 334 328 if (p == 0) { 329 mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 330 mca_par->stats = RegionStatsVector(e0_par - 1, e1_par); 331 } 332 else { 333 mca_par->T = ui32vector(e0_par, e1_par); 334 mca_par->stats = RegionStatsVector(e0_par, e1_par); 335 } 335 mca_par->T = ui32vector(e0_par, e1_par); 336 mca_par->stats = RegionStatsVector(e0_par, e1_par); 336 337 337 338 mca_par->D = (uint32 **) vvector(0, np - 1); … … 353 354 354 355 MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1)); 355 if (p == 0) { 356 set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 357 } 358 else { 359 set_ui32vector_j(T, e0, e1); 360 } 361 MCA_VERBOSE3(printf("\n")); 356 set_ui32vector_j(T, e0, e1); 362 357 } 363 358 … … 371 366 372 367 MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1)); 373 if (p == 0) { 374 MCA_VERBOSE3(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T")); 375 } 376 else { 377 MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T")); 378 } 368 MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T")); 379 369 MCA_VERBOSE3(printf("\n")); 380 370 } … … 506 496 free_dist_ui32matrix(mca_par->E, i0, i1, j0, j1); 507 497 508 if (p == 0) { 509 free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 510 free_RegionStatsVector(mca_par->stats, e0 - 1, e1); 511 } 512 else { 513 free_ui32vector(mca_par->T, e0, e1); 514 free_RegionStatsVector(mca_par->stats, e0, e1); 515 } 498 free_ui32vector(mca_par->T, e0, e1); 499 free_RegionStatsVector(mca_par->stats, e0, e1); 516 500 517 501 free_vvector((void **) mca_par->D, 0, np - 1); -
soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
r822 r823 43 43 #define MAX_THREADS 256 44 44 #define DEFAULT_NTHREADS 1 45 #define DEFAULT_NRUNS 1 45 46 #define DEFAULT_IN_FILENAME "/misc/cadastre.pgm" 46 47 #define DEFAULT_OUT_FILENAME "out.bmp" … … 233 234 234 235 235 // ----------------------------------------------------------- 236 void mca_test2(int num_threads, char * infile, char * outfile)237 // ----------------------------------------------------------- 236 // ------------------------------------------------------------------------- 237 void mca_test2(int num_threads, int num_runs, char * infile, char * outfile) 238 // ------------------------------------------------------------------------- 238 239 { 239 240 int i0, i1, j0, j1; … … 277 278 MCA_Set_ImageL(mca, E); 278 279 MCA_Set_NP(mca, num_threads); 280 MCA_Set_NR(mca, num_runs); 279 281 280 282 // -- MCA init … … 316 318 317 319 318 // -------------------------------------------------------------- 319 int main_test_mca(int num_threads, char * infile, char * outfile)320 // -------------------------------------------------------------- 320 // ---------------------------------------------------------------------------- 321 int main_test_mca(int num_threads, int num_runs, char * infile, char * outfile) 322 // ---------------------------------------------------------------------------- 321 323 { 322 324 CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body 323 325 CLOCK_APP_START; 324 326 325 mca_test2(num_threads, infile, outfile);327 mca_test2(num_threads, num_runs, infile, outfile); 326 328 327 329 CLOCK_APP_END; … … 349 351 int ch; 350 352 int num_threads = DEFAULT_NTHREADS; 353 int num_runs = DEFAULT_NRUNS; 351 354 352 355 MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n")); 353 356 354 357 #if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv 355 while ((ch = getopt(argc, argv, "i:o:n: hdg")) != EOF) {358 while ((ch = getopt(argc, argv, "i:o:n:r:hdg")) != EOF) { 356 359 switch (ch) { 357 360 case 'i': … … 363 366 case 'n': 364 367 num_threads = atoi(optarg); 368 break; 369 case 'r': 370 num_runs = atoi(optarg); 365 371 break; 366 372 case 'h': … … 409 415 MCA_VERBOSE1(printf("Parameters:\n")); 410 416 MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads)); 417 MCA_VERBOSE1(printf("- Number of images processed: %d\n", num_runs)); 411 418 MCA_VERBOSE1(printf("- Input file: %s\n", infile)); 412 419 MCA_VERBOSE1(printf("- Output file: %s\n", outfile)); … … 450 457 451 458 pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE); 452 main_test_mca(num_threads, infile, outfile);459 main_test_mca(num_threads, num_runs, infile, outfile); 453 460 454 461 return 0; -
soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c
r822 r823 142 142 } 143 143 #endif // FEATURES && !PARMERGE 144 145 146 #if !FEATURES && PARMERGE 147 // ----------------------------------------------------------------------------------------------------------- 148 static bool SetRoot_Parallel_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F) 149 // ----------------------------------------------------------------------------------------------------------- 150 { 151 assert(root != 0 && eps != 0); 152 153 MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root)); 154 155 int mask = (1 << shift) - 1; 156 157 uint32 r1 = root >> shift; 158 uint32 r0 = root & mask; 159 160 uint32 e1 = eps >> shift; 161 uint32 e0 = eps & mask; 162 163 // Locking towards the root (first root, then eps) 164 pthread_spin_lock(&F[r1][r0].lock); 165 pthread_spin_lock(&F[e1][e0].lock); 166 if (D[e1][e0] != eps || D[r1][r0] != root) { 167 // Someone change the root of epsilon or "root", need to find the new root 168 pthread_spin_unlock(&F[e1][e0].lock); 169 pthread_spin_unlock(&F[r1][r0].lock); 170 return false; 171 } 172 173 D[r1][r0] = eps; 174 175 pthread_spin_unlock(&F[e1][e0].lock); 176 pthread_spin_unlock(&F[r1][r0].lock); 177 return true; 178 } 179 #endif // !FEATURES && PARMERGE 144 180 145 181 … … 585 621 586 622 587 #if FAST && FEATURES && PARMERGE && !ARSP623 #if FAST && PARMERGE && !ARSP // Valid for FEATURES and !FEATURES 588 624 // --------------------------------------------------------------------------------------------------------------------------- 589 static void vuse2_Parallel_ Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)625 static void vuse2_Parallel_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 590 626 // --------------------------------------------------------------------------------------------------------------------------- 591 627 { … … 610 646 // qui a fait un test 611 647 if (rd < rl) { 612 ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F); 648 // Features or No Features depending on config 649 ok = SetRoot_Parallel_FNF(D, rl, rd, alpha, F); 613 650 } 614 651 else { 615 ok = SetRoot_Parallel_F eatures_Rosenfeld_Dist(D, rd, rl, alpha, F);652 ok = SetRoot_Parallel_FNF(D, rd, rl, alpha, F); 616 653 } 617 654 } while (!ok); 618 655 } 619 656 620 // FAST && FEATURES &&PARMERGE && !ARSP657 // FAST && PARMERGE && !ARSP 621 658 622 659 // ----------------------------------------------------------------------------------------------------------------------------------------- 623 static void vuse3_Parallel_ Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)660 static void vuse3_Parallel_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 624 661 // ----------------------------------------------------------------------------------------------------------------------------------------- 625 662 { … … 649 686 ok3 = true; 650 687 if (r1 > eps) { 651 ok1 = SetRoot_Parallel_F eatures_Rosenfeld_Dist(D, r1, eps, alpha, F);688 ok1 = SetRoot_Parallel_FNF(D, r1, eps, alpha, F); 652 689 } 653 690 if (r2 > eps && r2 != r1) { 654 ok2 = SetRoot_Parallel_F eatures_Rosenfeld_Dist(D, r2, eps, alpha, F);691 ok2 = SetRoot_Parallel_FNF(D, r2, eps, alpha, F); 655 692 } 656 693 if (r3 > eps && r3 != r2 && r3 != r1) { 657 ok3 = SetRoot_Parallel_F eatures_Rosenfeld_Dist(D, r3, eps, alpha, F);694 ok3 = SetRoot_Parallel_FNF(D, r3, eps, alpha, F); 658 695 } 659 696 } while (!(ok1 && ok2 && ok3)); 660 697 } 661 #endif // FAST && FEATURES &&PARMERGE && !ARSP698 #endif // FAST && PARMERGE && !ARSP 662 699 663 700 … … 1381 1418 uint32 e0 = mca->e0; 1382 1419 uint32 e1 = mca->e1; 1420 uint32 ne_prev = mca->ne_prev; 1383 1421 uint32 ne = e0 - 1; 1384 1422 uint32 nr = 0; … … 1390 1428 RegionStats * stats = mca->stats; 1391 1429 1392 // reset sous optimal (pour le moment = voir region32)1393 if (mca->p == 0) { 1394 set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot1430 CLOCK_THREAD_START_STEP(mca->p, 0); 1431 1432 set_ui32vector_j(T, e0, ne_prev); 1395 1433 #if FEATURES 1396 zero_RegionStatsVector(stats, e0 - 1, e1);1434 zero_RegionStatsVector(stats, e0, ne_prev); 1397 1435 #endif 1398 }1399 else {1400 set_ui32vector_j(T, e0, e1);1401 #if FEATURES1402 zero_RegionStatsVector(stats, e0, e1);1403 #endif1404 }1405 1436 1406 1437 if (mca->p == 0) { … … 1411 1442 // -- Etiquetage d'une bande -- // 1412 1443 // ---------------------------- // 1413 1414 CLOCK_THREAD_START_STEP(mca->p, 0);1415 1444 1416 1445 ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne); … … 1644 1673 1645 1674 CLOCK_THREAD_START(mca->p); 1646 CLOCK_THREAD_COMPUTE_START(mca->p); 1647 1648 MCA_Scatter_ImageX(mca); 1649 pthread_barrier_wait(&main_barrier); 1650 1651 MCA_Label_Rosenfeld_PAR1(mca); 1652 pthread_barrier_wait(&main_barrier); 1653 1675 1676 int num_runs = mca->nr; 1677 1678 // We always perform one more run than the num_runs 1679 // value, so as to know "ne", i.e. the number of 1680 // elements to reset in the T and F tables (labels and stats) 1681 // After this first extra run, clock times are not accumulated 1682 // and thus are lost. 1683 // Note: the CLOCK_THREAD_START will still include this first run, 1684 // and in case of multiple runs, only averaged times should be 1685 // considered. 1686 for (int run = 0; run < num_runs + 1; run++) { 1687 1688 CLOCK_THREAD_COMPUTE_START(mca->p); 1689 1690 MCA_Scatter_ImageX(mca); 1691 pthread_barrier_wait(&main_barrier); 1692 1693 MCA_Label_Rosenfeld_PAR1(mca); 1694 pthread_barrier_wait(&main_barrier); 1695 1654 1696 #if PARMERGE 1655 MCA_Label_Rosenfeld_PAR2(mca);1697 MCA_Label_Rosenfeld_PAR2(mca); 1656 1698 #else 1657 MCA_Label_Rosenfeld_PYR2(mca);1699 MCA_Label_Rosenfeld_PYR2(mca); 1658 1700 #endif 1659 pthread_barrier_wait(&main_barrier); 1660 1661 MCA_Label_Rosenfeld_PAR3(mca); 1662 pthread_barrier_wait(&main_barrier); 1663 1664 MCA_Gather_ImageL(mca); 1665 pthread_barrier_wait(&main_barrier); 1666 1667 CLOCK_THREAD_COMPUTE_END(mca->p); 1701 pthread_barrier_wait(&main_barrier); 1702 1703 MCA_Label_Rosenfeld_PAR3(mca); 1704 pthread_barrier_wait(&main_barrier); 1705 1706 MCA_Gather_ImageL(mca); 1707 pthread_barrier_wait(&main_barrier); 1708 1709 CLOCK_THREAD_COMPUTE_END(mca->p); 1710 1711 if (run == 0) { 1712 // Mise à jour du ne_prev par chaque thread 1713 mca->ne_prev = mca->ne; 1714 mca->ne = 0; 1715 } 1716 else { 1717 // Accumulation du temps COMPUTE et de toutes les STEP 1718 if (mca->p == 0) { 1719 CLOCK_ACCUMULATE; 1720 } 1721 assert(mca->ne == mca->ne_prev); 1722 // Reinitialisation de "ne" s'il ne s'agit pas du dernier run 1723 if (run != num_runs) { 1724 mca->ne = 0; 1725 } 1726 } 1727 pthread_barrier_wait(&main_barrier); 1728 } 1729 1668 1730 1669 1731 #if FEATURES
Note: See TracChangeset
for help on using the changeset viewer.