"""只检查 GPU Paddle 环境,不加载 OCR 模型。""" import sys def main() -> int: try: import paddle except ImportError: print("[ERROR] 未安装 PaddlePaddle GPU。请先运行 setup_env.py。") return 1 print(f"Python: {sys.version.split()[0]}") print(f"PaddlePaddle: {paddle.__version__}") print(f"CUDA build: {paddle.is_compiled_with_cuda()}") if not paddle.is_compiled_with_cuda(): print("[ERROR] 当前安装的 PaddlePaddle 不是 CUDA 版本。") return 2 try: device_count = paddle.device.cuda.device_count() except Exception as exc: print(f"[ERROR] 无法查询 CUDA 设备: {exc}") return 3 print(f"CUDA device count: {device_count}") if device_count < 1: print("[ERROR] 未检测到可用的 NVIDIA CUDA GPU。") return 4 for device_id in range(device_count): try: name = paddle.device.cuda.get_device_name(device_id) except Exception: name = "unknown" print(f"GPU {device_id}: {name}") try: paddle.set_device("gpu:0") tensor = paddle.ones([1024, 1024], dtype="float32") result = paddle.matmul(tensor, tensor) paddle.device.cuda.synchronize() print(f"CUDA smoke test: OK, result shape={list(result.shape)}") except Exception as exc: print(f"[ERROR] CUDA 计算测试失败: {exc}") return 5 return 0 if __name__ == "__main__": raise SystemExit(main())