how to use my existing .cpp code with cuda

后端 未结 3 415
情书的邮戳
情书的邮戳 2020-12-10 10:09

I hv code in c++ and wanted to use it along with cuda.Can anyone please help me? Should I provide my code?? Actually I tried doing so but I need some starting code to procee

3条回答
  •  忘掉有多难
    2020-12-10 10:42

    It's a non-trivial task to convert a program from straight C(++) to CUDA. As far as I know, it is possible to use C++ like stuff within CUDA (esp. with the announced CUDA 4.0), but I think it's easier to start with only C stuff (i.e. structs, pointers, elementary data types).

    Start by reading the CUDA programming guide and by examining the examples coming with the CUDA SDK or available here. I personally found the vector addition sample quite enlightening. It can be found over here.

    I can not tell you how to write your globals and shareds for your specific program, but after reading the introductory material, you will have at least a vague idea of how to do.

    The problem is that it is (as far as I know) not possible to tell a generic way of transforming pure C(++) into code suitable for CUDA. But here are some corner stones for you:

    • Central idea for CUDA: Loops can be transformed into different threads executed multiple times in parallel on the GPU.
    • Therefore, the single iterations optimally are independent of other iterations.
    • For optimal execution, the single execution branches of the threads should be (almost) the same, i.e. the single threads sould do almost the same.

提交回复
热议问题