- Notifications
You must be signed in to change notification settings - Fork 89
Added a sample file demonstrating placeholder accessors (fixes #123) #162
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.
So this is good but it looks a little weird. This is because you can actually use function objects as kernel functions already, but this doesn't really do that (see using-function-objects for an example). If you had that sort of code you'd not need to copy the accessors to avoid copying this, as one benefit.
We use them in SYCL-DNN to be able to construct buffers in the user-side templated library, then pass them to our code. I don't expect you'd be able to do anything like this in a sample, but maybe gives you more of an idea of what they're used for. The equivalent here I suppose would be choosing an accessor to actually double at runtime, though again, this might be synthetic.
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.
Nice to have an example of place holder accessor!
Thank you for this.
Perhaps the example could be simplified a little bit.
| class Doubler { | ||
| /* These are placeholder accessors so we can default construct Doubler, these | ||
| * accessors do not have a buffer associated with them yet. It will be | ||
| * attached during the command group */ |
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 unsure it is a good motivation for using a placeholder accessor in an example...
| | ||
| /* Can't pass "this" into the kernel - Create local copies */ | ||
| auto in_accessor = this->in_accessor; | ||
| auto out_accessor = this->out_accessor; |
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, this syntactic noise is annoying...
A possible alternative is probably to have something like
myQueue.submit([&, in_accessor = this->in_accessor, out_accessor = this->out_accessor](handler& cgh) { But perhaps replacing the class by a simple function for a simple example is simpler?
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'd suggest moving these two lines inside this lambda for access control: that way they can't accidentally be used after your submit call.
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 overall, thanks for contributing!
| | ||
| /* Can't pass "this" into the kernel - Create local copies */ | ||
| auto in_accessor = this->in_accessor; | ||
| auto out_accessor = this->out_accessor; |
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'd suggest moving these two lines inside this lambda for access control: that way they can't accidentally be used after your submit call.
cdbca6a to fbf637e Compare | With regards to perform_doubling taking in pointers, I'm not sure how I could do that generically without requiring them to take in std::arrays (which would mean you couldn't use this class with, a std::vector or something). |
fbf637e to bdbeb7a Compare | While waiting for can do it in this example. |
void perform_doubling(const uint8_t input[NUM_ITEMS], uint8_t output[NUM_ITEMS]) const {
This is no different to using a pointer (thanks decay-to-pointer rules!); I'd suggest sticking with pointer syntax in this case. That way, it remains clear that we're dealing with pointers. |
Yes, behind the curtain it is the same. |
Raw, non-owning pointers are still okay (references are preferred, but they can't be used in this situation). It's only advised that raw owning pointers be abolished.
Relying on an archaic language feature (from C) that catches many beginners by surprise to avoid pointers is not something that I'd say is beginner friendly. Happy to discuss further, but probably best if we take this to an email and report back with a summary. |
Probably not the best example, let me know if there is anything I should change/improve.