Skip to content

[SYCL] Delete range class default constructor. #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace detail {
// DefaultValue, truncation just removes extra values.
template <int NewDim, int DefaultValue, template <int> class T, int OldDim>
static T<NewDim> convertToArrayOfN(T<OldDim> OldObj) {
T<NewDim> NewObj;
T<NewDim> NewObj = InitializedVal<NewDim, T>::template get<0>();
const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
for (int I = 0; I < CopyDims; ++I)
NewObj[I] = OldObj[I];
Expand Down Expand Up @@ -727,7 +727,10 @@ class accessor :

public:
// Default constructor for objects later initialized with __init member.
accessor() : impl({}) {}
accessor()
: impl({}, detail::InitializedVal<AdjustedDim, range>::template get<0>(),
detail::InitializedVal<AdjustedDim, range>::template get<0>()) {}

#else
using AccessorBaseHost::getAccessRange;
using AccessorBaseHost::getMemoryRange;
Expand Down Expand Up @@ -1035,7 +1038,8 @@ class accessor<DataT, Dimensions, AccessMode, access::target::local,

public:
// Default constructor for objects later initialized with __init member.
accessor() : impl({}) {}
accessor()
: impl(detail::InitializedVal<AdjustedDim, range>::template get<0>()) {}

private:
PtrType getQualifiedPtr() const { return MData; }
Expand Down
4 changes: 3 additions & 1 deletion sycl/include/CL/sycl/detail/accessor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ template <int Dims> class AccessorImplDevice {

template <int Dims> class LocalAccessorBaseDevice {
public:
LocalAccessorBaseDevice(sycl::range<Dims> Size) : AccessRange(Size) {}
LocalAccessorBaseDevice(sycl::range<Dims> Size)
: AccessRange(Size),
MemRange(InitializedVal<Dims, range>::template get<0>()) {}
// TODO: Actually we need only one field here, but currently compiler requires
// all of them.
range<Dims> AccessRange;
Expand Down
21 changes: 13 additions & 8 deletions sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class HostKernel : public HostKernelBase {
runOnHost(const NDRDescT &NDRDesc) {
size_t XYZ[3] = {0};
sycl::id<Dims> ID;
sycl::range<Dims> Range;
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
for (int I = 0; I < Dims; ++I)
Range[I] = NDRDesc.GlobalSize[I];

Expand All @@ -226,7 +226,7 @@ class HostKernel : public HostKernelBase {
typename std::enable_if<
std::is_same<ArgT, item<Dims, /*Offset=*/true>>::value>::type
runOnHost(const NDRDescT &NDRDesc) {
sycl::range<Dims> Range;
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
sycl::id<Dims> Offset;
for (int I = 0; I < Dims; ++I) {
Range[I] = NDRDesc.GlobalSize[I];
Expand All @@ -253,16 +253,19 @@ class HostKernel : public HostKernelBase {
template <class ArgT = KernelArgType>
typename std::enable_if<std::is_same<ArgT, nd_item<Dims>>::value>::type
runOnHost(const NDRDescT &NDRDesc) {
sycl::range<Dims> GroupSize;
sycl::range<Dims> GroupSize(
InitializedVal<Dims, range>::template get<0>());
for (int I = 0; I < Dims; ++I) {
if (NDRDesc.LocalSize[I] == 0 ||
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
throw sycl::runtime_error("Invalid local size for global size");
GroupSize[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
}

sycl::range<Dims> GlobalSize;
sycl::range<Dims> LocalSize;
sycl::range<Dims> LocalSize(
InitializedVal<Dims, range>::template get<0>());
sycl::range<Dims> GlobalSize(
InitializedVal<Dims, range>::template get<0>());
sycl::id<Dims> GlobalOffset;
for (int I = 0; I < Dims; ++I) {
GlobalOffset[I] = NDRDesc.GlobalOffset[I];
Expand Down Expand Up @@ -291,17 +294,19 @@ class HostKernel : public HostKernelBase {
template <typename ArgT = KernelArgType>
enable_if_t<std::is_same<ArgT, cl::sycl::group<Dims>>::value>
runOnHost(const NDRDescT &NDRDesc) {
sycl::range<Dims> NGroups;
sycl::range<Dims> NGroups(InitializedVal<Dims, range>::template get<0>());

for (int I = 0; I < Dims; ++I) {
if (NDRDesc.LocalSize[I] == 0 ||
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
throw sycl::runtime_error("Invalid local size for global size");
NGroups[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
}
sycl::range<Dims> GlobalSize;
sycl::range<Dims> LocalSize;

sycl::range<Dims> LocalSize(
InitializedVal<Dims, range>::template get<0>());
sycl::range<Dims> GlobalSize(
InitializedVal<Dims, range>::template get<0>());
for (int I = 0; I < Dims; ++I) {
LocalSize[I] = NDRDesc.LocalSize[I];
GlobalSize[I] = NDRDesc.GlobalSize[I];
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ template <int NDIMS> struct NDLoop {
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
const LoopBoundTy<NDIMS> Stride =
InitializedVal<NDIMS, LoopBoundTy>::template get<1>();
LoopIndexTy<NDIMS> Index; // initialized down the call stack
LoopIndexTy<NDIMS> Index =
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();

NDLoopIterateImpl<NDIMS, NDIMS - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
LowerBound, Stride, UpperBound, f, Index};
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {

image_impl(cl_mem MemObject, const context &SyclContext,
event AvailableEvent = {})
: BaseT(MemObject, SyclContext, std::move(AvailableEvent)) {
: BaseT(MemObject, SyclContext, std::move(AvailableEvent)),
MRange(InitializedVal<Dimensions, range>::template get<0>()) {
RT::PiMem Mem = pi::cast<RT::PiMem>(BaseT::MInteropMemObject);
PI_CALL(RT::piMemGetInfo(Mem, CL_MEM_SIZE, sizeof(size_t),
&(BaseT::MSizeInBytes), nullptr));
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ template <int dimensions = 1> class id : public detail::array<dimensions> {
: base(item.get_id(0), item.get_id(1), item.get_id(2)) {}

explicit operator range<dimensions>() const {
range<dimensions> result;
range<dimensions> result(
detail::InitializedVal<dimensions, range>::template get<0>());
for (int i = 0; i < dimensions; ++i) {
result[i] = this->get(i);
}
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ template <int dimensions = 1> class range : public detail::array<dimensions> {
range(range<dimensions> &&rhs) = default;
range<dimensions> &operator=(const range<dimensions> &rhs) = default;
range<dimensions> &operator=(range<dimensions> &&rhs) = default;
range() = default;
range() = delete;

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

#undef __SYCL_GEN_OPT
};

} // namespace sycl
} // namespace cl