我这里需要做(64位的)除法运算和模运算,无符号八位到无符号64位的扩展。大家有没有简单的方法,多谢了!
有一些方法,可以尝试一下(仅供参考):
-
模运算
如果y是2^n,那么x%y = x &(y-1)
-
除法运算 x/y
如果y是2^n,那么x/y = x >>n
-
u8 -> u64转换
• 直接强制转换
y = (uint64_t)x;
• 与“0”按位进行或操作
x|0ull
• 使用union?
union {
uint64_t a;
uint8_t b[8];
}
• 使用ptx转换嵌入到CUDA中
例如u32->u64:
device uint8_t u8_to_u64 (int x) {
unsigned long long int y;
asm(“cvt.u64.u32 %0, %1;” : “=l”(y) : “r”(x));
return y;
}
你可以参考http://docs.nvidia.com/cuda/inline-ptx-assembly/index.html 和http://docs.nvidia.com/cuda/parallel-thread-execution/index.html
Some other reference:
Math API: http://docs.nvidia.com/cuda/cuda … .html#axzz4Oib3DpNG
cuBlas: http://docs.nvidia.com/cuda/cublas/index.html