Skip to content

Commit d3b6a49

Browse files
alexeyvoronov-intelbader
authored andcommitted
[SYCL] Delete range class default constructor (#645)
The SYCL specification does not provide a default constructor for the range class. Signed-off-by: Alexey Bader <[email protected]> Signed-off-by: Alexey Voronov <[email protected]>
1 parent 8c7d0e9 commit d3b6a49

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace detail {
158158
// DefaultValue, truncation just removes extra values.
159159
template <int NewDim, int DefaultValue, template <int> class T, int OldDim>
160160
static T<NewDim> convertToArrayOfN(T<OldDim> OldObj) {
161-
T<NewDim> NewObj;
161+
T<NewDim> NewObj = InitializedVal<NewDim, T>::template get<0>();
162162
const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
163163
for (int I = 0; I < CopyDims; ++I)
164164
NewObj[I] = OldObj[I];
@@ -719,7 +719,10 @@ class accessor :
719719

720720
public:
721721
// Default constructor for objects later initialized with __init member.
722-
accessor() : impl({}) {}
722+
accessor()
723+
: impl({}, detail::InitializedVal<AdjustedDim, range>::template get<0>(),
724+
detail::InitializedVal<AdjustedDim, range>::template get<0>()) {}
725+
723726
#else
724727
using AccessorBaseHost::getAccessRange;
725728
using AccessorBaseHost::getMemoryRange;
@@ -1023,7 +1026,8 @@ class accessor<DataT, Dimensions, AccessMode, access::target::local,
10231026

10241027
public:
10251028
// Default constructor for objects later initialized with __init member.
1026-
accessor() : impl({}) {}
1029+
accessor()
1030+
: impl(detail::InitializedVal<AdjustedDim, range>::template get<0>()) {}
10271031

10281032
private:
10291033
PtrType getQualifiedPtr() const { return MData; }

sycl/include/CL/sycl/detail/accessor_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ template <int Dims> class AccessorImplDevice {
4545

4646
template <int Dims> class LocalAccessorBaseDevice {
4747
public:
48-
LocalAccessorBaseDevice(sycl::range<Dims> Size) : AccessRange(Size) {}
48+
LocalAccessorBaseDevice(sycl::range<Dims> Size)
49+
: AccessRange(Size),
50+
MemRange(InitializedVal<Dims, range>::template get<0>()) {}
4951
// TODO: Actually we need only one field here, but currently compiler requires
5052
// all of them.
5153
range<Dims> AccessRange;

sycl/include/CL/sycl/detail/cg.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class HostKernel : public HostKernelBase {
202202
runOnHost(const NDRDescT &NDRDesc) {
203203
size_t XYZ[3] = {0};
204204
sycl::id<Dims> ID;
205-
sycl::range<Dims> Range;
205+
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
206206
for (int I = 0; I < Dims; ++I)
207207
Range[I] = NDRDesc.GlobalSize[I];
208208

@@ -226,7 +226,7 @@ class HostKernel : public HostKernelBase {
226226
typename std::enable_if<
227227
std::is_same<ArgT, item<Dims, /*Offset=*/true>>::value>::type
228228
runOnHost(const NDRDescT &NDRDesc) {
229-
sycl::range<Dims> Range;
229+
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
230230
sycl::id<Dims> Offset;
231231
for (int I = 0; I < Dims; ++I) {
232232
Range[I] = NDRDesc.GlobalSize[I];
@@ -253,16 +253,19 @@ class HostKernel : public HostKernelBase {
253253
template <class ArgT = KernelArgType>
254254
typename std::enable_if<std::is_same<ArgT, nd_item<Dims>>::value>::type
255255
runOnHost(const NDRDescT &NDRDesc) {
256-
sycl::range<Dims> GroupSize;
256+
sycl::range<Dims> GroupSize(
257+
InitializedVal<Dims, range>::template get<0>());
257258
for (int I = 0; I < Dims; ++I) {
258259
if (NDRDesc.LocalSize[I] == 0 ||
259260
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
260261
throw sycl::runtime_error("Invalid local size for global size");
261262
GroupSize[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
262263
}
263264

264-
sycl::range<Dims> GlobalSize;
265-
sycl::range<Dims> LocalSize;
265+
sycl::range<Dims> LocalSize(
266+
InitializedVal<Dims, range>::template get<0>());
267+
sycl::range<Dims> GlobalSize(
268+
InitializedVal<Dims, range>::template get<0>());
266269
sycl::id<Dims> GlobalOffset;
267270
for (int I = 0; I < Dims; ++I) {
268271
GlobalOffset[I] = NDRDesc.GlobalOffset[I];
@@ -291,17 +294,19 @@ class HostKernel : public HostKernelBase {
291294
template <typename ArgT = KernelArgType>
292295
enable_if_t<std::is_same<ArgT, cl::sycl::group<Dims>>::value>
293296
runOnHost(const NDRDescT &NDRDesc) {
294-
sycl::range<Dims> NGroups;
297+
sycl::range<Dims> NGroups(InitializedVal<Dims, range>::template get<0>());
295298

296299
for (int I = 0; I < Dims; ++I) {
297300
if (NDRDesc.LocalSize[I] == 0 ||
298301
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
299302
throw sycl::runtime_error("Invalid local size for global size");
300303
NGroups[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
301304
}
302-
sycl::range<Dims> GlobalSize;
303-
sycl::range<Dims> LocalSize;
304305

306+
sycl::range<Dims> LocalSize(
307+
InitializedVal<Dims, range>::template get<0>());
308+
sycl::range<Dims> GlobalSize(
309+
InitializedVal<Dims, range>::template get<0>());
305310
for (int I = 0; I < Dims; ++I) {
306311
LocalSize[I] = NDRDesc.LocalSize[I];
307312
GlobalSize[I] = NDRDesc.GlobalSize[I];

sycl/include/CL/sycl/detail/common.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ template <int NDIMS> struct NDLoop {
198198
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
199199
const LoopBoundTy<NDIMS> Stride =
200200
InitializedVal<NDIMS, LoopBoundTy>::template get<1>();
201-
LoopIndexTy<NDIMS> Index; // initialized down the call stack
201+
LoopIndexTy<NDIMS> Index =
202+
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
202203

203204
NDLoopIterateImpl<NDIMS, NDIMS - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
204205
LowerBound, Stride, UpperBound, f, Index};

sycl/include/CL/sycl/detail/image_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {
228228

229229
image_impl(cl_mem MemObject, const context &SyclContext,
230230
event AvailableEvent = {})
231-
: BaseT(MemObject, SyclContext, std::move(AvailableEvent)) {
231+
: BaseT(MemObject, SyclContext, std::move(AvailableEvent)),
232+
MRange(InitializedVal<Dimensions, range>::template get<0>()) {
232233
RT::PiMem Mem = pi::cast<RT::PiMem>(BaseT::MInteropMemObject);
233234
PI_CALL(RT::piMemGetInfo(Mem, CL_MEM_SIZE, sizeof(size_t),
234235
&(BaseT::MSizeInBytes), nullptr));

sycl/include/CL/sycl/id.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ template <int dimensions = 1> class id : public detail::array<dimensions> {
6868
: base(item.get_id(0), item.get_id(1), item.get_id(2)) {}
6969

7070
explicit operator range<dimensions>() const {
71-
range<dimensions> result;
71+
range<dimensions> result(
72+
detail::InitializedVal<dimensions, range>::template get<0>());
7273
for (int i = 0; i < dimensions; ++i) {
7374
result[i] = this->get(i);
7475
}

sycl/include/CL/sycl/range.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ template <int dimensions = 1> class range : public detail::array<dimensions> {
5959
range(range<dimensions> &&rhs) = default;
6060
range<dimensions> &operator=(const range<dimensions> &rhs) = default;
6161
range<dimensions> &operator=(range<dimensions> &&rhs) = default;
62-
range() = default;
62+
range() = delete;
6363

6464
// OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >=
6565
#define __SYCL_GEN_OPT(op) \
@@ -133,5 +133,6 @@ template <int dimensions = 1> class range : public detail::array<dimensions> {
133133

134134
#undef __SYCL_GEN_OPT
135135
};
136+
136137
} // namespace sycl
137138
} // namespace cl

0 commit comments

Comments
 (0)