Seg fault on cudaMemcpy

Hi all,

I have been having a problem with segfaults in my code. It generally seems to be some problem with the size of arrays. However from doing deviceQuery, the maximum memory allowed on my card (K1200) is 4038 MB. The arrays are both 4,655,695 elements long, so 4,655,695 x 1 + 4,655,695 x 4 for the char and int means they use up 23278475 bytes (~23 MB) so there shouldn’t be a problem in the the cudaMemcpy due to size, should there?

I couldn’t find anything that said so, but does it matter that my global values are on the heap instead of the stack?

The pertinent part of the code is below, I can add in cuda-memcheck/valgrind information, too. Although nothing stood out:

int total_amino_acids = 4655695;

char *subsequences_char = new char [total_amino_acids];
int  *look_up_table     = new int  [total_amino_acids];

char  *d_subsequences_char;
int   *d_look_up_table;

cudaMalloc(&d_subsequences_char, total_amino_acids * sizeof(char));
cudaMalloc(&d_look_up_table,     total_amino_acids * sizeof(int));

cudaMemcpy((void **)d_subsequences_char, &subsequences_char, total_amino_acids * sizeof(char),  cudaMemcpyHostToDevice);
cudaMemcpy((void **)d_look_up_table,     &look_up_table,     total_amino_acids * sizeof(int),   cudaMemcpyHostToDevice);

Apologies in advance if it’s something stupid, I’m a total beginner to CUDA and pretty new to C/C++. Is there a known common cause to a problem like this? Thanks

cudaMemcpy((void **)d_subsequences_char, &subsequences_char, total_amino_acids * sizeof(char),  cudaMemcpyHostToDevice);
cudaMemcpy((void **)d_look_up_table,     &look_up_table,     total_amino_acids * sizeof(int),   cudaMemcpyHostToDevice);

should be:

cudaMemcpy(d_subsequences_char, subsequences_char, total_amino_acids * sizeof(char), cudaMemcpyHostToDevice);
cudaMemcpy(d_look_up_table,     look_up_table,     total_amino_acids * sizeof(int),   cudaMemcpyHostToDevice);

Thank you for that, I appreciate the help. Why is it that you pass them in differently, if they are the same structure just in a different part of memory? Or have I totally missed the point?

you declared:

char *subsequences_char = new char [total_amino_acids];
char *d_subsequences_char;

so, these 2 variables are same type(char*).

you called:

cudaMemcpy((void **)d_subsequences_char, &subsequences_char, total_amino_acids * sizeof(char),  cudaMemcpyHostToDevice);

cudaMemcpy required 2 pointer(source & destination)
but you specified pointer and pointer-to-pointer.