英文:
Difference between __kernel and KERNEL_FQ in OpenCL
问题
在 HashCat 项目中,许多 OpenCL 文件中的内核函数定义如下:
```cpp
KERNEL_FQ void m20600_comp (KERN_ATTR_TMPS (omt_sha256_tmp_t))
{
...
}
参考文件: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
感谢提供帮助!
<details>
<summary>英文:</summary>
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))
{
...
}
Reference File: https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/m20600-pure.cl#L28
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:
```kernel-test.cl:138:1: error: unknown type name 'KERNEL_FQ'```
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```
Any help is appreciated!
</details>
# 答案1
**得分**: 1
KERNEL_FQ 是一个预处理宏,也就是说,在它出现的地方,预处理器会在编译之前用其他文本替换它:https://github.com/security-geeks/oclHashcat/blob/c4dfcf48f7f55ee370ca2e6f86f004e4d492da72/OpenCL/inc_vendor.h#L66
具体来说,它用于在OpenCL和CUDA内核以及其他后端之间进行切换,重用相同的C源代码(大部分兼容),但在两者在语言特定关键字上不同的地方替换关键字。这是一个非常聪明的技巧,可以避免多次冗余实现。
<details>
<summary>英文:</summary>
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
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.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论