MCPcopy Index your code
hub / github.com/apache/tvm / device_enabled

Function device_enabled

python/tvm/testing/utils.py:459–498  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

457
458
459def 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
501def enabled_targets():

Callers

nothing calls this directly

Calls 3

_get_targetsFunction · 0.85
anyFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…