我對opencl執行內核感興趣,它在unsigned int中計數設置(1)位 我知道opencl有這樣的擴展名,我不想使用它,但自己實現opencl中的bitcount實現
1
A
回答
0
大多數老派基於CPU的技巧也適用於這裏,雖然任何循環在GPU上都不會很好。 (非全局內存)表可能最好。
請參見:
How to count the number of set bits in a 32-bit integer?
2
這是不是你正在尋找的確切功能。但由於沒有人發佈OpenCL代碼,我會添加它。按照您的要求,它是OpenCL位計數代碼,用於256位整數而不是32位。代碼是從here。它使用Dithermaster指出的衆所周知的算法之一。轉換爲32位應該不困難。
//
// popcnt256 - return population count for 256-bit value
//
uint popcnt256 (ulong4 vreg)
{
const ulong4 m1 = (ulong4)(0x5555555555555555,0x5555555555555555,0x5555555555555555,0x5555555555555555);
const ulong4 m2 = (ulong4)(0x3333333333333333,0x3333333333333333,0x3333333333333333,0x3333333333333333);
const ulong4 m4 = (ulong4)(0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f);
const ulong4 h01 = (ulong4)(0x0101010101010101,0x0101010101010101,0x0101010101010101,0x0101010101010101);
vreg -= (vreg >> 1) & m1;
vreg = (vreg & m2) + ((vreg >> 2) & m2);
vreg = (vreg + (vreg >> 4)) & m4;
vreg = (vreg * h01) >> 56;
return vreg.s0 + vreg.s1 + vreg.s2 + vreg.s3;
}
相關問題
- 1. 在OpenCL中實現
- 2. 如何僅使用按位運算符來實現Bitcount?
- 3. Java - bitCount()的大O?
- 4. 如何實現opencl內核管道
- 5. Bitwise - bitCount的公式含義?
- 6. 這個並行性可以在OpenCL中實現
- 7. 是否有支持fp16擴展的OpenCL的可用實現?
- 8. 的OpenCL內核實現一個簡單的數學公式
- 9. 在不同的機器上實現OpenCL的最佳性能
- 10. bitCount導致錯誤,可能的修復?
- 11. 針對英特爾酷睿i5(linux)的OpenCL實現
- 12. 是否有unix crypt(3)函數的OpenCL實現?
- 13. 在openCL中clBuildProgram時出現-11錯誤
- 14. OpenCL中的clReleaseMemObject
- 15. 流中的OpenCL
- 16. OpenCL中
- 17. 基本OpenCL互斥鎖實現(當前掛起)
- 18. 需要採取哪些步驟在設備上實現OpenCL?
- 19. 爲什麼蘋果在他們的OpenGL/OpenCL實現中使用CLang
- 20. OpenCL使用GPU的最佳實踐
- 21. 模式中的OpenCL
- 22. 在OpenCL中的HashMap?
- 23. OpenCL中的障礙
- 24. 在OpenCL中,如何在CPU上實現私有內存和共享內存?
- 25. __local OpenCL中
- 26. PickerView在Titanium中實現的TableView實現
- 27. 在python中實現R表的實現
- 28. OSX上的矢量寬度在Intel Iris Graphics 6100上實現OpenCL(MBP 2015)
- 29. 運行Opencl時出現異常
- 30. OpenCL抽象和實際硬件