Skip to content

[SYCL] Implement SYCL 2020 spec functionality: no propagation from function to the caller #4084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ def SYCLSimdDocs : Documentation {
The compiler may decide to compile such functions using different optimization
and code generation pipeline. Also, this attribute is used to distinguish
ESIMD private globals from regular SYCL global variables.

In SYCL 1.2.1 mode, the ``intel::sycl_explicit_simd`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.
}];
}

Expand Down Expand Up @@ -2443,8 +2447,9 @@ lambda capture, or function object member, of the callable to which the
attribute was applied. This effect is equivalent to annotating restrict on
**all** kernel pointer arguments in an OpenCL or SPIR-V kernel.

If ``intel::kernel_args_restrict`` is applied to a function called from a device
kernel, the attribute is not ignored and it is propagated to the kernel.
In SYCL 1.2.1 mode, the ``intel::kernel_args_restrict`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.

The attribute forms an unchecked assertion, in that implementations
do not need to check/confirm the pre-condition in any way. If a user applies
Expand Down Expand Up @@ -2482,8 +2487,10 @@ def SYCLIntelNumSimdWorkItemsAttrDocs : Documentation {
let Content = [{
Applies to a device function/lambda function. Indicates the number of work
items that should be processed in parallel. Valid values are positive integers.
If ``intel::num_simd_work_items`` is applied to a function called from a
device kernel, the attribute is not ignored and it is propagated to the kernel.

In SYCL 1.2.1 mode, the ``intel::num_simd_work_items`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.

.. code-block:: c++

Expand Down Expand Up @@ -2656,6 +2663,11 @@ allows the Y and Z arguments to be optional. If not provided by the user, the
value of Y and Z defaults to 1. See section 5.8.1 Kernel Attributes for more
details.

In SYCL 1.2.1 mode, the ``intel::reqd_work_group_size``,
``cl::reqd_work_group_size``, and ``sycl::reqd_work_group_size`` attributes are
propagated from the function they are applied to onto the kernel which calls the
function. In SYCL 2020 mode, the attributes are not propagated to the kernel.

.. code-block:: c++

[[sycl::reqd_work_group_size(4, 4, 4)]] void foo() {}
Expand Down Expand Up @@ -2800,8 +2812,10 @@ Applies to a device function/lambda function. Indicates the maximum dimensions
of a work group. Values must be positive integers. This is similar to
reqd_work_group_size, but allows work groups that are smaller or equal to the
specified sizes.
If ``intel::max_work_group_size`` is applied to a function called from a
device kernel, the attribute is not ignored and it is propagated to the kernel.

In SYCL 1.2.1 mode, the ``intel::max_work_group_size`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.

.. code-block:: c++

Expand Down Expand Up @@ -2832,8 +2846,10 @@ Applies to a device function/lambda function or function call operator (of a
function object). Indicates the largest valid global work dimension that will be
accepted when running the kernel on a device. Valid values are integers in a
range of [0, 3].
If ``intel::max_global_work_dim`` is applied to a function called from a
device kernel, the attribute is not ignored and it is propagated to the kernel.

In SYCL 1.2.1 mode, the ``intel::max_global_work_dim`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.

.. code-block:: c++

Expand Down Expand Up @@ -2890,6 +2906,10 @@ device operation, guiding the FPGA backend to insert the appropriate number of
registers to break-up the combinational logic circuit, and thereby controlling
the length of the longest combinational path.

In SYCL 1.2.1 mode, the ``intel::scheduler_target_fmax_mhz`` attribute is
propagated from the function it is applied to onto the kernel which calls the
function. In SYCL 2020 mode, the attribute is not propagated to the kernel.

.. code-block:: c++

[[intel::scheduler_target_fmax_mhz(4)]] void foo() {}
Expand Down Expand Up @@ -2920,6 +2940,10 @@ function object). If 1, compiler doesn't use the global work offset values for
the device function. Valid values are 0 and 1. If used without argument, value
of 1 is set implicitly.

In SYCL 1.2.1 mode, the ``intel::no_global_work_offset`` attribute is
propagated from the function it is applied to onto the kernel which calls the
function. In SYCL 2020 mode, the attribute is not propagated to the kernel.

.. code-block:: c++

[[intel::no_global_work_offset]]
Expand Down Expand Up @@ -4607,6 +4631,10 @@ the ``[[intel::named_sub_group_size(NAME)]]`` documentation for clarification.
This attribute is mutually exclusive with ``[[intel::named_sub_group_size(NAME)]]``
and ``[[intel::sycl_explicit_simd]]``.

In SYCL 1.2.1 mode, the ``intel::reqd_sub_group_size`` attribute is propagated
from the function it is applied to onto the kernel which calls the function.
In SYCL 2020 mode, the attribute is not propagated to the kernel.

In addition to device functions, the required sub-group size attribute may also
be specified in the definition of a named functor object and lambda functions,
as in the examples below:
Expand Down
24 changes: 15 additions & 9 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,21 @@ static void collectSYCLAttributes(Sema &S, FunctionDecl *FD,
if (!FD->hasAttrs())
return;

llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) {
// FIXME: Make this list self-adapt as new SYCL attributes are added.
return isa<IntelReqdSubGroupSizeAttr, IntelNamedSubGroupSizeAttr,
ReqdWorkGroupSizeAttr, SYCLIntelKernelArgsRestrictAttr,
SYCLIntelNumSimdWorkItemsAttr,
SYCLIntelSchedulerTargetFmaxMhzAttr,
SYCLIntelMaxWorkGroupSizeAttr, SYCLIntelMaxGlobalWorkDimAttr,
SYCLIntelNoGlobalWorkOffsetAttr, SYCLSimdAttr>(A);
});
// In SYCL 1.2.1 mode, the attributes are propagated from the function they
// are applied to onto the kernel which calls the function.
// In SYCL 2020 mode, the attributes are not propagated to the kernel.
if (DirectlyCalled || S.getASTContext().getLangOpts().getSYCLVersion() <
LangOptions::SYCL_2020) {
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) {
// FIXME: Make this list self-adapt as new SYCL attributes are added.
return isa<IntelReqdSubGroupSizeAttr, IntelNamedSubGroupSizeAttr,
ReqdWorkGroupSizeAttr, SYCLIntelKernelArgsRestrictAttr,
SYCLIntelNumSimdWorkItemsAttr,
SYCLIntelSchedulerTargetFmaxMhzAttr,
SYCLIntelMaxWorkGroupSizeAttr, SYCLIntelMaxGlobalWorkDimAttr,
SYCLIntelNoGlobalWorkOffsetAttr, SYCLSimdAttr>(A);
});
}

// Attributes that should not be propagated from device functions to a kernel.
if (DirectlyCalled) {
Expand Down
Loading