|
| 1 | +.. SPDX-FileCopyrightText: 2019-2022 Intel Corporation |
| 2 | +.. SPDX-FileCopyrightText: Contributors to the oneAPI Specification project. |
| 3 | +.. |
| 4 | +.. SPDX-License-Identifier: CC-BY-4.0 |
| 5 | +
|
| 6 | +Buffer Wrappers |
| 7 | +--------------- |
| 8 | + |
| 9 | +.. code:: cpp |
| 10 | +
|
| 11 | + // Defined in <oneapi/dpl/iterator> |
| 12 | +
|
| 13 | + namespace oneapi { |
| 14 | + namespace dpl { |
| 15 | +
|
| 16 | + template < typename T, typename AllocatorT, typename TagT > |
| 17 | + /*unspecified*/ begin( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 18 | + TagT tag = sycl::read_write ); |
| 19 | +
|
| 20 | + template < typename T, typename AllocatorT, typename TagT > |
| 21 | + /*unspecified*/ begin( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 22 | + TagT tag, sycl::property::no_init ); |
| 23 | +
|
| 24 | + template < typename T, typename AllocatorT > |
| 25 | + /*unspecified*/ begin( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 26 | + sycl::property::no_init ); |
| 27 | +
|
| 28 | +
|
| 29 | + template < typename T, typename AllocatorT, typename TagT > |
| 30 | + /*unspecified*/ end( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 31 | + TagT tag = sycl::read_write ); |
| 32 | +
|
| 33 | + template < typename T, typename AllocatorT, typename TagT > |
| 34 | + /*unspecified*/ end( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 35 | + TagT tag, sycl::property::no_init ); |
| 36 | +
|
| 37 | + template < typename T, typename AllocatorT > |
| 38 | + /*unspecified*/ end( sycl::buffer<T, /*dim=*/1, AllocatorT> buf, |
| 39 | + sycl::property::no_init ); |
| 40 | +
|
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | +``oneapi::dpl::begin`` and ``oneapi::dpl::end`` are helper functions |
| 45 | +for passing `SYCL`_ buffers to oneDPL algorithms. |
| 46 | +These functions accept a buffer and return an object |
| 47 | +of an unspecified type that satisfies the following requirements: |
| 48 | + |
| 49 | +- it is ``CopyConstructible``, ``CopyAssignable``, and comparable |
| 50 | + with operators ``==`` and ``!=``; |
| 51 | +- the following expressions are valid: ``a + n``, ``a - n``, |
| 52 | + ``a - b``, where ``a`` and ``b`` are objects of the type, |
| 53 | + and ``n`` is an integer value; |
| 54 | +- it provides the ``get_buffer()`` method that returns the buffer |
| 55 | + passed to the ``begin`` or ``end`` function. |
| 56 | + |
| 57 | +When invoking an algorithm, the buffer passed to ``begin`` should be the same |
| 58 | +as the buffer passed to ``end``. Otherwise, the behavior is undefined. |
| 59 | + |
| 60 | +SYCL deduction tags (the ``TagT`` parameters) and ``sycl::property::no_init`` |
| 61 | +allow to specify an access mode to be used by algorithms for accessing the buffer. |
| 62 | +The mode serves as a hint, and can be overridden depending on semantics of the algorithm. |
| 63 | +When invoking an algorithm, the same access mode arguments should be used |
| 64 | +for ``begin`` and ``end``. Otherwise, the behavior is undefined. |
| 65 | + |
| 66 | +.. code:: cpp |
| 67 | + |
| 68 | + using namespace oneapi; |
| 69 | + auto buf_begin = dpl::begin(buf, sycl::write_only); |
| 70 | + auto buf_end_1 = dpl::end(buf, sycl::write_only); |
| 71 | + auto buf_end_2 = dpl::end(buf, sycl::write_only, sycl::no_init); |
| 72 | + dpl::fill(dpl::execution::dpcpp_default, buf_begin, buf_end_1, 42); // allowed |
| 73 | + dpl::fill(dpl::execution::dpcpp_default, buf_begin, buf_end_2, 42); // not allowed |
| 74 | +
|
| 75 | +.. _`SYCL`: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html |
0 commit comments