MCPcopy
hub / github.com/tinygrad/tinygrad / enumerate_devices_str

Function enumerate_devices_str

tinygrad/device.py:351–374  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

349 launch_viz("PROFILE", fn)
350
351def enumerate_devices_str() -> Generator[str, None, None]:
352 from tinygrad import Tensor, Device
353
354 for device in ALL_DEVICES:
355 ren_results, iface_results = [], []
356 try:
357 d = Device[device]
358 for iface in [i for i in getattr(d, 'ifaces', []) if not i.__name__.startswith("MOCK")]:
359 try:
360 name = iface.__name__[:-5]
361 default_text, count = ("(default)", d.count()) if type(d.iface) is iface else (f"(DEV={name}+{device} to make default)", iface(d, 0).count) # type: ignore
362 iface_results.append(f"{colored('+', 'green')} {name}: {pluralize('device', count)} {default_text}")
363 except Exception as e: iface_results.append(f"{colored('-', 'red')} {iface.__name__[:-5]}: {e}")
364 for r in d.renderers:
365 try:
366 with Context(CACHELEVEL=0, DEV=f"{device}:{d._renderer_name(r)}"): test = (Tensor([1,2,3], device=device) * 2).tolist()
367 if test != [2,4,6]: raise ValueError(f"got {test} instead of [2, 4, 6]")
368 default_text = '(default)' if type(d.renderer) is r else f'(DEV={device}:{d._renderer_name(r)} to make default)'
369 ren_results.append(f"{colored('+', 'green')} {d._renderer_name(r)} {default_text}")
370 except Exception as e: ren_results.append(f"{colored('-', 'red')} {d._renderer_name(r)}: {e}")
371 result = (colored('PASS', 'green') + ("\n"+" "*12+"interfaces:\n" if iface_results else "") + '\n'.join([" "*13+x for x in iface_results]) +
372 (("\n"+" "*12+"renderers:\n") + '\n'.join([" "*13+x for x in ren_results]) if len(ren_results) > 1 else ""))
373 except Exception as e: result = f"{colored('FAIL', 'red')} {e}"
374 yield f"{'*' if device == Device.DEFAULT else ' '} {device:8s}: {result}"
375
376if __name__ == "__main__":
377 for s in enumerate_devices_str(): print(s)

Callers 2

test_module_runsMethod · 0.90
device.pyFile · 0.85

Calls 8

coloredFunction · 0.90
pluralizeFunction · 0.90
ContextClass · 0.90
TensorClass · 0.90
appendMethod · 0.80
_renderer_nameMethod · 0.80
countMethod · 0.45
tolistMethod · 0.45

Tested by 1

test_module_runsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…