Hi there,
I’m having trouble copying data to the device.
I have a small test program that I’m trying to port in order
to run on a GPU. Half of the program generates a random
data file ([font=“Courier New”]400MB[/font]) with a pattern inserted often.
The reader-half of the program, reads through the data
file and uses [font=“Courier New”]memcmp[/font] to search for the pattern in each
page it reads in.
I copied the [font=“Courier New”]memcmp[/font] routine (and properly attributed it)
so that it is a [font=“Courier New”]device[/font] routine, under a different name.
I read in a page (4096 bytes) into an appropriately sized
array and attempt to copy it over. Each page has 32 records,
sized 128 bytes each.
#define TARGET_PATTERN "kevin"
...
bytes_read = fread( h_page_buffer, 1, parameters->page_size, input_file);
...
char* d_page_buffer;
char h_pattern[] = TARGET_PATTERN;
char* d_pattern;
cudaMalloc( &d_page_buffer, buf_sz );
cudaMalloc( &d_pattern, strlen(TARGET_PATTERN) * sizeof(char) );
cudaMemcpy( d_page_buffer, h_page_buffer, buf_sz, cudaMemcpyHostToDevice );
cudaMemcpy( d_pattern, h_pattern, strlen(TARGET_PATTERN) * sizeof(char), cudaMemcpyHostToDevice );
compare<<< 1, num_records_per_page >>>( d_page_buffer, ... , d_pattern );
I have a shared variable that’s used to track how many
matches have been found, but the count is zero.
Stepping through, using [font=“Courier New”]cuda-gdb[/font], I see
compare (__cuda_0=0x100100 "(", __cuda_1=0x100000, __cuda_2=128, __cuda_3=5, __cuda_4=0x100200 "?
compare (__cuda_0=0x100100 “(”, __cuda_1=0x100000, __cuda_2=128, __cuda_3=5, __cuda_4=0x100200 “?\001\020”)
01
compare (__cuda_0=0x100100 “(”, __cuda_1=0x100000, __cuda_2=128, __cuda_3=5, __cuda_4=0x100200 “?\001\020”)
20")
which confuses me, beyond showing me that I’m doing
something incorrectly.
At the minimum, I expected the value of [font=“Courier New”]__cuda_4[/font] to be
[font=“Courier New”]“kevin”[/font], not [font=“Courier New”]“?\001\020”[/font].
[font=“Courier New”]__cuda_0[/font] also appears incorrect. Using a hex editor, I can
see that the first record’s ASCII representation is (ignore
line breaks)
kom"XV*t']nKVXU5cKB&AUSeR]Gtd=u4Huf5-7_I?$; _MZ9n[]m\^N":0|[2LUZ-;/h2c@Yq}Sx'2wI_Ta97_3*]@(%_^.TDmj&{?S0YFis\lk_Q+_P6i*6_I?kevin
I’m not sure why[font=“Courier New”] __cuda_0[/font]'s value is a single character, [font=“Courier New”]“)”[/font].
I believe these are the reasons I can’t find a match.
Could anyone help point out any errors or help with guidance?
Am I missing something regarding preserving values or not
copying them properly?
Thanks in advance.