gpt4 book ai didi

CUDA:标识符 "cudaMemGetInfo"未定义

转载 作者:行者123 更新时间:2023-12-04 16:45:33 34 4
gpt4 key购买 nike

为了估计程序在一次内核启动中可以处理多少数据,我尝试使用 cudaMemGetInfo() 获取一些内存信息。但是,编译器告诉我:
错误:标识符“cudaMemGetInfo”未定义
cudaGetDeviceProperties(); 等其他函数工作正常。我必须安装某个 CUDA 版本吗? library description不包含版本等信息。

编辑:尽可能小的代码。 cudaSetDevice() 不会产生编译器错误,而 cudaMemGetInfo() 会产生

#include <cuda.h>
#include <cuda_runtime_api.h>

int main(){
unsigned int f, t;
cudaSetDevice(0);
cudaMemGetInfo(&f, &t);
return 0;
}

编辑 2:
我在 Linux 上使用“Cuda 编译工具,版本 2.0,V0.2.1221”(nvcc)。
当我尝试使用 cudaDriverGetVersion() 安装 cuda 驱动程序版本时,发生了同样的错误(当我使用驱动程序函数 cuDriverGetVersion() 时也是如此)。
好像系统不会让我知道任何关于它自己的细节...

最佳答案

对于您使用的非常旧版本的 CUDA,cudaMemGetInfo 不是运行时 API 的一部分。它在驱动程序 cuMemGetInfo 中有一个对应项,可以使用它来代替。请注意,使用此调用的驱动程序 API 版本需要先建立上下文。这应该适用于 CUDA 2.x:

// CUDA 2.x version
#include <cstdio>
#include <cuda.h>
#include <cuda_runtime_api.h>

int main(){
unsigned int f, t;
cudaSetDevice(0);
cudaFree(0); // This will establish a context on the device
cuMemGetInfo(&f, &t);
fprintf(stdout,"%d %d\n",f/1024,t/1024);
return 0;
}

编辑:此答案适用于 CUDA 3.0 及更高版本:

您的问题不是 cudaMemGetInfo,而是您提供的参数。我会预测:

// CUDA 3.0 or later version
#include <cuda.h>
#include <cuda_runtime_api.h>

int main(){
size_t f, t;
cudaSetDevice(0);
cudaMemGetInfo(&f, &t);
return 0;
}

将在您的示例失败的地方工作。请注意,nvcc 使用主机 C++ 编译器来编译主机代码,它不会找到带有错误参数的 API 函数实例。注意 cudaMemGetInfo 的原型(prototype)是

cudaError_t cudaMemGetInfo(size_t * free, size_t * total)       

而且参数应该是size_t,在很多平台上和unsigned int是不一样的。

关于CUDA:标识符 "cudaMemGetInfo"未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7386990/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com