Files
mlc-ai--mlc-llm/python/mlc_llm/cli/check_device.py
T
wehub-resource-sync 770d92cb1f
Lint / lint (push) Has been cancelled
Build Docs / Deploy Docs (push) Has been cancelled
Windows CI / Windows (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:23:58 +08:00

35 lines
726 B
Python

"""Check if a device exists."""
import os
import sys
from tvm.runtime import Device
from tvm.runtime import device as as_device
def _check_device(device: Device) -> bool:
try:
return bool(device.exist)
except Exception:
return False
def main():
"""Entrypoint for device check."""
device_str = sys.argv[1]
device_ids = []
i = 0
while True:
if _check_device(as_device(device_str, i)):
device_ids.append(i)
i += 1
if device_str in ["cpu", "llvm"] and i > os.cpu_count() / 2:
break
else:
break
print(f"check_device:{','.join(str(i) for i in device_ids)}")
if __name__ == "__main__":
main()