---
name: "functionQualifiers"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/functionQualifiers"
---

# functionQualifiers(3clc)

Qualifiers for kernel functions.

## NAME

Function\_Qualifiers - Qualifiers for kernel functions.

###

| |
| --- |
| \_\_kernel kernel \_\_attribute\_\_((vec\_type\_hint(\<type*n*\>))) \_\_attribute\_\_((work\_group\_size\_hint(*X*, *Y*, *Z*))) \_\_attribute\_\_((reqd\_work\_group\_size(*X*, *Y*, *Z*))) |

## DESCRIPTION

The **\_\_kernel** (or **kernel**) qualifier declares a function to be a kernel that can be executed by an application on an OpenCL device(s). The following rules apply to functions that are declared with this qualifier:

• It can be executed on the device only

• It can be called by the host

• It is just a regular function call if a **\_\_kernel** function is called by another kernel function.

Kernel functions with variables declared inside the function with the [**local**(3clc)](/local/3clc.md) or [**local**(3clc)](/local/3clc.md) qualifier can be called by the host using appropriate APIs such as [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md), and [**clEnqueueTask**(3clc)](/clEnqueueTask/3clc.md).

The behavior of calling kernel functions with variables declared inside the function with the [**local**(3clc)](/local/3clc.md) or [**local**(3clc)](/local/3clc.md) qualifier from other kernel functions is implementation-defined.

The **\_\_kernel** and **kernel** names are reserved for use as functions qualifiers and shall not be used otherwise. Optional Attribute Qualifiers.PP The **\_\_kernel** qualifier can be used with the keyword [**attribute**(3clc)](/attribute/3clc.md) to declare additional information about the kernel function as described below.

The optional \_\_attribute\_\_((vec\_type\_hint(\<type\>))) is a hint to the compiler and is intended to be a representation of the computational *width* of the **\_\_kernel**, and should serve as the basis for calculating processor bandwidth utilization when the compiler is looking to autovectorize the code. In the \_\_attribute\_\_((vec\_type\_hint(\<type\>))) qualifier \<type\> is one of the built-in vector types or the constituent scalar element types. If vec\_type\_hint (\<type\>) is not specified, the kernel is assumed to have the \_\_attribute\_\_((vec\_type\_hint(int))) qualifier.

Implicit in autovectorization is the assumption that any libraries called from the **\_\_kernel** must be recompilable at run time to handle cases where the compiler decides to merge or separate workitems. This probably means that such libraries can never be hard coded binaries or that hard coded binaries must be accompanied either by source or some retargetable intermediate representation. This may be a code security question for some.

For example, where the developer specified a width of **float4**, the compiler should assume that the computation usually uses up 4 lanes of a float vector, and would decide to merge work-items or possibly even separate one work-item into many threads to better match the hardware capabilities. A conforming implementation is not required to autovectorize code, but shall support the hint. A compiler may autovectorize, even if no hint is provided. If an implementation merges **N** work-items into one thread, it is responsible for correctly handling cases where the number of global or local work-items in any dimension modulo **N** is not zero.

If for example, a **\_\_kernel** function is declared with \_\_attribute\_\_(( vec\_type\_hint (float4))) (meaning that most operations in the **\_\_kernel** are explicitly vectorized using **float4**) and the kernel is running using Intel® Advanced Vector Instructions (Intel® AVX) which implements a 8-float-wide vector unit, the autovectorizer might choose to merge two work-items to one thread, running a second work-item in the high half of the 256-bit AVX register.

As another example, a Power4 machine has two scalar double precision floating-point units with an 6-cycle deep pipe. An autovectorizer for the Power4 machine might choose to interleave six kernels declared with the \_\_attribute\_\_(( vec\_type\_hint (double2))) qualifier into one hardware thread, to ensure that there is always 12-way parallelism available to saturate the FPUs. It might also choose to merge 4 or 8 work-items (or some other number) if it concludes that these are better choices, due to resource utilization concerns or some preference for divisibility by 2.

The optional \_\_attribute\_\_((work\_group\_size\_hint(*X*, *Y*, *Z*))) is a hint to the compiler and is intended to specify the work-group size that may be used i.e. value most likely to be specified by the *local\_work\_size* argument to [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md). For example the \_\_attribute\_\_((work\_group\_size\_hint(1, 1, 1))) is a hint to the compiler that the kernel will most likely be executed with a work-group size of 1.

The optional \_\_attribute\_\_((reqd\_work\_group\_size(*X*, *Y*, *Z*))) is the work-group size that must be used as the *local\_work\_size* argument to [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md). This allows the compiler to optimize the generated code appropriately for this kernel. The optional \_\_attribute\_\_((reqd\_work\_group\_size(*X*, *Y*, *Z*))), if specified, must be (1, 1, 1) if the kernel is executed via [**clEnqueueTask**(3clc)](/clEnqueueTask/3clc.md).

If *Z* is one, the *work\_dim* argument to [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md) can be 2 or 3. If *Y* and *Z* are one, the *work\_dim* argument to [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md) can be 1, 2 or 3.

## NOTES

Kernel functions with variables declared inside the function with the [**local**(3clc)](/local/3clc.md) or [**local**(3clc)](/local/3clc.md) qualifier can be called by the host using appropriate APIs such as [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md), and [**clEnqueueTask**(3clc)](/clEnqueueTask/3clc.md).

The behavior of calling kernel functions with variables declared inside the function with the [**local**(3clc)](/local/3clc.md) and [**local**(3clc)](/local/3clc.md) qualifier from other kernel functions is implementation-defined.

The **\_\_kernel** and **kernel** names are reserved for use as functions qualifiers and shall not be used otherwise.

### Example

| |
| --- |
| // autovectorize assuming float4 as the // basic computation width \_\_kernel \_\_attribute\_\_((vec\_type\_hint(float4))) void foo( \_\_global float4 \*p ) { .... // autovectorize assuming double as the // basic computation width \_\_kernel \_\_attribute\_\_((vec\_type\_hint(double))) void foo( \_\_global float4 \*p ){ .... // autovectorize assuming int (default) // as the basic computation width \_\_kernel void foo( \_\_global float4 \*p ){ .... |

## SPECIFICATION

**OpenCL Specification**\[1\]

## SEE ALSO

[**attribute**(3clc)](/attribute/3clc.md), [**clEnqueueNDRangeKernel**(3clc)](/clEnqueueNDRangeKernel/3clc.md), [**clEnqueueTask**(3clc)](/clEnqueueTask/3clc.md)

## AUTHORS

**The Khronos Group**

## COPYRIGHT

Copyright © 2007-2011 The Khronos Group Inc.\
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.

## NOTES

- 1\.

  OpenCL Specification

  page 227, section 6.7 - Function Qualifiers
