Skip to content

Commit 52910f0

Browse files
committed
Re-define access_mode explicitly, remove access_modes.h header
The alias was a leftover from pre-USM backed Celerity. This also resolves the ambiguity between namespaces celerity::access and celerity::detail::access (now removed).
1 parent 482cdd7 commit 52910f0

25 files changed

+142
-207
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ endif()
220220

221221
# TODO move all non-public headers from "include" to "src"
222222
set(PUBLIC_HEADERS
223-
include/access_modes.h
224223
include/accessor.h
225224
include/buffer.h
226225
include/celerity.h

include/access_modes.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

include/accessor.h

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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

include/buffer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
#include "ranges.h"
44
#include "runtime.h"
5-
#include "sycl_wrappers.h"
65
#include "tracy.h"
6+
#include "types.h"
77

88
#include <memory>
99

10-
#include <sycl/sycl.hpp>
11-
1210

1311
namespace celerity {
1412

include/cgf.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "range_mapper.h"
66
#include "ranges.h"
77
#include "reduction.h"
8-
#include "sycl_wrappers.h"
98
#include "types.h"
109

1110
#include <functional>
@@ -29,7 +28,7 @@ struct task_geometry {
2928

3029
struct buffer_access {
3130
buffer_id bid = -1;
32-
access_mode mode = access_mode::atomic;
31+
access_mode mode = access_mode::read;
3332
std::unique_ptr<range_mapper_base> range_mapper;
3433
};
3534

include/closure_hydrator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "grid.h"
44
#include "ranges.h"
5-
#include "sycl_wrappers.h"
65
#include "types.h"
76
#include "version.h"
87

include/fence.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
#include "host_object.h"
66
#include "range_mapper.h"
77
#include "runtime.h"
8-
#include "sycl_wrappers.h"
98
#include "tracy.h"
9+
#include "types.h"
1010
#include "utils.h"
1111

1212
#include <future>
1313
#include <memory>
1414
#include <type_traits>
15-
#include <vector>
1615

1716

1817
namespace celerity::detail {

include/range_mapper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <type_traits>
1111

1212
#include <fmt/format.h>
13-
#include <sycl/sycl.hpp>
1413

1514

1615
namespace celerity {

include/recorders.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "nd_memory.h"
88
#include "pilot.h"
99
#include "ranges.h"
10-
#include "sycl_wrappers.h"
1110
#include "task.h"
1211
#include "types.h"
1312

include/sycl_wrappers.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,14 @@
55
#include <sycl/sycl.hpp>
66

77

8-
namespace celerity {
9-
10-
using access_mode = sycl::access::mode;
11-
12-
enum class target {
13-
device,
14-
host_task,
15-
};
16-
17-
} // namespace celerity
18-
198
namespace celerity::detail {
209

21-
template <access_mode Mode, access_mode NoInitMode, target Target>
22-
struct access_tag {};
23-
2410
using memory_scope_ut = std::underlying_type_t<sycl::memory_scope>;
2511

2612
} // namespace celerity::detail
2713

2814
namespace celerity {
2915

30-
inline constexpr detail::access_tag<access_mode::read, access_mode::read, target::device> read_only;
31-
inline constexpr detail::access_tag<access_mode::write, access_mode::discard_write, target::device> write_only;
32-
inline constexpr detail::access_tag<access_mode::read_write, access_mode::discard_read_write, target::device> read_write;
33-
inline constexpr detail::access_tag<access_mode::read, access_mode::read, target::host_task> read_only_host_task;
34-
inline constexpr detail::access_tag<access_mode::write, access_mode::discard_write, target::host_task> write_only_host_task;
35-
inline constexpr detail::access_tag<access_mode::read_write, access_mode::discard_read_write, target::host_task> read_write_host_task;
36-
3716
using sycl::property_list;
3817

3918
namespace property {
@@ -64,4 +43,5 @@ using decorated_global_ptr = sycl::global_ptr<T>;
6443

6544
template <typename T>
6645
using decorated_local_ptr = sycl::local_ptr<T>;
46+
6747
} // namespace celerity

0 commit comments

Comments
 (0)