c++ - Cuda Thrust memory management -


i wrote code below:

 unsigned int* addrarray = (unsigned int*)malloc(sizeof(unsigned int)*datasetrows);  thrust::exclusive_scan(binarydataset,binarydataset+(sizeof(unsigned int)*datasetrows),addrarray);  free(addrarray); 

binarydataset unsigned int* type , have no problems allocating, processing data in part of memory , freeing it. addrarray causes problems. aftter running program following error:

*** glibc detected *** ./prog: free(): invalid next size (normal): 0x000000000180be10 *** , memory map.

this code wont generate error when use cudafree(addrarray) instead, later cause segmentation fault or glibc malloc memory corruption problem. example running this:

unsigned int* addrarray = (unsigned int*)malloc(sizeof(unsigned int)*datasetrows); thrust::exclusive_scan(binarydataset,binarydataset+(sizeof(unsigned int)*datasetrows),addrarray); const unsigned int compactarraysize = addrarray[datasetrows-1] - 1; printf("%u\n",compactarraysize) float* compactminorclass = (float*)malloc(sizeof(float)*datasetcols*compactarraysize); 

will generate segmentation fault when trying malloc memory on compactminorclass pointer(printf gives correct output, prefixsum calculated correctly , output saved in addrarray should be). build program set flags g++ , nvcc following:

gxxflags:= -o3 -wall -wextra -m64 -std=c++0x

nvccflags:= -xcompiler -wall -xcompiler -wextra -m64 -arch=sm_11

(i have geforce310m have set sm_11) question why running thrust function generates errors, why can't free memory allocated on host using free() ?

this not correct:

thrust::exclusive_scan(binarydataset,binarydataset+(sizeof(unsigned int)*datasetrows),addrarray); 

try instead:

thrust::exclusive_scan(binarydataset,binarydataset+(datasetrows),addrarray); 

the intention here pointer arithmetic, not byte arithmetic. , likewise in second code sample.

i'm not sure it's idea specify:

-std=c++0x 

but don't know sure it's source of of problems.

you should not cudafree on ordinary host pointer.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -