如何解决WSL2 上的设备内存分配失败
我正在尝试在 WSL2 上运行一个带有 Cuda Thrust 函数的简单 C++ 程序。似乎程序在运行时无法分配设备内存。我一直在 Microsoft Visual Studio 中使用 Thrust,我没有遇到任何错误。
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(proj LANGUAGES CXX CUDA)
add_executable(proj
proj.cu
)
项目.cu:
#include<thrust/host_vector.h>
#include<thrust/device_vector.h>
#include<thrust/fill.h>
int main()
{
//thrust::host_vector<int> h_vec(10);
//thrust::fill(h_vec.begin(),h_vec.end(),1);
thrust::device_vector<int> d_vec(10);
//thrust::fill(d_vec.begin(),d_vec.end(),1);
return 1;
}
输出:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): get_max_shared_memory_per_block :Failed to cudaGetDevice: unkNown error
Aborted (core dumped)
如果我注释 device_vector 行,并改用宿主向量,它运行时不会出错。
附加信息:
- GeForce GTX 950M
- Windows 11 家庭版。构建 22000.51。
- WSL2:ubuntu-18.04
- Cuda 编译工具,9.1 版,V9.1.85
解决方法
在发帖之前,我已经看到了here中的说明,并且都下载并安装了WSL的CUDA驱动程序,并加入了windows Insider程序并升级到了windows 11 build。但它没有用。
但我也安装了 Ubuntu 18.04。我认为是安装了 Ubuntu 20.4 才使程序最终运行没有错误!
所以,这就是我为解决这个问题所做的:
-从 Microsoft 商店安装 Ubuntu 20.04(它要求我先下载并运行 WSL 修复程序,我做到了)
-在 powershell 中,我删除了 Ubuntu 18.04
wsl --unregister Ubuntu-18.04
将 Ubuntu-18.04 替换为您的发行版名称。您可以通过
在 powershell 中获取它的名称wsl --list
-已安装 cmake 和 g++-9(已安装 gcc-9)
-使用 here
中的说明下载了 cuda 工具包然后
cmake -DCMAKE_CUDA_COMPILER=/usr/local/cuda-11.0/bin/nvcc ..
make
./proj
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。