参数类型的“无符号整型*”是与类型的参数不兼容的“为size_t *”
问题描述:
我有这样的代码在CUDA与C++:参数类型的“无符号整型*”是与类型的参数不兼容的“为size_t *”
// Variables
float *query_dev;
float *ref_dev;
float *dist_dev;
int *ind_dev;
cudaArray *ref_array;
cudaError_t result;
size_t query_pitch;
size_t query_pitch_in_bytes;
size_t ref_pitch;
size_t ref_pitch_in_bytes;
size_t ind_pitch;
size_t ind_pitch_in_bytes;
size_t max_nb_query_traited;
size_t actual_nb_query_width;
unsigned int memory_total;
unsigned int memory_free;
// Check if we can use texture memory for reference points
unsigned int use_texture = (ref_width*size_of_float<=MAX_TEXTURE_WIDTH_IN_BYTES && height*size_of_float<=MAX_TEXTURE_HEIGHT_IN_BYTES);
// CUDA Initialisation
cuInit(0);
// Check free memory using driver API ; only (MAX_PART_OF_FREE_MEMORY_USED*100)% of memory will be used
CUcontext cuContext;
CUdevice cuDevice=0;
cuCtxCreate(&cuContext, 0, cuDevice);
cuMemGetInfo(&memory_free, &memory_total);
我得到一个错误为在该行编译:cuMemGetInfo(& memory_free,& memory_total);
的错误是:
app.cu(311): error: argument of type "unsigned int *" is incompatible with parameter of type "size_t *"
app.cu(311): error: argument of type "unsigned int *" is incompatible with parameter of type "size_t
311线:cuMemGetInfo(&memory_free, &memory_total);
我不知道这是什么错误,你对此有任何想法?
答
更改以下行:
unsigned int memory_total;
unsigned int memory_free;
到:
size_t memory_total;
size_t memory_free;
你可能想的是CUDA 3.0之前初步建成的旧代码。
答
错误说size_t
和unsigned int
是不同类型的,所以你不能一个指针传递给一个给需要的其他功能。
要么改变的类型和memory_free
memory_total
到size_t
或使用临时size_t
变量然后将值复制到memory_free
memory_total
和
P.S.你张贴的方式太多的源代码,请尽量减少你的例子。
答
你不能同时定义
unsigned int memory_total;
unsigned int memory_free;
为
size_t memory_total;
size_t memory_free;
是的,它的工作原理。谢谢! – olidev
当然,很高兴帮助:) –