0
class A 
{
  B *b;
}

Supose that I have an array of elements of Class A, and I want to send them to a CUDA kernel! Without the pointer inside it would be trivial, because I'll just need to call

cudaMalloc(&arrayA, sizeof(A) * numberof A elements).

In this situation if I just call cudaMalloc, what happens to memory pointed by *b pointer? It remains as a pointer to Host memory? I searched that I could pin memory on the host and access to it from the device, is it viable to pin *b pointed memory and access it from device (Access times)? Or if I should copy the entire b object to device memory and make *b as a reference to device memory?

talonmies
  • 70,661
  • 34
  • 192
  • 269
sheepCow
  • 99
  • 1
  • 3
  • 11
  • you should copy the object indeed, have you any good reason of not doing it ? – Guiroux Apr 04 '16 at 11:25
  • I should copy the b object inside A object to device memory? I have nearly one million A objects! – sheepCow Apr 04 '16 at 11:38
  • is your B object distinct for every A object ? And what's a A object size compared to a B object size ? – Guiroux Apr 04 '16 at 11:42
  • B object is distinct for every A object! B object is 4 times larger – sheepCow Apr 04 '16 at 11:49
  • 2
    If B is conceptually a part of A, why is it a pointeur ? and not agregation ? Moreover, why is it ok to copy A to host, but not B ? ( I know I'm not answering your question here, but the understanding of WHY you need to do this is very important in order to give you an answer ) – Guiroux Apr 04 '16 at 11:55
  • I think you are right! I could just agreate B object to A! But what will happen in this case if I just allocate A on device? Does b remains as a pointer to host? Thanks for the answer – sheepCow Apr 04 '16 at 12:19
  • well, you can't just use directly the original pointer to get to B on the host from the device, but I think that there's a system to request a virtual CUDA address which can be accessed from both HOST and device, but not directly using the original pointer, but for this I'll let someone with more knowledge answer (and YES it was your original question, but sometimes, the answer is to do otherwise because it would make more sense rather than adressing the technical problem directly) – Guiroux Apr 04 '16 at 12:27
  • look into CUDA Unified Virtual Addressing – Guiroux Apr 04 '16 at 12:31
  • seems that this http://stackoverflow.com/questions/29013903/confusion-about-cuda-unified-virtual-memory could be interesting – Guiroux Apr 04 '16 at 12:40
  • Thank you all for helping me! – sheepCow Apr 04 '16 at 15:02

0 Answers0