Skip to content

CUDA 与设备 — 练习 ​

Download exercise.py

  1. choose_device():有 CUDA 返回 cuda,否则 cpu。
  2. to_numpy_safe(t):detach().cpu().numpy()。
bash
cd docs/programming/cuda/code
python exercise.py

源码位置 ​

docs/programming/cuda/code/exercise.py