测试环境
测试代码:
import numpy as np
from mindspore import Tensor
from mindspore.ops import functional as F
import mindspore.context as context
context.set_context(device_target="GPU")
x = Tensor(np.ones([1,3,3,4]).astype(np.float32))
y = Tensor(np.ones([1,3,3,4]).astype(np.float32))
print(F.tensor_add(x, y))
1.1 ImportError: libcudart.so.10.1: cannot open shared object file: No such file or directory
解决方法:
1.首先通过:conda list 确认是否安装 cudatoolkit=10.1
如果没有的话,执行: conda install cudatoolkit=10.1 cudnn=7
2.增加 LD_LIBRARY_PATH:
先通过: which python 确定当前conda环境路径,笔者的输出:/root/miniconda3/envs/tf2c/bin/python
在增加LD_LIBRARY_PATH:export LD_LIBRARY_PATH="/root/miniconda3/envs/tf2c/lib"
此时第一个问题就解决了
1.2 OSError: MindSpore version 1.0.0 and cuda version 10.2 does not match, reference to the match info on: https://www.mindspore.cn/install
详细错误信息为:
Traceback (most recent call last):
File "test_img.py", line 5, in <module>
from mindspore import Tensor
File "/root/miniconda3/envs/tf2c/lib/python3.7/site-packages/mindspore/__init__.py", line 17, in <module>
from ._version_check import check_version_and_env_config
File "/root/miniconda3/envs/tf2c/lib/python3.7/site-packages/mindspore/_version_check.py", line 256, in <module>
check_version_and_env_config()
File "/root/miniconda3/envs/tf2c/lib/python3.7/site-packages/mindspore/_version_check.py", line 250, in check_version_and_env_config
env_checker.check_version()
File "/root/miniconda3/envs/tf2c/lib/python3.7/site-packages/mindspore/_version_check.py", line 95, in check_version
raise EnvironmentError(f"MindSpore version {__version__} and cuda version {v_str} does not match, "
OSError: MindSpore version 1.0.0 and cuda version 10.2 does not match, reference to the match info on: https://www.mindspore.cn/install
解决方法:修改 /root/miniconda3/envs/tf2c/lib/python3.7/site-packages/mindspore/_version_check.py 文件
注释一下几行:
"""
if v_str not in self.version:
raise EnvironmentError(f"MindSpore version {__version__} and cuda version {v_str} does not match, "
"reference to the match info on: https://www.mindspore.cn/install")
"""
问题解决。执行代码,输出:
[[[[2. 2. 2. 2.]
[2. 2. 2. 2.]
[2. 2. 2. 2.]]
[[2. 2. 2. 2.]
[2. 2. 2. 2.]
[2. 2. 2. 2.]]
[[2. 2. 2. 2.]