Eluri
November 11, 2009, 8:21pm
1
Hi, when I try to run my test-program, I get a fault (invalid argument) in the line:
cutilSafeCall( cudaMemcpyToArray( cu_array, 0, 0, arr, size, cudaMemcpyHostToDevice));
Relevant part of the program:
int main(int argc, char** argv)
{
const int rows = 5;
const int columns = 5;
unsigned int size = rows * columns * sizeof(double);
//Initiate 2d array :
double **arr = (double**)malloc(rows * sizeof(*arr));
for(int i = 0; i < rows; ++i)
{
arr[i] = (double*)malloc(columns * sizeof(*arr[0]));
}
for(int i = 0; i < rows; ++i)
{ for(int j = 0; j < columns; ++j)
{ arr[i][j] = i*j+j;
printf("%lf\n", arr[i][j]);
}
}
// allocate array and copy data
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaArray* cu_array;
cutilSafeCall( cudaMallocArray( &cu_array, &channelDesc, columns, rows ));
cutilSafeCall( cudaMemcpyToArray( cu_array, 0, 0, arr, size, cudaMemcpyHostToDevice));
}
Does anyone see per chance what I do wrong?
Thanks
Did you ever get an answer? I’m having the same problem.
I get an invalid argument when I call cudaMemcpyToArray.
I have an idea of what might be causing your problem, although it’s just a guess.
You might try passing in arr instead of arr which is a double *.
I think the function calls for a const void * in that argument.
Hi, when I try to run my test-program, I get a fault (invalid argument) in the line:
cutilSafeCall( cudaMemcpyToArray( cu_array, 0, 0, arr, size, cudaMemcpyHostToDevice));
Relevant part of the program:
int main(int argc, char** argv)
{
const int rows = 5;
const int columns = 5;
unsigned int size = rows * columns * sizeof(double);
//Initiate 2d array :
double **arr = (double**)malloc(rows * sizeof(*arr));
for(int i = 0; i < rows; ++i)
{
arr[i] = (double*)malloc(columns * sizeof(*arr[0]));
}
for(int i = 0; i < rows; ++i)
{ for(int j = 0; j < columns; ++j)
{ arr[i][j] = i*j+j;
printf("%lf\n", arr[i][j]);
}
}
// allocate array and copy data
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaArray* cu_array;
cutilSafeCall( cudaMallocArray( &cu_array, &channelDesc, columns, rows ));
cutilSafeCall( cudaMemcpyToArray( cu_array, 0, 0, arr, size, cudaMemcpyHostToDevice));
}
Does anyone see per chance what I do wrong?
Thanks
Because you used cudaChannelFormatKindFloat option, you should use float type instead of double type. Replacing the double data type with float, you can solve this problem.