Skip to content

Commit 99db761

Browse files
committed
docs: add cross-platform device support section to README
1 parent c40ada2 commit 99db761

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,46 @@ profiler.export_perfetto("metal_trace.json")
410410
- Optional: Raw `.trace` file (use `--keep-trace`) for viewing in Instruments
411411
- Optional: Perfetto JSON export (use `--perfetto`)
412412

413+
#### Python Examples with Cross-Platform Device Support
414+
415+
All Python examples support multiple GPU platforms with automatic device detection:
416+
417+
```bash
418+
# Run examples on specific device
419+
python examples/basic_usage.py --device cuda # NVIDIA GPU
420+
python examples/basic_usage.py --device mps # Apple Silicon
421+
python examples/basic_usage.py --device rocm # AMD GPU
422+
python examples/basic_usage.py --device cpu # CPU fallback
423+
424+
# Run all examples with test runner
425+
python examples/run_tests.py # Best available device
426+
python examples/run_tests.py --all-devices # Test on all devices
427+
python examples/run_tests.py --test pytorch # Run specific test
428+
python examples/run_tests.py --list # List available tests
429+
```
430+
431+
**Using DeviceManager for cross-platform code:**
432+
433+
```python
434+
from examples.device_utils import DeviceManager, benchmark
435+
436+
# Auto-detect best device
437+
dm = DeviceManager() # or DeviceManager(prefer_device="mps")
438+
print(f"Using: {dm.get_device_name()}") # Apple Silicon GPU (mps:0, 25.2 GB)
439+
440+
# Create tensors on device
441+
x = dm.randn(1000, 1000)
442+
y = dm.randn(1000, 1000)
443+
444+
# Benchmark with proper synchronization
445+
results = benchmark(lambda: x @ y, warmup=3, iterations=10, dm=dm)
446+
print(f"Mean: {results['mean_ms']:.2f} ms")
447+
448+
# Device-agnostic operations
449+
dm.synchronize()
450+
print(f"Memory: {dm.memory_allocated() / 1024**2:.1f} MB")
451+
```
452+
413453
#### C++ API
414454

415455
```cpp

0 commit comments

Comments
 (0)