-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Optimize NDRDescT by removing sycl::range, sycl::id and padding #18851
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
Changes from all commits
b959782
520e446
907717c
adafe3d
ef58ba7
86d7783
7d4175f
4fe9507
11fdc89
19e8982
73b8e4d
889b4d7
9964dcf
6c51413
0c62f94
9e879fa
ace2ae2
abbeed9
e084cb4
b04e914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,99 +62,96 @@ class ArgDesc { | |
|
||
// The structure represents NDRange - global, local sizes, global offset and | ||
// number of dimensions. | ||
class NDRDescT { | ||
// The method initializes all sizes for dimensions greater than the passed one | ||
// to the default values, so they will not affect execution. | ||
void setNDRangeLeftover() { | ||
for (int I = Dims; I < 3; ++I) { | ||
GlobalSize[I] = 1; | ||
LocalSize[I] = LocalSize[0] ? 1 : 0; | ||
GlobalOffset[I] = 0; | ||
NumWorkGroups[I] = 0; | ||
} | ||
} | ||
|
||
template <int Dims> static sycl::range<3> padRange(sycl::range<Dims> Range) { | ||
if constexpr (Dims == 3) { | ||
return Range; | ||
} else { | ||
sycl::range<3> Res{0, 0, 0}; | ||
for (int I = 0; I < Dims; ++I) | ||
Res[I] = Range[I]; | ||
return Res; | ||
} | ||
} | ||
|
||
template <int Dims> static sycl::id<3> padId(sycl::id<Dims> Id) { | ||
if constexpr (Dims == 3) { | ||
return Id; | ||
} else { | ||
sycl::id<3> Res{0, 0, 0}; | ||
for (int I = 0; I < Dims; ++I) | ||
Res[I] = Id[I]; | ||
return Res; | ||
} | ||
} | ||
// TODO: A lot of tests rely on particular values to be set for dimensions that | ||
// are not used. To clarify, for example, if a 2D kernel is invoked, in | ||
// NDRDescT, the value of index 2 in GlobalSize must be set to either 1 or 0 | ||
// depending on which constructor is used for no clear reason. | ||
// Instead, only sensible defaults should be used and tests should be updated | ||
// to reflect this. | ||
class NDRDescT { | ||
|
||
public: | ||
NDRDescT() = default; | ||
NDRDescT(const NDRDescT &Desc) = default; | ||
NDRDescT(NDRDescT &&Desc) = default; | ||
|
||
NDRDescT(sycl::range<3> N, bool SetNumWorkGroups, int DimsArg) | ||
: GlobalSize{SetNumWorkGroups ? sycl::range<3>{0, 0, 0} : N}, | ||
NumWorkGroups{SetNumWorkGroups ? N : sycl::range<3>{0, 0, 0}}, | ||
Dims{size_t(DimsArg)} { | ||
setNDRangeLeftover(); | ||
} | ||
template <int Dims_> | ||
NDRDescT(sycl::range<Dims_> N, bool SetNumWorkGroups) : Dims{size_t(Dims_)} { | ||
if (SetNumWorkGroups) { | ||
for (size_t I = 0; I < Dims_; ++I) { | ||
NumWorkGroups[I] = N[I]; | ||
} | ||
} else { | ||
for (size_t I = 0; I < Dims_; ++I) { | ||
GlobalSize[I] = N[I]; | ||
} | ||
|
||
NDRDescT(sycl::range<3> NumWorkItems, sycl::range<3> LocalSize, | ||
sycl::id<3> Offset, int DimsArg) | ||
: GlobalSize{NumWorkItems}, LocalSize{LocalSize}, GlobalOffset{Offset}, | ||
Dims{size_t(DimsArg)} { | ||
setNDRangeLeftover(); | ||
for (int I = Dims_; I < 3; ++I) { | ||
GlobalSize[I] = 1; | ||
} | ||
} | ||
} | ||
|
||
NDRDescT(sycl::range<3> NumWorkItems, sycl::id<3> Offset, int DimsArg) | ||
: GlobalSize{NumWorkItems}, GlobalOffset{Offset}, Dims{size_t(DimsArg)} {} | ||
template <int Dims_> | ||
NDRDescT(sycl::range<Dims_> NumWorkItems, sycl::range<Dims_> LocalSizes, | ||
sycl::id<Dims_> Offset) | ||
: Dims{size_t(Dims_)} { | ||
for (size_t I = 0; I < Dims_; ++I) { | ||
GlobalSize[I] = NumWorkItems[I]; | ||
LocalSize[I] = LocalSizes[I]; | ||
GlobalOffset[I] = Offset[I]; | ||
} | ||
|
||
for (int I = Dims_; I < 3; ++I) { | ||
LocalSize[I] = LocalSizes[0] ? 1 : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a number of tests that depend on extra LocalSize dimensions higher than Dims_ being set to zero or one depending on whether LocalSizes[I] is zero or not respectively. RequiredWGSize.NoRequiredSize and RequiredWGSize.HasRequiredSize always fail if extra LocalSize dimensions are always set to 1 and various tests such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems strange to me that this was introduced in the first place. It really should not matter what the value of dimensions higher than Dims_ are and should just be ignored. But now a number of tests depend on this behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a TODO to revisit this? This sort of complexity will have a (small) impact on runtime, but it's also going to make it harder to make changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the TODO. I can also create a github issue if you think it is a good idea to keep track of this. |
||
} | ||
|
||
for (int I = Dims_; I < 3; ++I) { | ||
GlobalSize[I] = 1; | ||
} | ||
} | ||
|
||
template <int Dims_> | ||
NDRDescT(sycl::nd_range<Dims_> ExecutionRange, int DimsArg) | ||
: NDRDescT(padRange(ExecutionRange.get_global_range()), | ||
padRange(ExecutionRange.get_local_range()), | ||
padId(ExecutionRange.get_offset()), size_t(DimsArg)) { | ||
setNDRangeLeftover(); | ||
NDRDescT(sycl::range<Dims_> NumWorkItems, sycl::id<Dims_> Offset) | ||
: Dims{size_t(Dims_)} { | ||
for (size_t I = 0; I < Dims_; ++I) { | ||
GlobalSize[I] = NumWorkItems[I]; | ||
GlobalOffset[I] = Offset[I]; | ||
} | ||
} | ||
|
||
template <int Dims_> | ||
NDRDescT(sycl::nd_range<Dims_> ExecutionRange) | ||
: NDRDescT(ExecutionRange, Dims_) {} | ||
: NDRDescT(ExecutionRange.get_global_range(), | ||
ExecutionRange.get_local_range(), | ||
ExecutionRange.get_offset()) {} | ||
|
||
template <int Dims_> | ||
NDRDescT(sycl::range<Dims_> Range) | ||
: NDRDescT(padRange(Range), /*SetNumWorkGroups=*/false, Dims_) {} | ||
: NDRDescT(Range, /*SetNumWorkGroups=*/false) {} | ||
|
||
void setClusterDimensions(sycl::range<3> N, int Dims) { | ||
if (this->Dims != size_t(Dims)) { | ||
template <int Dims_> void setClusterDimensions(sycl::range<Dims_> N) { | ||
if (this->Dims != size_t(Dims_)) { | ||
throw std::runtime_error( | ||
"Dimensionality of cluster, global and local ranges must be same"); | ||
} | ||
|
||
for (int I = 0; I < 3; ++I) | ||
ClusterDimensions[I] = (I < Dims) ? N[I] : 1; | ||
for (int I = 0; I < Dims_; ++I) | ||
ClusterDimensions[I] = N[I]; | ||
} | ||
|
||
NDRDescT &operator=(const NDRDescT &Desc) = default; | ||
NDRDescT &operator=(NDRDescT &&Desc) = default; | ||
|
||
sycl::range<3> GlobalSize{0, 0, 0}; | ||
sycl::range<3> LocalSize{0, 0, 0}; | ||
sycl::id<3> GlobalOffset{0, 0, 0}; | ||
std::array<size_t, 3> GlobalSize{0, 0, 0}; | ||
std::array<size_t, 3> LocalSize{0, 0, 0}; | ||
std::array<size_t, 3> GlobalOffset{0, 0, 0}; | ||
/// Number of workgroups, used to record the number of workgroups from the | ||
/// simplest form of parallel_for_work_group. If set, all other fields must be | ||
/// zero | ||
sycl::range<3> NumWorkGroups{0, 0, 0}; | ||
sycl::range<3> ClusterDimensions{1, 1, 1}; | ||
std::array<size_t, 3> NumWorkGroups{0, 0, 0}; | ||
std::array<size_t, 3> ClusterDimensions{1, 1, 1}; | ||
size_t Dims = 0; | ||
}; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these necessary to be exported? Both "new" and "old".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these functions are used in
handler.cpp
,handler.hpp
and alsoSchedulerTestUtils.hpp
.There does not seem to be a straight forward way to stop these functions from being exported?
After chatting with a co-worker, I don't think there is an easy way to fix this. There are attributes to set visibility, but I strongly suspect doing so will break things. Complicated by the fact that
setNDRangeDescriptor
is used inSchedulerTestUtils.hpp
.I would have expected that only functions that are marked as
__SYCL_EXPORT
would actually be exported, but that appears to not matter?sycl_symbols_linux.dump
contains loads of symbols that are in the detail namespace and should not be used directly by the user. Windows and linux have different visibility defaults but it appears both have been set to export all.