Is there any example for passing a map array to a cuda kernel? #493
-
I have several hash maps to pass them into kernel. Is there any example to show how can I combine them into a vector or a array and them pass it into cuda kernel. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @wangzilu, There are multiple ways to achieve this. I just put together a simple example here. The downside of this approach is that each map will allocate its own storage, which can lead to overheads during allocation/initialization (plain |
Beta Was this translation helpful? Give feedback.
Hi @wangzilu,
There are multiple ways to achieve this. I just put together a simple example here.
The idea is to emplace the map objects into a host vector and then create non-owning reference objects for each map that can be placed into a device vector and then later be used in the kernel.
The downside of this approach is that each map will allocate its own storage, which can lead to overheads during allocation/initialization (plain
cudaMalloc
is a blocking operation).Instead, it is also possible to allocate a single storage array first and then subdivide it into multiple maps.
This approach is a bit more complex. We have an example here.