-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL][FPGA] Initial implementation of pipes feature #292
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
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 looks like a super-useful feature on FPGA.
I have nevertheless a few remarks.
OpenCL 2.2 program pipe representation in SPIR-V | ||
================================================ | ||
|
||
The SPIR-V program pipe representation is leveraged, to be an underlying |
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.
Spurious ,
.
I do not know if "leveraged" is good here. Do you improve SPIR-V or you just recycle it for another purpose?
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.
SPIR-V representation is re-used.
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.
Then clarify...
|
||
Global pipe creation itself is being done by SPIR-V built-in | ||
__spirv_CreatePipeFromPipeStorage_{read|write} which has no OpenCL | ||
representation and therefore stays in IR before and after SPIR-V tool-chain as: |
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.
Unclear.
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 rewrote this one, please check it.
sycl/include/CL/sycl/pipes.hpp
Outdated
|
||
// Writing to pipe is lowered to SPIR-V instruction OpWritePipe via SPIR-V | ||
// friendly LLVM IR. | ||
static void write(dataT Data, bool &Success) { |
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.
static bool write(const dataT &Data)
instead?
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!
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 const reference is good. The status return code move to returned bool makes the signatures of read and write differ more than I would like. Read returns the data type in both cases. How strongly do you think that write should return bool success status, while read returns the data and takes a status ref arg?
while (!SuccessCode) | ||
write_acc[idx] = Pipe::read(SuccessCode); | ||
}); | ||
}); |
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.
Is there any user-friendly documentation on how this Pipe extension works?
One of the things that confuses me is that, in the test above, there is nothing preventing a SYCL runtime to execute goo_nb
before foo_nb
, since the intersection of the requirements is empty and SYCL queues are out-of-order.
Is that relevant in your case? I figure for an FPGA it doesn't matter, but there is nothing in this extension that suggest it shouldn't work on anything that is not an FPGA but supports pipes.
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.
Is there any user-friendly documentation on how this Pipe extension works?
It's going to be published. Don't really know when.
There is SYCL 2.2 spec (which is deprecated, but yet can provide some information). Also this implementation doesn't follows 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 figure for an FPGA it doesn't matter, but there is nothing in this extension that suggest it shouldn't work on anything that is not an FPGA but supports pipes.
Yeah, I shall put some code in device information quarrying.
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.
We'll publish the extension document soon in this repo
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 problem is to come with a terse API and at the same time not giving up any performance on the table...
Perhaps a more explicit naming in the case of (non-)blocking? Adding a tag to pick another overload? Adding a template parameter?...
I understand that relying on an accessor
to encode the blocking behavior like in SYCL 2.2 might be a too heavy syntax....
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 pipes extension at SYCL level is described in the document, currently as a pending PR, at:
#635
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.
Ah thank you for the cross-reference. It prevents me from looking for 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.
Current documentation mostly covers SPIR-V and LLVM IR levels.
Please describe how this feature is represented and used (with examples) at SYCL level.
f97d84a
to
30ae85f
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.
Interesting!
Still a few remarks.
cgh.parallel_for<class foo_nb>(range<1> { dataSize }, [=](id<1> idx) { | ||
bool SuccessCode = false; | ||
while (!SuccessCode) | ||
Pipe::write(42, SuccessCode); // Write '42' into a some_pipe allocated |
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.
What is the memory model of a pipe
in the case you are executing it in a parallel_for
and not a single_task
?
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 you expect some independent-forward-progress here in the case dataSize > 1
(the capacity of the pipe...)?
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, I expect that. I should re-write the example code into:
cgh.parallel_for<class bar>(range<1> { 1024 }, [=](id<1> idx) { write_acc[idx] = my_pipe::read(); });
OpenCL analog of the code above is:
__kernel void foo(__read_only pipe uint in_pipe, __global uint *dst) { int gid = get_global_id(0); read_pipe(in_pipe, &dst[gid]); }
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.
But it is illegal OpenCL code in general. You have to use pipe reservation for this and and I am not sure we want this anyway on FPGA...
So the assumptions are probably to be described in the document describing the extension.
What happens if there are multiple work-group on different CU using the same pipe input or output?
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.
But it is illegal OpenCL code in general. You have to use pipe reservation for this and and I am not sure we want this anyway on FPGA...
You are right.
What happens if there are multiple work-group on different CU using the same pipe input or output?
... to be described in the document describing the extension :) I added a quote from there:
Accesses to a single pipe within two work-items of the same kernel, and/or threads of the host program: No ordering guarantees are made on the order of pipe operations across device work-items or host threads. For example, if two work-items executing a kernel write to a pipe, there are no guarantees that the work-item with lower id (for any definition of id) executes before the pipe write from a higher id. The execution order of work-items executing a kernel are not defined by SYCL, may be dynamically reordered, and may not be deterministic. If ordering guarantees are required across work-items and/or host threads, synchronization mechanisms such as atomics or barriers must be used.
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.
Simple example of SYCL program | ||
============================== | ||
.. code:: cpp | ||
using Pipe = pipe<class some_pipe, int, 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.
Is it legal to have a local class some_pipe
declaration like here?
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 I don't try to use it after - yes. It's a forward declaration that adds appropriate mangling for fields and methods of the template class pipe.
fffd69f
to
c627b78
Compare
clang/lib/Parse/ParseDecl.cpp
Outdated
// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should | ||
// support the "pipe" word as identifier. | ||
Tok.getIdentifierInfo()->revertTokenIDToIdentifier(); | ||
goto DoneWithDeclSpec; | ||
} | ||
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy); | ||
break; | ||
case tok::kw___pipe: | ||
// __pipe is defined only for SYCL kernel language |
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.
Shouldn't we add a check for that?
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. If this keyword appears in any other language, clang already will report it be unknown keyword.
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, but if there is __pipe
used in an existing library, unrelated to SYCL?
But do we need such a keyword?
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.
Fixed.
But do we need such a keyword?
Will be reworked as attribute. Or you suggest to do some forward declaration expecting the translator to do its work?
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 the attribute is fine.
81c2eff
to
ec15072
Compare
fdacf2e
to
ad598c1
Compare
@keryell, @Ruyk, @asavonic, please, "resolve conversations", which do not require follow-up actions. I think there are at least three issues left to resolve (updated by @keryell last Friday). |
Pipe types construction rely on keywords mechanism. Consider following code: __read_only __pipe int p; It declares a read only pipe with integer layout. In LLVM IR this type is seen as 'pipe_ro_t'. Write only pipe type will be looking like 'pipe_wo_t'. Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
ad598c1
to
a5f9027
Compare
Pipe are supported via generation SPIR-V friendly IR and lowering it directly to SPIR-V code. non-blocking pipes are supported; blocking pipes are supported as a workaround. Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
a5f9027
to
cb9c774
Compare
@keryell, are you okay to merge this PR? |
Signed-off-by: Michael Kinsner <michael.kinsner@intel.com>
No description provided.