在CUDA布尔运算 [英] Boolean operations on CUDA
问题描述
我的应用程序需要对位向量执行像OR和XOR位向量运算。
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
CUDA是否支持布尔变量?例如布尔
为C.如果是的话,它是如何存储和操作的?那么它也支持位向量操作?我找不到CUDA编程指南中的答案。
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.
推荐答案
CUDA支持标准C ++ 布尔
,但在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.
这篇关于在CUDA布尔运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!