将所有CUDA功能更改为__host__ __device__ [英] Change all CUDA functions to __host__ __device__

查看:357
本文介绍了将所有CUDA功能更改为__host__ __device__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CUDA中使用一个现存函数,但是它包含许多类和其他函数。
在每个函数都很简单之前添加 __ host__ __device __ 。那么,是否有自动方法可以做到这一点?还是如何让nvcc将所有功能编译为 __ device__ __host __

I want to use an exist function in CUDA, but it contains many class and other functions. Adding __host__ __device__ before every function is trivial. So, is there an automatic method to do this? Or how to let nvcc compile all functions as __device__ __host__?

推荐答案

基本上,GPU编程是关于大规模并行性的。它是与普通单线程编程完全不同的范例。
除非您只想同时将这些函数应用于大型数组的各个元素,否则将其编码到GPU中没有任何好处。
实际上,GPU核心时钟比您的处理器慢得多。
如果将主要针对CPU编写的函数以单线程形式编译为GPU,则可能会导致性能下降。
您需要将问题重新考虑到GPU范例中。

Basically, GPU programming is all about massive parallelism. It is a totally different paradigm than normal single threaded programming. Unless you just want to apply these functions at the same time to individual elements of large arrays, there is no benefit of coding it into the GPU. In fact, GPU core clock is much slower than your processor. If you will compile functions written mainly targeting a CPU in a single thread flavor to GPU, you will get a potential performance penalty. You need to re-think your problem into the GPU paradigm.

这篇关于将所有CUDA功能更改为__host__ __device__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆