codeplaysoftware / standards-proposals

Repository for publicly sharing proposals in various standards groups
Apache License 2.0
27 stars 17 forks source link

CP024 Default placeholders #122

Open ProGTX opened 4 years ago

ProGTX commented 4 years ago
  1. Deprecate access::placeholder
  2. Extend placeholder functionality to ignore template parameter
    • Still applies only to global and constant buffers
  3. Updated handler::require
  4. New accessor constructors
    • Default constructor
    • From a buffer, 0-dim
    • From a buffer, ranged
  5. New access member functions
    • is_null
    • has_handler
  6. Vector addition example
keryell commented 4 years ago

That looks good.

A minor point I see is that before by default an accessor constructor without a CGH was a host accessor. Now it is no longer the case, since it might be a default placeholder accessor to be used in a kernel instead.

ProGTX commented 4 years ago

A minor point I see is that before by default an accessor constructor without a CGH was a host accessor. Now it is no longer the case, since it might be a default placeholder accessor to be used in a kernel instead.

@keryell You're right that the default when constructing an accessor will now be a placeholder instead of a host accessor, but this is only really important for CTAD, otherwise you'd still need to specify target::host_buffer. Allowing CTAD to determine either a device accessor or a host accessor based on whether the handler was provided seems dangerous to us - it is already a common mistake to call get_access without a handler, which gives you a host accessor in a command group, which is UB. At least with a placeholder you still have the option of calling require (which is valid for placeholders and non-placeholders according to this proposal), which gets rid of the UB.

There is even some interest in making host accessors a separate type, as an extension of the work here and in https://github.com/codeplaysoftware/standards-proposals/pull/100.

keryell commented 4 years ago

Allowing CTAD to determine either a device accessor or a host accessor based on whether the handler was provided seems dangerous to us - it is already a common mistake to call get_access without a handler, which gives you a host accessor in a command group, which is UB.

The compiler should warn about it at least. But this is what I do in all the example I show because it is shorter...

ProGTX commented 4 years ago

The compiler should warn about it at least. But this is what I do in all the example I show because it is shorter...

I think that calling buf.get_access<mode>() is still fine, I'm just saying that sometimes this happens because the user forgets to pass the handler - they wanted a device accessor, but got a host one instead, so with new proposals I'm keen on making more of a distinction between host and device accessors. I'm not sure if the compiler has enough information to warn on this.