Skip to content

Commit

Permalink
Merge pull request #104 from codeplaysoftware/update-default-buffer-p…
Browse files Browse the repository at this point in the history
…roposal

Update default-ctor proposal
  • Loading branch information
DuncanMcBain authored Nov 18, 2019
2 parents f103b4a + 5e1db84 commit e13cc9d
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions default-constructed-buffers/default-constructed-buffers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Date of Creation | 2019-08-20
Target | SYCL 1.2.1
Status | _Draft_
Author | Duncan McBain [Duncan McBain](mailto:[email protected])
Contributors | Duncan McBain, [Gordon Brown](mailto:[email protected])
Contributors | Duncan McBain, [Gordon Brown](mailto:[email protected]), [Ruyman Reyes](mailto:[email protected])

## Description

Expand All @@ -34,7 +34,8 @@ aid their use in this style of generic interface.
## Proposal
The `cl::sycl::buffer` class should be augmented with an additional constructor
that takes no arguments, which initialises the buffer with a zero-size range.
that takes no arguments, which default-constructs the buffer in an
implementation-defined manner.
```c++
namespace cl {
namespace sycl {
Expand All @@ -43,7 +44,7 @@ typename AllocatorT = cl::sycl::buffer_allocator>
class buffer {
buffer();
bool is_valid() const noexcept;
bool has_storage() const noexcept;
explicit operator bool() const noexcept;
};
Expand All @@ -53,18 +54,21 @@ class buffer {
The template arguments should remain the same, so that the argument can be
rebound to a new `buffer` instance later using the copy constructor.

The `is_valid()` call would allow the programmer to query whether or not
the buffer can be used, i.e. whether or not it was constructed with a range of
size zero. The explicit conversion operator would call this same function but
allow its use in `if` statements.
The `has_storage()` call would allow the programmer to query whether or not
the buffer can be used, i.e. whether or not it was default-constructed. The
explicit conversion operator would call this same function but allow its use
in `if` statements.

Requesting access from a default-constructed buffer should throw an exception.
It is not meaningful to use a zero-sized allocation on-device. Since there is
no allocation associated with the `buffer`, `cl::sycl::buffer::set_final_data`
and `cl::sycl::buffer::set_write_back` should behave as if the `buffer` had a
final pointer of `nullptr` at all times. The other functions in the `buffer`
API should behave as though the buffer were constructed with a `range` of size
zero and otherwise behave normally.
It is not meaningful to use a default-constructed buffer. Since there
is no allocation associated with a default-constructed `buffer`,
`cl::sycl::buffer::set_final_data` and `cl::sycl::buffer::set_write_back`
should behave as if the `buffer` had a final pointer of `nullptr` at all times.
The other functions in the `buffer` API should behave as though the buffer were
constructed with a `range` of size zero and otherwise behave normally.

Explicitly constructing a buffer with a range of zero is not allowed. This does
not correspond to a valid allocation.

## Sample code

Expand Down

0 comments on commit e13cc9d

Please sign in to comment.