-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Add support for new FPGA function attribute stall_enable #2734
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
Conversation
This patch adds support a new FPGA function attribute, stall_enable, to be sent through to the backend (and ignored by the emulator). Syntax: [[intel::stall_enable]] This function attribute applies to a lambda function, or function definition. Requests, to the extent possible, that statically-scheduled clusters handle stalls using a stall-enable signal to freeze computation within the cluster. Note that this attribute can be applied to any lambda or function definition, it does not have to be a device function/kernel. Stall_enable attribute takes no arguments and LLVM IR function metadata should simply be i32 1. Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks ok in general except my little comment and the fact that I completely didn't get the doc, because it looks like very specific for some devices (FPGA?).
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
} else if (const auto *A = D->getAttr<SYCLIntelStallEnableAttr>()) { | ||
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | ||
D->setInvalidDecl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines seem not necessary. The attribute stall_enable
seems to be enabled only for SYCL and this section of the code produces errors for attributes which should be applied to OpenCL kernel in OpenCL language and all these diagnostics are disabled for SYCL. See if statement on lines 8822-8823 in this file.
} else if (const auto *A = D->getAttr<SYCLIntelStallEnableAttr>()) { | |
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; | |
D->setInvalidDecl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks ok in general except my little comment and the fact that I completely didn't get the doc, because it looks like very specific for some devices (FPGA?).
I meant that, I didn't get the doc because I'm not familiar with FPGA devices. Does it make sense to mention that it is some FPGA-specific thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i looked at other new FPGA function attribute "SYCLIntelSchedulerTargetFmaxMhz" . It did not add those line (i think i can remove those).
i do not see anywhere it is mentioned to be a FPGA specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we had FPGA specific attributes in intelfpga
namespace, so it was pretty much obvious to which device they belong. Now when intelfpga
was deprecated in favor of just intel
namespace we can re-consider texts in some warnings etc, but it can be done in a separate patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created separate PR for this issue.
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
// CHECK: define spir_kernel void @"{{.*}}test_kernel2"() #0 {{.*}} !stall_enable [[FOO:![0-9]+]] | ||
// CHECK: define spir_kernel void @"{{.*}}test_kernel3"() #0 {{.*}} !stall_enable [[FOO:![0-9]+]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect the same metadata for all 3 kernels? If yes, we can do
// CHECK: define spir_kernel void @"{{.*}}test_kernel2"() #0 {{.*}} !stall_enable [[FOO:![0-9]+]] | |
// CHECK: define spir_kernel void @"{{.*}}test_kernel3"() #0 {{.*}} !stall_enable [[FOO:![0-9]+]] | |
// CHECK: define spir_kernel void @"{{.*}}test_kernel2"() #0 {{.*}} !stall_enable [[FOO]] | |
// CHECK: define spir_kernel void @"{{.*}}test_kernel3"() #0 {{.*}} !stall_enable [[FOO]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexeySotkin, Thanks for taking a look at the patch and the feedback. All three kernels expect same metadata here. I have updated test.
Signed-off-by: Soumi Manna <[email protected]>
clang/lib/Sema/SemaSYCL.cpp
Outdated
@@ -543,6 +543,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> { | |||
if (auto *A = FD->getAttr<SYCLIntelNoGlobalWorkOffsetAttr>()) | |||
Attrs.insert(A); | |||
|
|||
if (auto *A = FD->getAttr<SYCLIntelStallEnableAttr>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means this attribute is propagated to kernel if its applied to any function the kernel calls. Is that the requirement? If so, I think we should add this to documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @elizabethandrews for taking a look at the patch and the feedback.
No. The attribute can not be applied to arbitrary device functions, only to kernels.
If intel::stall_enable
is applied to a function called from a device
kernel, the attribute is ignored and it is not propagated to a kernel.
The attribute must be used on a kernel lambda or functor, e.g.,:
cgh.single_task([=] () [[intel::stall_enable]]
{ // kernel body }
);
This attribute will be similar like kernel_args_restrict and scheduler_target_fmax_mhz as an example of kernel attributes.
I have updated documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If intel::stall_enable is applied to a function called from a device
kernel, the attribute is ignored and it is not propagated to a kernel.
But I guess this part of the code will propagate this attribute from any function, right? We probably need to double check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. This needs to be removed if we don't want to propagate attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated SemaSYCL file. We will not propagate attribute on functions that are called from the kernel. I am not sure whether there is any other way we can handle this.
// Allow the kernel attribute "stall_enable" only on lambda functions
// and function objects that are called directly from a kernel
// (i.e. the one passed to the single_task or parallel_for functions).
// For all other cases, emit a warning and ignore.
Applies to a lambda function, or function definition. Requests, to the extent | ||
possible, that statically-scheduled clusters handle stalls using a stall-enable | ||
signal to freeze computation within the cluster. This attribute can be applied | ||
to device function/kernel and not to arbitrary device functions. This takes no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on this? I think this line needs to be more clear. What is device function (in device function/kernel) vs 'arbitrary device functions'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated documentation to be more clear about the attribute.
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
clang/include/clang/Basic/Attr.td
Outdated
@@ -1226,6 +1226,19 @@ def SYCLIntelNumSimdWorkItems : InheritableAttr { | |||
let PragmaAttributeSupport = 0; | |||
} | |||
|
|||
def SYCLIntelStallEnable : InheritableAttr { | |||
let Spellings = [CXX11<"intel","stall_enable">]; | |||
let LangOpts = [SYCLIsDevice, SYCLIsHost]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we are simply ignoring the attribute on host. Let's just allow it on device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we are ignoring it on host, but now host compiler emits warnings when sees this attribute, because it became unknown for host compiler once you removed SYCLIsHost
lang option from here. I.e. there is no way to write code with this attribute without emitting warnings now, this is not good for users. Can we return SYCLIsHost
back, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you are saying @Fznamznon. I take back my suggestion. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added back SYCLIsHost. Thanks for the suggestion.
let Category = DocCatFunction; | ||
let Heading = "intel::stall_enable"; | ||
let Content = [{ | ||
Applies to a device function/lambda function. Requests, to the extent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this changed to: "When applied to a lambda or
function call operator (of a function object) on device, this requests, to the extent ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
return; | ||
|
||
if (S.LangOpts.SYCLIsHost) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are not applying the attribute on host, I think we should allow it only on device.
h.single_task<class test_kernel1>(f); | ||
|
||
h.single_task<class test_kernel2>( | ||
[]() { test(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused by this case. Is the attribute on function test(), expected to be propagated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should not be propagated.
clang/test/SemaSYCL/stall_enable.cpp
Outdated
[[intel::stall_enable]] void operator()() const {} | ||
}; | ||
|
||
[[intel::stall_enable]] void func_do_not_ignore() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, this one too. Is the attribute valid only on lambdas and function objects passed to the kernel or even on functions called from the kernel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attribute is valid only on lambdas and function objects passed to the kernel not on function called from kernel.
Signed-off-by: Soumi Manna <[email protected]>
|
||
The ``intel::stall_enable`` attribute has an effect when applied to a | ||
function, and no effect otherwise. This attribute takes no argument and | ||
LLVM IR function metadata should simply be i32 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to mention what will be emitted in LLVM IR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we need to mention this. Removed it.
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
clang/test/SemaSYCL/stall_enable.cpp
Outdated
Functor16 f16; | ||
// CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 | ||
// CHECK: SYCLIntelStallEnableAttr {{.*}} | ||
h.single_task<class test_kernel3>(f16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is no longer necessary as it is the same as FuncObj above.
When applied to a lambda or function call operator (of a function object) | ||
on device, this requests, to the extent possible, that statically-scheduled | ||
clusters handle stalls using a stall-enable signal to freeze computation | ||
within the cluster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to say that this is ignored on host, @Fznamznon?
If so, suggest, somethine like: 'This attribute is ignored on the host'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion here, other FPGA attributes are likely also ignored on host, but most of their docs don't mention anything about host. This doc also says "When applied to a lambda or function call operator (of a function object) on device " and nothing about host, which might be a clue that this attribute is intended for device use. However explicit statement that this attribute doesn't have any effect on host does seem good. So, I think we could add it, but it is not really something that should block this patch if we don't do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good for users to mention about this. I have updated doc.
Signed-off-by: Soumi Manna <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Thank you Everyone for the reviews. @premanandrao, are you OK with the change? |
Absolutely! |
Thanks. @bader, Patch is ready for merge. |
…ANY function [[intel::use_stall_enable_clusters]] is a function attribute, not a kernel one. It can be applied to any function or lambda. This patch removes the restriction that was added on PR: intel#2734 to allow propagating the attribute to kernel if it is applied to any function the kernel calls. Signed-off-by: Soumi Manna <[email protected]>
…any function (#3900) * [SYCL][FPGA] Apply [[intel::use_stall_enable_clusters]] attribute to ANY function [[intel::use_stall_enable_clusters]] is a function attribute, not a kernel one. It can be applied to any function or lambda. This patch removes the restriction that was added on PR: #2734 to allow propagating the attribute to kernel if it is applied to any function the kernel calls. Signed-off-by: Soumi Manna <[email protected]>
This patch adds support a new FPGA function attribute, stall_enable,
to be sent through to the backend (and ignored by the emulator).
Syntax:
[[intel::stall_enable]]
This function attribute applies to a lambda function, or function definition.
Requests, to the extent possible, that statically-scheduled clusters handle
stalls using a stall-enable signal to freeze computation within the cluster.
Stall_enable attribute can be applied to device function/kernel
and it takes no arguments.
LLVM IR function metadata should simply be i32 1.
Signed-off-by: Soumi Manna [email protected]