11#pragma once
22
3- #include " access_modes.h"
43#include " buffer.h"
54#include " cgf_diagnostics.h"
65#include " closure_hydrator.h"
@@ -40,6 +39,9 @@ namespace detail {
4039 using const_reference = const DataT&;
4140 };
4241
42+ template <access_mode Mode, access_mode NoInitMode, target Target>
43+ struct access_tag {};
44+
4345 struct accessor_testspy ;
4446
4547} // namespace detail
@@ -91,6 +93,13 @@ class buffer_allocation_window {
9193 friend class accessor ;
9294};
9395
96+ inline constexpr detail::access_tag<access_mode::read, access_mode::read, target::device> read_only;
97+ inline constexpr detail::access_tag<access_mode::write, access_mode::discard_write, target::device> write_only;
98+ inline constexpr detail::access_tag<access_mode::read_write, access_mode::discard_read_write, target::device> read_write;
99+ inline constexpr detail::access_tag<access_mode::read, access_mode::read, target::host_task> read_only_host_task;
100+ inline constexpr detail::access_tag<access_mode::write, access_mode::discard_write, target::host_task> write_only_host_task;
101+ inline constexpr detail::access_tag<access_mode::read_write, access_mode::discard_read_write, target::host_task> read_write_host_task;
102+
94103#define CELERITY_DETAIL_ACCESSOR_DEPRECATED_CTOR [[deprecated(" Creating accessor from const buffer is deprecated, capture buffer by reference instead" )]]
95104
96105/* *
@@ -106,8 +115,6 @@ class accessor<DataT, Dims, Mode, target::device> : public detail::accessor_base
106115 struct ctor_internal_tag {};
107116
108117 public:
109- static_assert (Mode != access_mode::atomic, " access_mode::atomic is not supported. Please use atomic_ref instead." );
110-
111118 accessor () noexcept = default ;
112119
113120 template <typename Functor>
@@ -195,7 +202,7 @@ class accessor<DataT, Dims, Mode, target::device> : public detail::accessor_base
195202 }
196203
197204 template <access_mode M = Mode>
198- inline std::conditional_t <detail::access::mode_traits::is_producer (M), DataT&, const DataT&> operator [](const id<Dims>& index) const {
205+ inline std::conditional_t <detail::is_producer_mode (M), DataT&, const DataT&> operator [](const id<Dims>& index) const {
199206#if CELERITY_ACCESSOR_BOUNDARY_CHECK
200207 // We currently don't support boundary checking for accessors created using accessor_testspy::make_device_accessor,
201208 // which does not set m_oob_indices.
@@ -220,35 +227,35 @@ class accessor<DataT, Dims, Mode, target::device> : public detail::accessor_base
220227 return detail::subscript<D>(*this , index);
221228 }
222229
223- template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), int > = 0 >
230+ template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), int > = 0 >
224231 inline operator DataT&() const {
225232 return *m_device_ptr;
226233 }
227234
228- template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), int > = 0 >
235+ template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), int > = 0 >
229236 inline operator const DataT&() const {
230237 return *m_device_ptr;
231238 }
232239
233240 // we provide operator* and operator-> in addition to SYCL's operator reference() as we feel it better represents the pointer semantics of accessors
234241
235242 template <access_mode M = Mode>
236- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), DataT&> operator *() const {
243+ inline std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), DataT&> operator *() const {
237244 return *m_device_ptr;
238245 }
239246
240247 template <access_mode M = Mode>
241- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), const DataT&> operator *() const {
248+ inline std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), const DataT&> operator *() const {
242249 return *m_device_ptr;
243250 }
244251
245252 template <access_mode M = Mode>
246- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), DataT*> operator ->() const {
253+ inline std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), DataT*> operator ->() const {
247254 return m_device_ptr;
248255 }
249256
250257 template <access_mode M = Mode>
251- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), const DataT*> operator ->() const {
258+ inline std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), const DataT*> operator ->() const {
252259 return m_device_ptr;
253260 }
254261
@@ -330,8 +337,6 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
330337 struct ctor_internal_tag {};
331338
332339 public:
333- static_assert (Mode != access_mode::atomic, " access_mode::atomic is not supported." );
334-
335340 accessor () noexcept = default ;
336341
337342 template <typename Functor>
@@ -345,7 +350,7 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
345350 * TODO: As of ComputeCpp 2.5.0 they do not support no_init prop, hence this constructor is needed along with discard deduction guide.
346351 * but once they do this should be replace for a constructor that takes a prop list as an argument.
347352 */
348- template <typename Functor, access_mode TagMode, access_mode M = Mode, typename = std::enable_if_t <detail::access::mode_traits::is_producer (M)>>
353+ template <typename Functor, access_mode TagMode, access_mode M = Mode, typename = std::enable_if_t <detail::is_producer_mode (M)>>
349354 accessor (buffer<DataT, Dims>& buff, handler& cgh, const Functor& rmfn, const detail::access_tag<TagMode, Mode, target::host_task> /* tag */ ,
350355 const property::no_init& /* no_init */ )
351356 : accessor(ctor_internal_tag{}, buff, cgh, rmfn) {}
@@ -378,7 +383,7 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
378383 * TODO: As of ComputeCpp 2.5.0 they do not support no_init prop, hence this constructor is needed along with discard deduction guide.
379384 * but once they do this should be replace for a constructor that takes a prop list as an argument.
380385 */
381- template <typename Functor, access_mode TagMode, access_mode M = Mode, typename = std::enable_if_t <detail::access::mode_traits::is_producer (M)>>
386+ template <typename Functor, access_mode TagMode, access_mode M = Mode, typename = std::enable_if_t <detail::is_producer_mode (M)>>
382387 CELERITY_DETAIL_ACCESSOR_DEPRECATED_CTOR accessor (const buffer<DataT, Dims>& buff, handler& cgh, const Functor& rmfn,
383388 const detail::access_tag<TagMode, Mode, target::host_task> /* tag */ , const property::no_init& /* no_init */ )
384389 : accessor(ctor_internal_tag{}, buff, cgh, rmfn) {}
@@ -417,7 +422,7 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
417422 }
418423
419424 template <access_mode M = Mode>
420- inline std::enable_if_t <detail::access::mode_traits::is_producer (M), DataT&> operator [](const id<Dims>& index) const {
425+ inline std::enable_if_t <detail::is_producer_mode (M), DataT&> operator [](const id<Dims>& index) const {
421426#if CELERITY_ACCESSOR_BOUNDARY_CHECK
422427 if (m_oob_indices != nullptr ) {
423428 const bool is_within_bounds_lo = all_true (index >= m_accessed_buffer_subrange.offset );
@@ -439,7 +444,7 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
439444 }
440445
441446 template <access_mode M = Mode>
442- inline std::enable_if_t <detail::access::mode_traits::is_pure_consumer (M), const DataT&> operator [](const id<Dims>& index) const {
447+ inline std::enable_if_t <detail::is_pure_consumer_mode (M), const DataT&> operator [](const id<Dims>& index) const {
443448 return m_host_ptr[get_linear_offset (index)];
444449 }
445450
@@ -448,35 +453,35 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
448453 return detail::subscript<D>(*this , index);
449454 }
450455
451- template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), int > = 0 >
456+ template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), int > = 0 >
452457 inline operator DataT&() const {
453458 return *m_host_ptr;
454459 }
455460
456- template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), int > = 0 >
461+ template <access_mode M = Mode, std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), int > = 0 >
457462 inline operator const DataT&() const {
458463 return *m_host_ptr;
459464 }
460465
461466 // we provide operator* and operator-> in addition to SYCL's operator reference() as we feel it better represents the pointer semantics of accessors
462467
463468 template <access_mode M = Mode>
464- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), DataT&> operator *() const {
469+ inline std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), DataT&> operator *() const {
465470 return *m_host_ptr;
466471 }
467472
468473 template <access_mode M = Mode>
469- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), const DataT&> operator *() const {
474+ inline std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), const DataT&> operator *() const {
470475 return *m_host_ptr;
471476 }
472477
473478 template <access_mode M = Mode>
474- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_producer (M), DataT*> operator ->() const {
479+ inline std::enable_if_t <Dims == 0 && detail::is_producer_mode (M), DataT*> operator ->() const {
475480 return m_host_ptr;
476481 }
477482
478483 template <access_mode M = Mode>
479- inline std::enable_if_t <Dims == 0 && detail::access::mode_traits::is_pure_consumer (M), const DataT*> operator ->() const {
484+ inline std::enable_if_t <Dims == 0 && detail::is_pure_consumer_mode (M), const DataT*> operator ->() const {
480485 return m_host_ptr;
481486 }
482487
0 commit comments