Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Conversation

@RossBrunton
Copy link
Contributor

Probably not the best example, let me know if there is anything I should change/improve.

Copy link
Member

@DuncanMcBain DuncanMcBain left a 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.

Copy link
Contributor

@keryell keryell left a 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 */
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

@cjdb cjdb left a 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;
Copy link
Contributor

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.

@RossBrunton
Copy link
Contributor Author

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).

@keryell
Copy link
Contributor

keryell commented Dec 11, 2018

While waiting for md_span in C++2c and other cool stuff, probably

void perform_doubling(const uint8_t input[NUM_ITEMS], uint8_t output[NUM_ITEMS]) const { 

can do it in this example.

@cjdb
Copy link
Contributor

cjdb commented Dec 13, 2018

While waiting for md_span in C++2c and other cool stuff, probably

void perform_doubling(const uint8_t input[NUM_ITEMS], uint8_t output[NUM_ITEMS]) const {

can do it in this example.

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.

@keryell
Copy link
Contributor

keryell commented Dec 13, 2018

While waiting for md_span in C++2c and other cool stuff, probably

void perform_doubling(const uint8_t input[NUM_ITEMS], uint8_t output[NUM_ITEMS]) const {

can do it in this example.

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.
Just that there is no explicit pointer in the code. :-)
Think about your ISO C++ SG20 here...
It is the same in SYCL examples. It does not male sense to advertise raw pointers, goto, asm, volatile, etc. as a first contact. :-)

@DuncanMcBain DuncanMcBain merged commit 09d0fc3 into codeplaysoftware:master Dec 14, 2018
@cjdb
Copy link
Contributor

cjdb commented Dec 14, 2018

It is the same in SYCL examples. It does not male sense to advertise raw pointers, goto, asm, volatile, etc. as a first contact. :-)

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.

Yes, behind the curtain it is the same.
Just that there is no explicit pointer in the code. :-)
Think about your ISO C++ SG20 here...

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

4 participants