问题描述
使用香橙派 aipro 20t,运行pytorch程序,无法正确调用AI Core,只能调用cpu。
软件环境
操作系统
镜像为 opiaipro_20t_ubuntu22.04_desktop_aarch64_20240924.img
基础软件包
Ascend-cann-kernels-310b_7.0.0_linux.run
Ascend-cann-toolkit_7.0.0_linux-aarch64.run
Ascend-hdk-310b-npu-driver-soc_23.0.0_linux-aarch64-opiaipro-20t.run
Ascend310B-firmware-7.3.t7.0.b507-rc-signed-20t-1.6ghz-20240910.run
torch_npu-2.1.0.post2+git64bdab5-cp39-cp39-linux_aarch64.whl
python及pytorch版本
python 3.9.2 pytorch 2.1.0 torch_npu使用的是 torch_npu-2.1.0.post2+git64bdab5-cp39-cp39-linux_aarch64.whl
程序代码
运行结果
如果改用cpu运行大约在3秒左右,显然是没有调用AI Core。也用npu-smi info watch命令观察过,确定程序只使用了cpu。
问题描述
使用香橙派 aipro 20t,运行pytorch程序,无法正确调用AI Core,只能调用cpu。
软件环境
操作系统
镜像为 opiaipro_20t_ubuntu22.04_desktop_aarch64_20240924.img
基础软件包
Ascend-cann-kernels-310b_7.0.0_linux.run
Ascend-cann-toolkit_7.0.0_linux-aarch64.run
Ascend-hdk-310b-npu-driver-soc_23.0.0_linux-aarch64-opiaipro-20t.run
Ascend310B-firmware-7.3.t7.0.b507-rc-signed-20t-1.6ghz-20240910.run
torch_npu-2.1.0.post2+git64bdab5-cp39-cp39-linux_aarch64.whl
python及pytorch版本
python 3.9.2 pytorch 2.1.0 torch_npu使用的是 torch_npu-2.1.0.post2+git64bdab5-cp39-cp39-linux_aarch64.whl
程序代码
import torch import torch_npu import time print(torch_npu.npu.is_available()) torch_npu.npu.set_device(0) start_time = time.perf_counter() device = torch.device("npu" if torch_npu.npu.is_available() else "cpu") print("using device:", device) x = torch.randn(2, 2).npu() y = torch.randn(2, 2).npu() z = x.mm(y) print(z) end_time = time.perf_counter() duration_ms = (end_time - start_time) * 1000 print(f"Duration: {duration_ms:.3f} ms")运行结果
python npu.py /home/HwHiAiUser/.local/lib/python3.9/site-packages/torch_npu/dynamo/__init__.py:18: UserWarning: Register eager implementation for the 'npu' backend of dynamo, as torch_npu was not compiled with torchair. warnings.warn( True using device: npu Warning: Device do not support double dtype now, dtype cast repalce with float. tensor([[-0.0325, 1.3582], [-1.0262, -1.6385]], device='npu:0') Duration: 11189.677 ms如果改用cpu运行大约在3秒左右,显然是没有调用AI Core。也用npu-smi info watch命令观察过,确定程序只使用了cpu。