【发布时间】:2021-09-16 07:48:30
【问题描述】:
我正在尝试在 WSL2 上运行一个带有 Cuda Thrust 函数的简单 c++ 程序。似乎程序在运行时无法分配设备内存。我一直将 Thrust 与 Microsoft Visual Studio 一起使用,没有出现任何错误。
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(proj LANGUAGES CXX CUDA)
add_executable(proj
proj.cu
)
proj.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
【问题讨论】:
-
WSL2 在一个实际上可能没有你的 GPU 的虚拟机中运行。因此 device_vector 将无法在 GPU 上分配内存 - 它在 WSL2 的上下文中不存在
-
您的 WSL2 实例是否甚至可以访问 GPU?尝试使用此处的代码检查您的设备属性developer.nvidia.com/blog/…
-
您没有在 WSL2 上正确设置 CUDA。见here。