Beispiel #1
0
Datei: utils.py Projekt: were/tvm
def _get_targets(target_str=None):
    if target_str is None:
        target_str = os.environ.get("TVM_TEST_TARGETS", "")
        # Use dict instead of set for de-duplication so that the
        # targets stay in the order specified.
        target_names = list(
            {t.strip(): None
             for t in target_str.split(";") if t.strip()})

    if not target_names:
        target_names = DEFAULT_TEST_TARGETS

    targets = []
    for target in target_names:
        target_kind = target.split()[0]

        if target_kind == "cuda" and "cudnn" in tvm.target.Target(
                target).attrs.get("libs", []):
            is_enabled = tvm.support.libinfo()["USE_CUDNN"].lower() in [
                "on", "true", "1"
            ]
            is_runnable = is_enabled and cudnn.exists()
        elif target_kind == "hexagon":
            is_enabled = tvm.support.libinfo()["USE_HEXAGON"].lower() in [
                "on", "true", "1"
            ]
            # If Hexagon has compile-time support, we can always fall back
            is_runnable = is_enabled and "ANDROID_SERIAL_NUMBER" in os.environ
        else:
            is_enabled = tvm.runtime.enabled(target_kind)
            is_runnable = is_enabled and tvm.device(target_kind).exist

        targets.append({
            "target": target,
            "target_kind": target_kind,
            "is_enabled": is_enabled,
            "is_runnable": is_runnable,
        })

    if all(not t["is_runnable"] for t in targets):
        if tvm.runtime.enabled("llvm"):
            logging.warning(
                "None of the following targets are supported by this build of TVM: %s."
                " Try setting TVM_TEST_TARGETS to a supported target. Defaulting to llvm.",
                target_str,
            )
            return _get_targets("llvm")

        raise TVMError(
            "None of the following targets are supported by this build of TVM: %s."
            " Try setting TVM_TEST_TARGETS to a supported target."
            " Cannot default to llvm, as it is not enabled." % target_str)

    return targets
Beispiel #2
0
def _get_targets(target_str=None):
    if target_str is None:
        target_str = os.environ.get("TVM_TEST_TARGETS", "")
        # Use dict instead of set for de-duplication so that the
        # targets stay in the order specified.
        target_names = list({t.strip(): None for t in target_str.split(";") if t.strip()})

    if not target_names:
        target_names = DEFAULT_TEST_TARGETS

    targets = []
    for target in target_names:
        target_kind = target.split()[0]
        is_enabled = tvm.runtime.enabled(target_kind)
        is_runnable = is_enabled and tvm.device(target_kind).exist
        targets.append(
            {
                "target": target,
                "target_kind": target_kind,
                "is_enabled": is_enabled,
                "is_runnable": is_runnable,
            }
        )

    if all(not t["is_runnable"] for t in targets):
        if tvm.runtime.enabled("llvm"):
            logging.warning(
                "None of the following targets are supported by this build of TVM: %s."
                " Try setting TVM_TEST_TARGETS to a supported target. Defaulting to llvm.",
                target_str,
            )
            return _get_targets("llvm")

        raise TVMError(
            "None of the following targets are supported by this build of TVM: %s."
            " Try setting TVM_TEST_TARGETS to a supported target."
            " Cannot default to llvm, as it is not enabled." % target_str
        )

    return targets
Beispiel #3
0
def _get_targets(target_str=None):
    if target_str is None:
        target_str = os.environ.get("TVM_TEST_TARGETS", "")

    if len(target_str) == 0:
        target_str = DEFAULT_TEST_TARGETS

    target_names = set(t.strip() for t in target_str.split(";") if t.strip())

    targets = []
    for target in target_names:
        target_kind = target.split()[0]
        is_enabled = tvm.runtime.enabled(target_kind)
        is_runnable = is_enabled and tvm.device(target_kind).exist
        targets.append({
            "target": target,
            "target_kind": target_kind,
            "is_enabled": is_enabled,
            "is_runnable": is_runnable,
        })

    if all(not t["is_runnable"] for t in targets):
        if tvm.runtime.enabled("llvm"):
            logging.warning(
                "None of the following targets are supported by this build of TVM: %s."
                " Try setting TVM_TEST_TARGETS to a supported target. Defaulting to llvm.",
                target_str,
            )
            return _get_targets("llvm")

        raise TVMError(
            "None of the following targets are supported by this build of TVM: %s."
            " Try setting TVM_TEST_TARGETS to a supported target."
            " Cannot default to llvm, as it is not enabled." % target_str)

    return targets