First I initialize my Wrapper struct (host) and then copy it over to my device:
Wrapper wrapperHost;
// initialize the arrays (fill data arrays with '5.0f')and other related stuff
COMPUTE_SAFE(cudaMemcpyToSymbol(wrapperDevice, &wrapperHost, sizeof(Wrapper))); // Works fine
When I run my kernel I get a memory access violation error, which is expected since the data pointers point to host memory (I think) - now my question is: how can I copy the Wrapper struct with its arrays over to my device?
Thanks in advance, also note that this was written in-browser, so there’s a good chance that there are typos/minor errors in the code examples.
An alternative that does not require deep copies is to use Managed memory for any data structure you need to access on the GPU. Then the CPU and GPU share the same address space, and the driver handles copying of data chunks between host and device on an as-needed basis. Deep copying won’t be needed as pointers remain valid.
This solution may require the use of custom allocators for non-POD objects.
hey, I know this isn’t really related to the question, but would you mind showing me a way of copying the data back from the symbol to host? I’ve been trying to do it myself, but I’m having trouble getting it working.
This is one of my attempts at making it work (I’m also copying only 1 array for now):