CUDA 上的布尔运算
我的应用程序需要对位向量执行“或”和“异或”等位向量运算。
e.g suppose array A = 000100101 (a.k.a bit vector)
B = 100101010
A . B = 100101111
CUDA 支持布尔变量吗?例如C中的bool
。如果是,它是如何存储和操作的?它也支持位向量运算吗?我在《CUDA编程指南》中找不到答案。
My application needs to perform bit-vector operations like OR and XOR on bit-vectors.
e.g suppose array A = 000100101 (a.k.a bit vector)
B = 100101010
A . B = 100101111
Does CUDA support boolean variables? e.g. bool
as in C. If yes, how is it stored and operated on? Does it also support bit-vector operations?. I couldn't find the answer in the CUDA Programming Guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CUDA 支持标准 C++
bool
,但在 C++ 中它只是保证支持两种状态的类型,因此不应对其使用位操作。在 CUDA 中,与 C++ 中一样,您可以获得整数类型按位运算符的标准补码(与、或、异或、补码以及左移和右移)。理想情况下,出于内存吞吐量的原因,您应该致力于使用 32 位类型(或打包的 32 位 CUDA 向量类型)。CUDA supports the standard C++
bool
, but in C++ it is only a type guaranteed to support two states, so bit operations shouldn't be used on it. In CUDA, as in C++, you get the standard complement of bitwise operators for integral types (and, or, xor, complement and left and right shift). Ideally you should aim to use a 32 bit type (or a packed 32 bit CUDA vector type) for memory throughput reasons.