Disable autotuning during the call to this function. Some tests want to base assertions on a graph being isomorphic with a copy. To ensure this, this decorator disables autotuning. Args: func: Function to run with CuDNN autotuning turned off. Returns: Decorated function.
(func)
| 1566 | |
| 1567 | |
| 1568 | def disable_cudnn_autotune(func): |
| 1569 | """Disable autotuning during the call to this function. |
| 1570 | |
| 1571 | Some tests want to base assertions on a graph being isomorphic with a copy. |
| 1572 | To ensure this, this decorator disables autotuning. |
| 1573 | |
| 1574 | Args: |
| 1575 | func: Function to run with CuDNN autotuning turned off. |
| 1576 | |
| 1577 | Returns: |
| 1578 | Decorated function. |
| 1579 | """ |
| 1580 | |
| 1581 | def decorator(f): |
| 1582 | |
| 1583 | def decorated(self, *args, **kwargs): |
| 1584 | original_tf_cudnn_use_autotune = os.environ.get("TF_CUDNN_USE_AUTOTUNE") |
| 1585 | os.environ["TF_CUDNN_USE_AUTOTUNE"] = "false" |
| 1586 | original_xla_flags = os.environ.get("XLA_FLAGS") |
| 1587 | new_xla_flags = "--xla_gpu_autotune_level=0" |
| 1588 | if original_xla_flags: |
| 1589 | new_xla_flags = original_xla_flags + " " + new_xla_flags |
| 1590 | os.environ["XLA_FLAGS"] = new_xla_flags |
| 1591 | |
| 1592 | result = f(self, *args, **kwargs) |
| 1593 | |
| 1594 | if (original_tf_cudnn_use_autotune is None): |
| 1595 | del os.environ["TF_CUDNN_USE_AUTOTUNE"] |
| 1596 | else: |
| 1597 | os.environ["TF_CUDNN_USE_AUTOTUNE"] = original_tf_cudnn_use_autotune |
| 1598 | if (original_xla_flags is None): |
| 1599 | del os.environ["XLA_FLAGS"] |
| 1600 | else: |
| 1601 | os.environ["XLA_FLAGS"] = original_xla_flags |
| 1602 | |
| 1603 | return result |
| 1604 | |
| 1605 | return decorated |
| 1606 | |
| 1607 | if func is not None: |
| 1608 | return decorator(func) |
| 1609 | |
| 1610 | return decorator |
| 1611 | |
| 1612 | |
| 1613 | # The description is just for documentation purposes. |
nothing calls this directly
no test coverage detected