Search code examples
c++gpuopenclgpgpu

Difference between __kernel and KERNEL_FQ in OpenCL


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!


Solution

  • 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.