|
14 | 14 | from devito.arch import Cpu64, Device, get_cpu_info, get_gpu_info |
15 | 15 | from devito.exceptions import InvalidArgument |
16 | 16 | from devito.ir import ( |
17 | | - Call, Conditional, Expression, FindNodes, FindSymbols, Section, |
| 17 | + Call, Conditional, Expression, FindNodes, FindSymbols, Section, Transfer, |
18 | 18 | retrieve_iteration_tree |
19 | 19 | ) |
20 | 20 | from devito.passes.iet.languages.openmp import OmpIteration |
@@ -285,7 +285,9 @@ def test_linearize_transfer_no_overflow(self): |
285 | 285 |
|
286 | 286 | # The transfer bound is a product of the four `size[i]`, each cast to |
287 | 287 | # `long`; the multiplication is thus carried out in 64-bit arithmetic |
288 | | - for transfer in op.body.maps + op.body.unmaps: |
| 288 | + transfers = FindNodes(Transfer).visit(op.body.maps + op.body.unmaps) |
| 289 | + assert len(transfers) == 3 |
| 290 | + for transfer in transfers: |
289 | 291 | code = transfer.ccode.value |
290 | 292 | for i in range(4): |
291 | 293 | assert f'(long)(u_vec->size[{i}])' in code |
@@ -453,7 +455,10 @@ def test_tasking_fused(self): |
453 | 455 | assert len(retrieve_iteration_tree(op)) == 3 |
454 | 456 | locks = [i for i in FindSymbols().visit(op) if isinstance(i, Lock)] |
455 | 457 | assert len(locks) == 1 # Only 1 because it's only `tmp` that needs protection |
456 | | - assert len(op._func_table) == 5 + int(configuration['language'] == 'openacc') |
| 458 | + if configuration['language'] == 'openacc': |
| 459 | + assert len(op._func_table) == 7 |
| 460 | + else: |
| 461 | + assert len(op._func_table) == 5 |
457 | 462 | exprs = FindNodes(Expression).visit(op._func_table['copy_to_host0'].root) |
458 | 463 | b = 17 if configuration['language'] == 'openacc' else 16 # No `qid` w/ OMP |
459 | 464 | assert str(exprs[b]) == 'const int deviceid = sdata0->deviceid;' |
@@ -508,7 +513,10 @@ def test_tasking_unfused_two_locks(self): |
508 | 513 | body = sections[2].body[0].body[0] |
509 | 514 | assert str(body.body[0]) == 'release_lock0(lock0);' |
510 | 515 | assert str(body.body[1]) == 'activate0(time,sdata0);' |
511 | | - assert len(op._func_table) == 5 + int(configuration['language'] == 'openacc') |
| 516 | + if configuration['language'] == 'openacc': |
| 517 | + assert len(op._func_table) == 7 |
| 518 | + else: |
| 519 | + assert len(op._func_table) == 5 |
512 | 520 | calls = FindNodes(Call).visit(op._func_table['copy_to_host0'].root) |
513 | 521 | stores = [str(i) for i in calls if i.name == '__atomic_store_n'] |
514 | 522 | assert stores[0] == '__atomic_store_n(&lock0[0],1,__ATOMIC_RELEASE);' |
@@ -563,7 +571,10 @@ def test_tasking_forcefuse(self): |
563 | 571 | assert str(body.body[1]) == 'sdata0[0].time = time;' |
564 | 572 | assert str(body.body[2]) == \ |
565 | 573 | '__atomic_store_n(&sdata0[0].flag,2,__ATOMIC_RELEASE);' |
566 | | - assert len(op._func_table) == 5 + int(configuration['language'] == 'openacc') |
| 574 | + if configuration['language'] == 'openacc': |
| 575 | + assert len(op._func_table) == 7 |
| 576 | + else: |
| 577 | + assert len(op._func_table) == 5 |
567 | 578 | exprs = FindNodes(Expression).visit(op._func_table['copy_to_host0'].root) |
568 | 579 | b = 21 if configuration['language'] == 'openacc' else 20 # No `qid` w/ OMP |
569 | 580 | assert exprs[b].write is u |
@@ -636,7 +647,10 @@ def test_tasking_multi_output(self): |
636 | 647 | body = op1._func_table['activate0'].root.body |
637 | 648 | assert str(body.body[-1]) == \ |
638 | 649 | '__atomic_store_n(&sdata0[wi0].flag,2,__ATOMIC_RELEASE);' |
639 | | - assert len(op1._func_table) == 5 + int(configuration['language'] == 'openacc') |
| 650 | + if configuration['language'] == 'openacc': |
| 651 | + assert len(op1._func_table) == 7 |
| 652 | + else: |
| 653 | + assert len(op1._func_table) == 5 |
640 | 654 | exprs = FindNodes(Expression).visit(op1._func_table['copy_to_host0'].root) |
641 | 655 | b = 21 if configuration['language'] == 'openacc' else 20 # No `qid` w/ OMP |
642 | 656 | assert exprs[b].write is usave |
@@ -695,8 +709,9 @@ def test_streaming_basic(self, opt, ntmps): |
695 | 709 | op = Operator(eqn, opt=opt) |
696 | 710 |
|
697 | 711 | # Check generated code |
| 712 | + # OpenACC maps both the Function and its staging array. |
698 | 713 | if configuration['language'] == 'openacc': |
699 | | - assert len(op._func_table) == 10 |
| 714 | + assert len(op._func_table) == 11 |
700 | 715 | else: |
701 | 716 | assert len(op._func_table) == 8 |
702 | 717 | assert len([i for i in FindSymbols().visit(op) if i.is_Array]) == ntmps |
@@ -771,7 +786,7 @@ def test_streaming_two_buffers(self, opt, ntmps): |
771 | 786 | # Check generated code |
772 | 787 | arrays = [i for i in FindSymbols().visit(op) if i.is_Array] |
773 | 788 | if configuration['language'] == 'openacc': |
774 | | - assert len(op._func_table) == 10 |
| 789 | + assert len(op._func_table) == 11 |
775 | 790 | assert len(arrays) == ntmps |
776 | 791 | else: |
777 | 792 | assert len(op._func_table) == 8 |
@@ -982,7 +997,7 @@ def test_streaming_multi_input(self, opt, ntmps): |
982 | 997 |
|
983 | 998 | # Check generated code |
984 | 999 | if configuration['language'] == 'openacc': |
985 | | - assert len(op1._func_table) == 10 |
| 1000 | + assert len(op1._func_table) == 11 |
986 | 1001 | else: |
987 | 1002 | assert len(op1._func_table) == 8 |
988 | 1003 | assert len([i for i in FindSymbols().visit(op1) if i.is_Array]) == ntmps |
@@ -1074,7 +1089,7 @@ def test_streaming_postponed_deletion(self, opt, ntmps): |
1074 | 1089 |
|
1075 | 1090 | # Check generated code |
1076 | 1091 | if configuration['language'] == 'openacc': |
1077 | | - assert len(op1._func_table) == 10 |
| 1092 | + assert len(op1._func_table) == 11 |
1078 | 1093 | else: |
1079 | 1094 | assert len(op1._func_table) == 8 |
1080 | 1095 | assert len([i for i in FindSymbols().visit(op1) if i.is_Array]) == ntmps |
@@ -1160,7 +1175,7 @@ def test_composite_buffering_tasking_multi_output(self): |
1160 | 1175 | # loop nests, but they eventually get mapped to the same pair of efuncs, |
1161 | 1176 | # since devito attempts to maximize code reuse |
1162 | 1177 | if configuration['language'] == 'openacc': |
1163 | | - assert len(op1._func_table) == 9 |
| 1178 | + assert len(op1._func_table) == 10 |
1164 | 1179 | else: |
1165 | 1180 | assert len(op1._func_table) == 7 |
1166 | 1181 |
|
@@ -1383,7 +1398,7 @@ def test_save_multi_output(self): |
1383 | 1398 | # are identical, so they get mapped to the same efuncs (init + copy) |
1384 | 1399 | # There also are two extra functions to allocate and free arrays |
1385 | 1400 | if configuration['language'] == 'openacc': |
1386 | | - assert len(op._func_table) == 9 |
| 1401 | + assert len(op._func_table) == 10 |
1387 | 1402 | else: |
1388 | 1403 | assert len(op._func_table) == 7 |
1389 | 1404 |
|
@@ -1442,7 +1457,7 @@ def test_save_w_nonaffine_time(self): |
1442 | 1457 | # We just check the generated code here |
1443 | 1458 | assert len([i for i in FindSymbols().visit(op) if isinstance(i, Lock)]) == 1 |
1444 | 1459 | if configuration['language'] == 'openacc': |
1445 | | - assert len(op._func_table) == 9 |
| 1460 | + assert len(op._func_table) == 11 |
1446 | 1461 | else: |
1447 | 1462 | assert len(op._func_table) == 7 |
1448 | 1463 |
|
@@ -1502,7 +1517,7 @@ def test_streaming_w_shifting(self, opt, ntmps): |
1502 | 1517 |
|
1503 | 1518 | # Check generated code |
1504 | 1519 | if configuration['language'] == 'openacc': |
1505 | | - assert len(op._func_table) == 10 |
| 1520 | + assert len(op._func_table) == 11 |
1506 | 1521 | else: |
1507 | 1522 | assert len(op._func_table) == 8 |
1508 | 1523 | assert len([i for i in FindSymbols().visit(op) if i.is_Array]) == ntmps |
@@ -1560,16 +1575,21 @@ def test_streaming_complete(self): |
1560 | 1575 | {'npthreads': 1})) |
1561 | 1576 |
|
1562 | 1577 | # Check generated code |
1563 | | - diff = int(configuration['language'] == 'openmp') |
1564 | | - extra = int(configuration['language'] == 'openacc') |
1565 | | - assert len(op1._func_table) == 14 - diff + extra |
1566 | | - assert len([i for i in FindSymbols().visit(op1) if i.is_Array]) == 9 - diff |
1567 | | - assert len(op2._func_table) == 14 - diff + extra |
1568 | | - assert len([i for i in FindSymbols().visit(op2) if i.is_Array]) == 9 - diff |
1569 | 1578 | # The streaming/buffering cannot be fused since the guards of |
1570 | 1579 | # vas and vasb/vasf are not compatible. |
1571 | | - assert len(op3._func_table) == 12 - diff + extra |
1572 | | - assert len([i for i in FindSymbols().visit(op3) if i.is_Array]) == 9 - diff |
| 1580 | + if configuration['language'] == 'openacc': |
| 1581 | + expected_funcs = (16, 16, 14) |
| 1582 | + expected_arrays = 9 |
| 1583 | + elif configuration['language'] == 'openmp': |
| 1584 | + expected_funcs = (13, 13, 11) |
| 1585 | + expected_arrays = 8 |
| 1586 | + else: |
| 1587 | + expected_funcs = (14, 14, 12) |
| 1588 | + expected_arrays = 9 |
| 1589 | + for op, nfuncs in zip((op1, op2, op3), expected_funcs, strict=True): |
| 1590 | + assert len(op._func_table) == nfuncs |
| 1591 | + arrays = [i for i in FindSymbols().visit(op) if i.is_Array] |
| 1592 | + assert len(arrays) == expected_arrays |
1573 | 1593 |
|
1574 | 1594 | op0.apply(time_m=15, time_M=35, save_shift=0) |
1575 | 1595 | op1.apply(time_m=15, time_M=36, save_shift=0, u=u1) |
|
0 commit comments