Problems with pointer inside of struct

Hi,

the following problem was encountered:

Scenario:

  • struct A, which contains a pointer to another struct B array
  • cudaMalloc for both structs A and B
  • cudaMemcpy for both structs A and B
  • cudaMemcpy to assign the pointer from struct B to struct A on the GPU
  • everything remains in global memory

Problem:

  • running the program produces wrong results when accessing the memory of struct B array through the pointer contained in struct A
  • for debugging purposes the pointer to struct B array returned by cudaMalloc is passed in addition to the pointer to struct A into the kernel
  • debugging with cuda-gdb reveals:
    [indent]- address of the struct B passed directly to the kernel is identical to the one stored in struct A
  • accessing the memory region of struct B through the pointer in struct A fails (i.e. produces garbage values, though cuda-gdb displays the layout of struct B correctly. So it must know with what kind of struct it deals)
  • accessing the memory region of struct B through the pointer to struct B, which is directly passed to the kernel, works[/indent]

The System:

  • Ubuntu 64bit 10.04
  • Kernel: 2.6.32-26-generic
  • Nvidia driver version: 260.19.29
  • SDK: 3.2.16

The main questions:

  • Why does an access of the same memory through identical addresses produce different results depending on where the pointers are stored?
  • Is this a known issue?

Hopefully, this information is enough. Posting of code might be possible, though the current working version of the code uses two separate pointers and it is unlikely that it will be changed back to the nested version. Nevertheless it would be much appreciated if someone can shed some light on this topic as it is strange nevertheless.

Thx & Greetings

supposing that struct A is like this:

struct A{

  int some_values;

  float some_floats;

  B *b_pointer;

};

for debuging reasons, i would try to do almost the same steps with a small difference:

a) make a A *d_structA variable;

b) cudaMalloc for d_structA and then cudaMalloc for d_structA->B pointer.

c) cudamemcpy from h_structA to d_structA, and from h_structA->B to d_structA->B. (instead of having another B struct apart)

d) test

it looks very similar to what you did, you could tell us what is the behaveiour.

the error looks very strange, could be a small detail or a very deep concept thing related to the architecture.

Thanks for your reply. I am currently busy with other stuff. I will do the test as soon as I find some time and post the result.