开发者

CUDA: identifier "cudaMemGetInfo" is undefined

开发者 https://www.devze.com 2023-04-04 11:12 出处:网络
To estimate how much data the program may process in one kernel launch i try to get some memory info with cudaMemGetInfo(). However, the compiler tells me this:

To estimate how much data the program may process in one kernel launch i try to get some memory info with cudaMemGetInfo(). However, the compiler tells me this:

error: identifier "cudaMemGetInfo" is undefined

Other functions like cudaGetDeviceProperties(); work fine. Do I have to install a certain CUDA-version? The library description does not contain infos about the version and so on.

EDIT: the smallest possible code. cudaSetDevice() generates no compiler error while cudaMemGetInfo() does

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

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

EDIT 2:

I'm on Linux using "Cuda compilation tools, release 2.0, V0.2.1221" (nvcc).

As I tried to get the cuda driver version installed with cudaDriverGetVersion() the same error occured (same thing when I use the driver function cuDriverGetVersion()).

开发者_Go百科 It seems that the system wont let me know any detail about itself...


For the very old version of CUDA you are using, cudaMemGetInfo is not part of the runtime API. It has a counterpart in the driver cuMemGetInfo, which can be used instead. Note that using the driver API version of this call will require establishing a context first. This should work on 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;
}

EDIT: this answer applied to CUDA 3.0 and later:

Your problem isn't cudaMemGetInfo, it is the arguments you are supplying it. I would predict that this:

// 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;
}

will work where your example fails. Note that nvcc uses a host C++ compiler to compile host code, and it will not find instances of API functions with incorrect arguments. Note that the prototype of cudaMemGetInfo is

cudaError_t cudaMemGetInfo(size_t * free, size_t * total)       

and that the arguments should be size_t, which is not the same as unsigned int on many platforms.


to fix this error:

error: argument of type "unsigned int *" is incompatible with parameter of type "size_t *".

I found from nvidia technical report for cuda 3.2 that: Driver API functions that accept or return memory sizes, such as cuMemAlloc() and cuMemGetInfo(), now use size_t for this purpose rather than unsigned int.

so you must change *.cu code, as the following lines:

Incorrect code: unsigned int free, total; cuMemGetInfo(&free, &total);

Correct code: size_t free, total; cuMemGetInfo(&free, &total);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号