2011-11-02 81 views
2

我有這樣的代碼在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);

我不知道這是什麼錯誤,你對此有任何想法?

回答

6

更改以下行:

unsigned int memory_total; 
unsigned int memory_free; 

到:

size_t memory_total; 
size_t memory_free; 

你可能想的是CUDA 3.0之前初步建成的舊代碼。

Source

+0

是的,它的工作原理。謝謝! – olidev

+0

當然,很高興幫助:) –

5

錯誤說size_tunsigned int是不同類型的,所以你不能一個指針傳遞給一個給需要的其他功能。

要麼改變的類型和memory_freememory_totalsize_t或使用臨時size_t變量然後將值複製到memory_freememory_total

P.S.你張貼的方式太多的源代碼,請儘量減少你的例子。

1

你不能同時定義

unsigned int memory_total; 
unsigned int memory_free; 

size_t memory_total; 
size_t memory_free; 
相關問題