我在装有CUDA 9.2和Nvidia驱动程序(398.82-desktop-win10-64bit-international-whql)的Windows 10 64bit中安装了TitanXP,并且我有一个使用统一内存的简单程序,如下所示。
// CUDA kernel to add elements of two arrays
__global__
void add(int n, float *x, float *y)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < n; i += stride)
y[i] = x[i] + y[i];
}
int main(void)
{
int N = 1 << 20;
float *x, *y;
// Allocate Unified Memory -- accessible from CPU or GPU
cudaMallocManaged(&x, N * sizeof(float));
cudaMallocManaged(&y, N * sizeof(float));
// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
// Launch kernel on 1M elements on the GPU
int blockSize = 256;
int numBlocks = (N + blockSize - 1) / blockSize;
add <<< numBlocks, blockSize >>>(N, x, y);
// Wait for GPU to finish before accessing on host
cudaDeviceSynchronize();
// Check for errors (all values should be 3.0f)
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i] - 3.0f));
std::cout << "Max error: " << maxError << std::endl;
// Free memory
cudaFree(x);
cudaFree(y);
return 0;
}
我使用Visual Studio 2017社区编译此代码,然后在命令提示符窗口中运行它而没有错误。
当我在Nvidia Profiler中对其进行配置时,它会显示如下“警告”消息。
"==852== Warning: Unified Memory Profiling is not supported on the
current configuration because a pair of devices without peer-to-peer
support is detected on this multi-GPU setup. When peer mappings are
not available, system falls back to using zero-copy memory. It can
cause kernels, which access unified memory, to run slower. More
details can be found at:
http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-
managed-memory"
我很确定我的计算机中仅安装了一个GPU,为什么我无法获得统一的内存配置信息?
顺便说一句,我在另一台具有相同软件环境和GPU的机器上进行了完全相同的实验,并且探查器确实显示了统一的内存信息。那台特定的计算机有什么问题吗?我是否需要做任何与硬件相关的配置/设置才能启用统一内存功能?
答案 0 :(得分:1)
I had faced this problem in the past, but after updating my driver to the last version (Released in 19/9/2018 if am not mistaken) the problem resolved.
Hope it will resolve your problem as well. Let me know if it did.
答案 1 :(得分:1)
我安装了新的cuda sdk 10,现在可以正常工作了。