【发布时间】:2017-09-11 19:35:09
【问题描述】:
每当我调用cudaMemPrefetchAsync() 时,它都会返回错误代码cudaErrorInvalidDevice。我确信我传递了正确的设备 ID(我的笔记本电脑中只有一个支持 CUDA 的 GPU 在id == 0 下)。
我相信下面发布的代码示例没有错误,但在52 行(致电cudaMemPrefetchAsync())我不断收到此错误。
我试过了:
- 干净的驱动程序安装。 (最新版本)
- 我在 Google 上查找答案,但找不到任何答案。 (我才找到this)
(其他的我还没想好)
系统规格:
操作系统: Microsoft windows 8.1 x64 主页。
IDE: Visual Studio 2015
CUDA 工具包: 8.0.61
NVIDIA GPU: GeForce GTX 960M
NVIDIA GPU 驱动程序: 版本 381.65(最新)
计算能力: 5.0 (Maxwell)
支持统一内存:。
英特尔集成 GPU: 英特尔高清显卡 4600
代码示例:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- INCLUDE:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Cuda Libs: ( Device Side ):
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
// Std C++ Libs:
#include <iostream>
#include <iomanip>
///////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- NAMESPACE:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
///////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- START POINT:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
// Set cuda Device:
if (cudaSetDevice(0) != cudaSuccess)
cout << "ERROR: cudaSetDevice(***)" << endl;
// Array:
unsigned int size = 1000;
double * d_ptr = nullptr;
// Allocate unified memory:
if (cudaMallocManaged(&d_ptr, size * sizeof(double), cudaMemAttachGlobal) != cudaSuccess)
cout << "ERROR: cudaMallocManaged(***)" << endl;
if (cudaDeviceSynchronize() != cudaSuccess)
cout << "ERROR: cudaDeviceSynchronize(***)" << endl;
// Prefetch:
if(cudaMemPrefetchAsync(d_ptr, size * sizeof(double), 0) != cudaSuccess)
cout << "ERROR: cudaMemPrefetchAsync(***)" << endl;
// Exit:
getchar();
}
///////////
【问题讨论】:
-
文档说设备的 cudaDevAttrConcurrentManagedAccess 属性必须非零。你检查过吗?
-
谢谢。你是对的,我错了。我的 GPU 不支持此功能。我仍然可以使用统一内存,但没有
cudaMemPrefetchAsync(***)。 -
请为您的问题添加简短答案
-
此 api 调用适用于 pascal GPU。您没有帕斯卡 GPU,无论如何调用都是多余的,因为在内核启动时pre-pascal UM will automatically migrate managed data to the GPU