Reputation: 175
template <typename T, std::size_t N>
void gpu_load(T (&data)[N])
{
cudaMalloc((void**)data, N*sizeof(T));
}
I call it like this:
float data[2];
gpu_load(data);
But it doesn't work. I guss it must be something with the & and points...
Upvotes: 0
Views: 436
Reputation: 29240
You can't just convert a pointer to a pointer to a pointer. data is of type T*
but cudaMalloc wants a void **
.
Try this:
cudaMalloc(static_cast<void**>(&d), N*sizeof(T));
Note the new ampersand.
Edit: added the static cast as suggested in the comments.
Upvotes: 1