standards-proposals icon indicating copy to clipboard operation
standards-proposals copied to clipboard

CP024 Default placeholders

Open ProGTX opened this issue 5 years ago • 4 comments

  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

ProGTX avatar Mar 09 '20 08:03 ProGTX

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.

keryell avatar Mar 10 '20 19:03 keryell

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.

ProGTX avatar Mar 13 '20 10:03 ProGTX

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

keryell avatar Mar 13 '20 18:03 keryell

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.

ProGTX avatar Mar 17 '20 15:03 ProGTX