2

I am new to CUDA programming so I am curious as to how to do the following:

According to the question here: Using std::vector in cuda device code

we cannot use std::vector. I am trying to pass an argument like std::vector to a kernel. The void * describes memory pointers on the GPU/ device (cuda terminology).

What is the best way to do so? Maybe void ** ? will that work?

Community
  • 1
  • 1
Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
  • No I just wanted to be a little more specific about the problem I am trying to solve so I can get some sense on which is the way that makes most sense to input an array of void pointers. – Saher Ahwal Apr 27 '14 at 21:28

1 Answers1

2

That post seems clear but I'll repeat it in other words: you can't pass a std::vector to a CUDA kernel, the reason is the following:

  • CUDA kernels need to use device code, i.e. code that runs on your gpu or code that can be translated as such. In order to generate that code, almost everything you write needs to pass through a compilation chain which eventually generates intermediate code or executable code for your gpu.

  • By using STL constructs and algorithms you're using code that hasn't been written for the GPU and for which there's NO device equivalent code or emulation is slow/not even always possible.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • I completely understand that std runs on host. My question is what is the best way to input an array/vector of void pointers – Saher Ahwal Apr 27 '14 at 21:30
  • depending on what you need to do a pointer to an array of pointers might be a good choice (make sure to pass in the size of the array as well) or you might use thrust: http://docs.nvidia.com/cuda/thrust/#vectors Keep in mind that you're not actually using "code that runs on the host", that code might also be source-level but require other components not ported to the device or simply be unsupported code – Marco A. Apr 27 '14 at 21:36
  • so when you say array you mean `void **` a pointer to void pointer? – Saher Ahwal Apr 27 '14 at 21:46
  • yes, a pointer which points to the array of void pointers. Since an array decays (it has decayed functionalities) into a pointer we're talking about the same thing. – Marco A. Apr 27 '14 at 21:48