-
Notifications
You must be signed in to change notification settings - Fork 749
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
[SYCL][FPGA] Add clang support for buffer_location property #2166
[SYCL][FPGA] Add clang support for buffer_location property #2166
Conversation
174a54d
to
076b49d
Compare
This is a compiler-time known accessor property which serves as an optimization hint for a compiler on where exactly buffer was allocated. This is needed when a board has multiple disjoint global memories that must be managed explicitly by a programmer. When the property is added as a template parameter of an accessor - SemaSYCL will implicitly add ``intelfpga::kernel_arg_buffer_location`` attribute to an OpenCL kernel generated from SYCL kernel object. It is not allowed to use the attribute explicitly in SYCL code. When the attribute is applied, clang generates metadata attached to OpenCL kernel. Number of values stored in the metadata is the same as number of kernel parameters. Order of metadata values is following the order of pointer kernel parameters. Metadata values are of an integer type and is being set accordingly values passed through accessor property ``buffer_location``. This values are mapped in hardware backend to the actual locations of buffers (DDR, QDR etc). Default value passed in the metadata is '-1'. Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
5a5ee02
to
49dce75
Compare
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'm not a big fan of this approach. The info you really care about is at the parameter level.
First, don't name attributes we don't expect our users to spell.
Second, are we sure this isn't something we can calculate during codegen directly, rather than putting it in sema?
Third, if we cannot, than this is better expressed in the AST as an attribute on the ParmVarDecl instead. So each parameter of the BufferLocation type should have an attribute with the integer value attached to it (again, ONLY if we are sure we cannot figure this out during codegen).
Finally, this patch seems to make assumptions about the layout of the library. We have to be more defensive about this.
We don't necessarily control our the library (a 3rd party could write a version of the library!), nor do we have any guarantee that the version necessarily matches our release. We need to diagnose to protect our assumptions.
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.
@erichkeane thanks for the early feedback !
Second, are we sure this isn't something we can calculate during codegen directly, rather than putting it in sema?
I think it's too late to do in CodeGen since we are constructing OpenCL kernel in Sema. In CodeGen we already see kernel declarations having pointer parameters instead of accessor objects, so no original information stored in the appropriate QualType can be queried. Also we can't even distinguish accessor pointers from USM pointers in CodeGen! I agree, that this attribute is looking nasty, but I believe for this we shall move OpenCL kernel generation out of Sema to actually CodeGen (where it belongs).
Third, if we cannot, than this is better expressed in the AST as an attribute on the ParmVarDecl instead. So each parameter of the BufferLocation type should have an attribute with the integer value attached to it (again, ONLY if we are sure we cannot figure this out during codegen).
I will think about it.
Finally, this patch seems to make assumptions about the layout of the library. We have to be more defensive about this.
We don't necessarily control our the library (a 3rd party could write a version of the library!), nor do we have any guarantee that the version necessarily matches our release. We need to diagnose to protect our assumptions.
Thanks! I'll add some (warnings?) diagnostics then.
They'd likely need to be errors, and stop execution. If the buffer isn't the right layout it seems that it should just be an ill-formed program. |
I disagree. As for now accessor properties are Intel extension and serves only for optimization purposes (semantically they have no affect, but metadata generation). Hence if some one wants to use Intel compiler and a third-party library I see no reasons to deny them this opportunity (emitting warning and stop whatever compiler was up to do with this property is good enough). |
In that case, you absolutely cannot make any assumptions on the layout of them. The purpose of errors is to be an assertion type-thing, where we would require this buffer_location property to be a certain format. If we don't emit those as errors, NO assumptions on them being valid can be made. I'm alright with this, but it means you have to be much more careful with the implementation. |
Sure, thanks! For now this implementation doesn't break any SYCL tests, even we have no support for this feature in the headers, so I assume I was quite careful :) |
You weren't particularly, I see a number of assumptions you make, like that the template arguments are types, etc. I pointed out a few, but everything you pull from the buffer_location property isn't something that can be counted on. |
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.
Any spec links for this one?
Seems like it is exposed to user.
1. Move attribute from FuncDecl to ParamVarDecl 2. Add several diagnostics 3. Reimplement property handler Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
What have changed:
@Fznamznon spec for compiletime known properties can be found here: #1925 . For buffer location itself only SPIR-V spec is public now: #2084 , ping @mohammadfawaz and @GarveyJoe to make SYCL spec public. |
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Addressed the comments, major:
I left @Fznamznon comment #2166 (comment) unaddressed, since I don't really know, how to improve special type detection |
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
This reverts commit f71cec5.
Seems like CPU RT in our CI isn't ready for this change SPIR-V-wise, so I have reverted SPIR-V support of the feature for testing. |
…ion"" This reverts commit ab5b6da.
This patch needs to be merged first: #2240 |
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.
Looks ok, but please get approve from @erichkeane first.
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.
See a few missed diagnostics.
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
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 seems correct now, thanks.
…es (#2166) Implement translation via SPIR-V friendly calls, as: the LLVM instructions are not capable to accept target extension types; matrix arithmetic instructions require additional carry additional rules, which LLVM can not perform (for example while technically Add for vectors and (flattened) matrices is the same - yet for matrices we need to perform extra checks, also mul instruction is complitely different). As for now some BE would need to recognize and define what to do with a call to __spirv_FMul(matrixA, matrixB). Better option is to map such SPIR-V to an intrinsic or define an appropriate type in LLVM (hence defining rules for GEP and other instructions) , but it's off the table now. Original commit: KhronosGroup/SPIRV-LLVM-Translator@fdc961f
This is a compiler-time known accessor property which serves as an
optimization hint for a compiler on where exactly buffer was allocated.
This is needed when a board has multiple disjoint global memories that
must be managed explicitly by a programmer.
When the property is added as a template parameter of an accessor -
SemaSYCL will implicitly add an attribute to an OpenCL kernel parameters,
which were generated from SYCL kernel object. It is not allowed to use the
attribute explicitly in SYCL code.
When the attribute is applied, clang generates metadata attached to OpenCL
kernel. Number of values stored in the metadata is the same as number of kernel
parameters. Order of metadata values is following the order of pointer
kernel parameters. Metadata values are of an integer type and is being set
accordingly values passed through accessor property
buffer_location
.This values are mapped in hardware backend to the actual locations of buffers
(DDR, QDR etc). Default value passed in the metadata is '-1'.
Signed-off-by: Dmitry Sidorov dmitry.sidorov@intel.com