Skip to content

Commit d3bdea1

Browse files
v-klochkovbader
authored andcommitted
[SYCL] Added a constructor to local accessor, fixed accessor_impl constructors
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 069512d commit d3bdea1

File tree

1 file changed

+48
-51
lines changed

1 file changed

+48
-51
lines changed

sycl/include/CL/sycl/accessor.hpp

+48-51
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,8 @@ SYCL_ACCESSOR_IMPL(!isTargetHostAccess(accessTarget) &&
172172

173173
dataT *Data;
174174

175-
// Device accessors must be associated with a command group handler.
176-
// The handler though can be nullptr at the creation point if the
177-
// accessor is a placeholder accessor.
178-
accessor_impl(dataT *Data, handler *Handler = nullptr)
179-
: Data(Data)
180-
{}
175+
// Device accessor constructor.
176+
accessor_impl(dataT *Data) : Data(Data) {}
181177

182178
// Returns the number of accessed elements.
183179
size_t get_count() const { return 1; }
@@ -216,12 +212,9 @@ SYCL_ACCESSOR_IMPL(!isTargetHostAccess(accessTarget) &&
216212
range<dimensions> MemRange;
217213
id<dimensions> Offset;
218214

219-
// Device accessors must be associated with a command group handler.
220-
// The handler though can be nullptr at the creation point if the
221-
// accessor is a placeholder accessor.
215+
// Device accessor constructor.
222216
accessor_impl(dataT * Data, range<dimensions> AccessRange,
223-
range<dimensions> MemRange, handler *Handler = nullptr,
224-
id<dimensions> Offset = {})
217+
range<dimensions> MemRange, id<dimensions> Offset = {})
225218
: Data(Data), AccessRange(AccessRange), MemRange(MemRange),
226219
Offset(Offset) {}
227220

@@ -259,12 +252,10 @@ SYCL_ACCESSOR_IMPL(accessTarget == access::target::local &&
259252

260253
dataT *Data;
261254

262-
accessor_impl(handler * Handler)
263-
: ByteSize(sizeof(dataT))
264-
{
255+
accessor_impl(handler &Handler)
256+
: ByteSize(sizeof(dataT)) {
265257
#ifndef __SYCL_DEVICE_ONLY__
266-
assert(Handler != nullptr && "Handler is nullptr");
267-
if (Handler->is_host()) {
258+
if (Handler.is_host()) {
268259
dataBuf = std::make_shared<vector_class<dataT>>(1);
269260
Data = dataBuf->data();
270261
}
@@ -315,12 +306,11 @@ SYCL_ACCESSOR_IMPL(accessTarget == access::target::local &&
315306
// duplication and complication of the code even more.
316307
id<dimensions> Offset;
317308

318-
accessor_impl(range<dimensions> Range, handler * Handler)
309+
accessor_impl(range<dimensions> Range, handler &Handler)
319310
: AccessRange(Range), MemRange(Range),
320311
ByteSize(Range.size() * sizeof(dataT)) {
321312
#ifndef __SYCL_DEVICE_ONLY__
322-
assert(Handler != nullptr && "Handler is nullptr");
323-
if (Handler->is_host()) {
313+
if (Handler.is_host()) {
324314
dataBuf = std::make_shared<vector_class<dataT>>(Range.size());
325315
Data = dataBuf->data();
326316
}
@@ -723,10 +713,12 @@ class accessor
723713
Dimensions == 0),
724714
buffer<DataT, 1>>::type &bufferRef)
725715
#ifdef __SYCL_DEVICE_ONLY__
726-
: impl((dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr) {
716+
: impl(reinterpret_cast<_ValueType *>(
717+
detail::getSyclObjImpl(bufferRef)->BufPtr)) {
727718
#else
728719
: impl(std::make_shared<_ImplT>(
729-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr)) {
720+
reinterpret_cast<_ValueType *>(
721+
detail::getSyclObjImpl(bufferRef)->BufPtr))) {
730722
#endif
731723
auto BufImpl = detail::getSyclObjImpl(bufferRef);
732724
if (AccessTarget == access::target::host_buffer) {
@@ -765,11 +757,11 @@ class accessor
765757
// Pass nullptr as a pointer to mem and use buffers from the ctor
766758
// arguments to avoid the need in adding utility functions for
767759
// dummy/default initialization of range fields.
768-
: impl(nullptr, (handler *)nullptr) {}
760+
: impl(nullptr) {}
769761
#else // !__SYCL_DEVICE_ONLY__
770762
: impl(std::make_shared<_ImplT>(
771-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr,
772-
&commandGroupHandlerRef)) {
763+
reinterpret_cast<_ValueType *>(
764+
detail::getSyclObjImpl(bufferRef)->BufPtr))) {
773765
auto BufImpl = detail::getSyclObjImpl(bufferRef);
774766
if (BufImpl->OpenCLInterop && !BufImpl->isValidAccessToMem(accessMode)) {
775767
throw cl::sycl::runtime_error(
@@ -804,11 +796,13 @@ class accessor
804796
Dimensions > 0),
805797
buffer<DataT, Dimensions>>::type &bufferRef)
806798
#ifdef __SYCL_DEVICE_ONLY__
807-
: impl((dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr,
799+
: impl(reinterpret_cast<_ValueType *>(
800+
detail::getSyclObjImpl(bufferRef)->BufPtr),
808801
bufferRef.MemRange, bufferRef.MemRange) {
809802
#else
810803
: impl(std::make_shared<_ImplT>(
811-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr,
804+
reinterpret_cast<_ValueType *>(
805+
detail::getSyclObjImpl(bufferRef)->BufPtr),
812806
bufferRef.MemRange, bufferRef.MemRange)) {
813807
#endif
814808
auto BufImpl = detail::getSyclObjImpl(bufferRef);
@@ -848,13 +842,12 @@ class accessor
848842
// Pass nullptr as a pointer to mem and use buffers from the ctor
849843
// arguments to avoid the need in adding utility functions for
850844
// dummy/default initialization of range fields.
851-
: impl(nullptr, bufferRef.MemRange, bufferRef.MemRange,
852-
&commandGroupHandlerRef) {}
845+
: impl(nullptr, bufferRef.MemRange, bufferRef.MemRange) {}
853846
#else
854847
: impl(std::make_shared<_ImplT>(
855-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr,
856-
bufferRef.MemRange, bufferRef.MemRange,
857-
&commandGroupHandlerRef)) {
848+
reinterpret_cast<_ValueType *>(
849+
detail::getSyclObjImpl(bufferRef)->BufPtr),
850+
bufferRef.MemRange, bufferRef.MemRange)) {
858851
auto BufImpl = detail::getSyclObjImpl(bufferRef);
859852
if (BufImpl->OpenCLInterop && !BufImpl->isValidAccessToMem(accessMode)) {
860853
throw cl::sycl::runtime_error(
@@ -899,8 +892,9 @@ class accessor
899892
: impl(nullptr, Range, bufferRef.MemRange, Offset) {}
900893
#else // !__SYCL_DEVICE_ONLY__
901894
: impl(std::make_shared<_ImplT>(
902-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr, Range,
903-
bufferRef.MemRange, Offset)) {
895+
reinterpret_cast<_ValueType *>(
896+
detail::getSyclObjImpl(bufferRef)->BufPtr),
897+
Range, bufferRef.MemRange, Offset)) {
904898
auto BufImpl = detail::getSyclObjImpl(bufferRef);
905899
if (AccessTarget == access::target::host_buffer) {
906900
simple_scheduler::Scheduler::getInstance()
@@ -941,12 +935,12 @@ class accessor
941935
// arguments to avoid the need in adding utility functions for
942936
// dummy/default initialization of range<Dimensions> and
943937
// id<Dimension> fields.
944-
: impl(nullptr, Range, bufferRef.MemRange,
945-
&commandGroupHandlerRef, Offset) {}
938+
: impl(nullptr, Range, bufferRef.MemRange, Offset) {}
946939
#else // !__SYCL_DEVICE_ONLY__
947940
: impl(std::make_shared<_ImplT>(
948-
(dataT *)detail::getSyclObjImpl(bufferRef)->BufPtr, Range,
949-
bufferRef.MemRange, &commandGroupHandlerRef, Offset)) {
941+
reinterpret_cast<_ValueType *>(
942+
detail::getSyclObjImpl(bufferRef)->BufPtr),
943+
Range, bufferRef.MemRange, Offset)) {
950944
auto BufImpl = detail::getSyclObjImpl(bufferRef);
951945
if (BufImpl->OpenCLInterop && !BufImpl->isValidAccessToMem(accessMode)) {
952946
throw cl::sycl::runtime_error(
@@ -958,24 +952,27 @@ class accessor
958952
}
959953
#endif // !__SYCL_DEVICE_ONLY__
960954

961-
// TODO:
962955
// local accessor ctor #1
963-
// accessor(handler &);
956+
// accessor(handler &);
964957
// Available only when:
965958
// AccessTarget == access::target::local && Dimensions == 0
966-
//
967-
// template <typename DataT = dataT, int Dimensions = dimensions,
968-
// access::mode AccessMode = accessMode,
969-
// access::target AccessTarget = accessTarget,
970-
// access::placeholder IsPlaceholder = isPlaceholder>
971-
// accessor(typename std::enable_if<(AccessTarget == access::target::local &&
972-
// Dimensions == 0), handler>::type &commandGroupHandlerRef);
973-
959+
template <typename DataT = dataT, int Dimensions = dimensions,
960+
access::mode AccessMode = accessMode,
961+
access::target AccessTarget = accessTarget,
962+
access::placeholder IsPlaceholder = isPlaceholder>
963+
accessor(typename std::enable_if<
964+
(AccessTarget == access::target::local &&
965+
Dimensions == 0), handler>::type &commandGroupHandlerRef)
966+
#ifdef __SYCL_DEVICE_ONLY__
967+
: impl(commandGroupHandlerRef) {}
968+
#else
969+
: impl(std::make_shared<_ImplT>(commandGroupHandlerRef)) {}
970+
#endif
974971

975972
// local accessor ctor #2
976-
// accessor(range allocationSize, handler &);
973+
// accessor(range allocationSize, handler &);
977974
// Available only when:
978-
// AccessTarget == access::target::local && Dimensions => 0
975+
// AccessTarget == access::target::local && Dimensions > 0
979976
template <typename DataT = dataT, int Dimensions = dimensions,
980977
access::mode AccessMode = accessMode,
981978
access::target AccessTarget = accessTarget,
@@ -985,10 +982,10 @@ class accessor
985982
range<Dimensions>>::type allocationSize,
986983
handler &commandGroupHandlerRef)
987984
#ifdef __SYCL_DEVICE_ONLY__
988-
: impl(allocationSize, &commandGroupHandlerRef) {}
985+
: impl(allocationSize, commandGroupHandlerRef) {}
989986
#else
990987
: impl(std::make_shared<_ImplT>(allocationSize,
991-
&commandGroupHandlerRef)) {}
988+
commandGroupHandlerRef)) {}
992989
#endif
993990

994991
accessor(const accessor &rhs) = default;

0 commit comments

Comments
 (0)