Check if a target should be used when testing. It is recommended that you use :py:func:`tvm.testing.parametrize_targets` instead of manually checking if a target is enabled. This allows the user to control which devices they are testing against. In tests, this should be used to che
(target)
| 457 | |
| 458 | |
| 459 | def device_enabled(target): |
| 460 | """Check if a target should be used when testing. |
| 461 | |
| 462 | It is recommended that you use :py:func:`tvm.testing.parametrize_targets` |
| 463 | instead of manually checking if a target is enabled. |
| 464 | |
| 465 | This allows the user to control which devices they are testing against. In |
| 466 | tests, this should be used to check if a device should be used when said |
| 467 | device is an optional part of the test. |
| 468 | |
| 469 | Parameters |
| 470 | ---------- |
| 471 | target : str or Dict[str, Any] or tvm.target.Target |
| 472 | Target string to check against |
| 473 | |
| 474 | Returns |
| 475 | ------- |
| 476 | bool |
| 477 | Whether or not the device associated with this target is enabled. |
| 478 | |
| 479 | Example |
| 480 | ------- |
| 481 | >>> @pytest.mark.gpu |
| 482 | >>> def test_mytest(): |
| 483 | >>> for target in ["cuda", "llvm"]: |
| 484 | >>> if device_enabled(target): |
| 485 | >>> test_body... |
| 486 | |
| 487 | Here, `test_body` will only be reached by with `target="cuda"` on gpu test |
| 488 | nodes and `target="llvm"` on cpu test nodes. |
| 489 | """ |
| 490 | if isinstance(target, dict): |
| 491 | target_kind = target["kind"] |
| 492 | elif hasattr(target, "kind"): |
| 493 | target_kind = target.kind.name |
| 494 | else: |
| 495 | assert isinstance(target, str), "device_enabled requires a target as a string" |
| 496 | # Target strings may include extra flags; only compare the kind. |
| 497 | target_kind = target.split(" ")[0] |
| 498 | return any(target_kind == t["target_kind"] for t in _get_targets() if t["is_runnable"]) |
| 499 | |
| 500 | |
| 501 | def enabled_targets(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…