在CUDA中处理大型switch语句 [英] Dealing with large switch statements in CUDA

查看:241
本文介绍了在CUDA中处理大型switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解不建议在CUDA中进行分支,因为它会对性能产生不利影响。在我的工作中,我发现自己必须实现包含数十个以上案例的大型switch语句。

I understand that branching in CUDA is not recommended as it can adversely affect performance. In my work, I find myself having to implement large switch statements that contain upward of a few dozen cases.

有人能知道这对性能有多严重的影响吗? (官方文档不是很明确)还有没有人有更有效的方式来处理这一部分?

Does anyone have any idea how badly this will affect performance. (The official documentation isn't very specific) Also does anyone have a more efficient way of handling this portion?

推荐答案

一个好避免多次切换的方法是实现功能表,并根据切换条件从表中按索引选择功能。 CUDA允许您在内核中的 __ device __ 函数上使用函数指针。

A good way to avoid multiple switches is to implement function table and select function from table by index based in you switch condition. CUDA allows you to use function pointers on __device__ function in kernels.

这篇关于在CUDA中处理大型switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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