在OpenCL中,__kernel和KERNEL_FQ之间的区别是什么?

huangapple go评论103阅读模式
英文:

Difference between __kernel and KERNEL_FQ in OpenCL

问题

  1. HashCat 项目中,许多 OpenCL 文件中的内核函数定义如下:
  2. ```cpp
  3. KERNEL_FQ void m20600_comp (KERN_ATTR_TMPS (omt_sha256_tmp_t))
  4. {
  5. ...
  6. }

参考文件:https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/m20600-pure.cl#L28

我只见过以 __kernel 定义的 OpenCL 内核函数。KERNEL_FQ 能否有效替代 __kernel?如果不能,它是什么?当我尝试使用 Clang 编译 AMD 内核时,出现以下错误:

kernel-test.cl:138:1: error: unknown type name 'KERNEL_FQ'

我运行的命令是:clang -Dcl_clang_storage_class_specifiers -isystem libclc/generic/include -include clc/clc.h -target polaris11-amdgcn-- -xcl kernel-test.cl -emit-llvm -S -o kernel-test.ll

感谢提供帮助!

  1. <details>
  2. <summary>英文:</summary>
  3. In the HashCat project, a lot of the OpenCL files have kernel functions defined like this:

KERNEL_FQ void m20600_comp (KERN_ATTR_TMPS (omt_sha256_tmp_t))
{
...
}

  1. Reference File: https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/m20600-pure.cl#L28
  2. I have only seen OpenCL kernel functions defined with `__kernel`. Is KERNEL_FQ a valid replacement for `__kernel`? If not, what is it? When I try to compile the Kernel with Clang for AMD I get:
  3. ```kernel-test.cl:138:1: error: unknown type name &#39;KERNEL_FQ&#39;```
  4. The command I ran was: ```clang -Dcl_clang_storage_class_specifiers -isystem libclc/generic/include -include clc/clc.h -target polaris11-amdgcn-- -xcl kernel-test.cl -emit-llvm -S -o kernel-test.ll```
  5. Any help is appreciated!
  6. </details>
  7. # 答案1
  8. **得分**: 1
  9. KERNEL_FQ 是一个预处理宏,也就是说,在它出现的地方,预处理器会在编译之前用其他文本替换它:https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/inc_vendor.h#L66
  10. 具体来说,它用于在OpenCLCUDA内核以及其他后端之间进行切换,重用相同的C源代码(大部分兼容),但在两者在语言特定关键字上不同的地方替换关键字。这是一个非常聪明的技巧,可以避免多次冗余实现。
  11. <details>
  12. <summary>英文:</summary>
  13. KERNEL_FQ is a preprocessor macro, i.e. wherever it occurs, the preprocessor replaces it with some other text before compiling: https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/inc_vendor.h#L66
  14. Specifically it is used to switch between OpenCL and CUDA kernels and other backends, reusing the same C source code (mostly compatible) but replacing the keywords where the two differ to language-specific keywords. A very clever trick to avoid multiple redundant implememtations.
  15. </details>

huangapple
  • 本文由 发表于 2023年7月7日 05:27:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632615.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定