【发布时间】:2019-02-26 04:53:42
【问题描述】:
我在带有 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 的机器上进行了完全相同的实验,并且分析器确实显示了统一的内存信息。那台特定的计算机有问题吗?为了启用统一内存功能,我需要做任何与硬件相关的配置/设置吗?
【问题讨论】:
标签: memory cuda profiling nvidia