CUDA:标识符"cudaMemGetInfo"未定义

Cal*_*han 3 cuda

为了估计程序在一次内核启动时可以处理多少数据,我尝试获取一些内存信息cudaMemGetInfo().但是,编译器告诉我这个:
错误:标识符"cudaMemGetInfo"未定义
其他函数如cudaGetDeviceProperties();工作正常.我是否必须安装某个CUDA版本?该库的描述不包含版本等相关信息.

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

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

int main(){
   unsigned int f, t;
   cudaSetDevice(0);
   cudaMemGetInfo(&f, &t);
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

编辑2:
我在Linux上使用"Cuda编译工具,版本2.0,V0.2.1221"(nvcc).
因为我试图安装cuda驱动程序版本cudaDriverGetVersion()时发生了同样的错误(当我使用驱动程序函数时同样的事情cuDriverGetVersion()).
系统似乎不会让我知道任何有关自身的细节......

tal*_*ies 7

对于您正在使用的旧版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;
}
Run Code Online (Sandbox Code Playgroud)

编辑:此答案适用于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;
}
Run Code Online (Sandbox Code Playgroud)

将在您的示例失败的地方工作.请注意,nvcc使用主机C++编译器来编译主机代码,并且它将找不到具有不正确参数的API函数的实例.请注意,cudaMemGetInfo的原型是

cudaError_t cudaMemGetInfo(size_t * free, size_t * total)       
Run Code Online (Sandbox Code Playgroud)

并且参数应该是size_t,这与unsigned int许多平台上的不同.