简体   繁体   中英

CUDA 6.5 (Cap 1.1) cudaMemcpy array of structs results in “invalid argument”

Code:

Octree_t* tarr = (Octree*)malloc(nodes * sizeof(Octree_t));
//nodearray[2]->test = 42;
for (int i = 0; i < cnodes; i++)
{
    tarr[i] = *nodearray[i];
}
//printf(" test: %d\n",tarr[2].test); //returns 42

cudaError_t err;
Octree_t*     gpu_nodearray;

//allocate storage on gpu
err = cudaMalloc( &gpu_nodearray, cnodes * sizeof(Octree_t) != cudaSuccess  );
if ( err != cudaSuccess)
{
    printf("1: %s\n", cudaGetErrorString(err));
    return;
}
err = cudaMemcpy(gpu_nodearray, tarr,  cnodes * sizeof(Octree_t), cudaMemcpyHostToDevice);
if ( err != cudaSuccess)
{
    printf("3: %s\n", cudaGetErrorString(err));
    return;
}

It compiles fine but when I run it, it returns "3: invalid argument". So clearly something is wrong with the cudaMempy. I already looked at similar posts here and I can't find the mistake I made.

Thanks for any help.

The line

err = cudaMalloc( &gpu_nodearray, cnodes * sizeof(Octree_t) != cudaSuccess  );

should be

err = cudaMalloc( &gpu_nodearray, cnodes * sizeof(Octree_t));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM