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

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

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 &#39;KERNEL_FQ&#39;```

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>



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:

确定