Skip to content

[SYCL] Remove std::function usage from applyFuncOnFilteredArgs #17202

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
merged 2 commits into from
Feb 28, 2025
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
34 changes: 0 additions & 34 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,6 @@ static std::string demangleKernelName(std::string Name) {
static std::string demangleKernelName(std::string Name) { return Name; }
#endif

void applyFuncOnFilteredArgs(
const KernelArgMask *EliminatedArgMask, std::vector<ArgDesc> &Args,
std::function<void(detail::ArgDesc &Arg, int NextTrueIndex)> Func) {
if (!EliminatedArgMask || EliminatedArgMask->size() == 0) {
for (ArgDesc &Arg : Args) {
Func(Arg, Arg.MIndex);
}
} else {
// TODO this is not necessary as long as we can guarantee that the
// arguments are already sorted (e. g. handle the sorting in handler
// if necessary due to set_arg(...) usage).
std::sort(Args.begin(), Args.end(), [](const ArgDesc &A, const ArgDesc &B) {
return A.MIndex < B.MIndex;
});
int LastIndex = -1;
size_t NextTrueIndex = 0;

for (ArgDesc &Arg : Args) {
// Handle potential gaps in set arguments (e. g. if some of them are
// set on the user side).
for (int Idx = LastIndex + 1; Idx < Arg.MIndex; ++Idx)
if (!(*EliminatedArgMask)[Idx])
++NextTrueIndex;
LastIndex = Arg.MIndex;

if ((*EliminatedArgMask)[Arg.MIndex])
continue;

Func(Arg, NextTrueIndex);
++NextTrueIndex;
}
}
}

static std::string accessModeToString(access::mode Mode) {
switch (Mode) {
case access::mode::read:
Expand Down
36 changes: 33 additions & 3 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,39 @@ void SetArgBasedOnType(
const std::function<void *(Requirement *Req)> &getMemAllocationFunc,
const sycl::context &Context, detail::ArgDesc &Arg, size_t NextTrueIndex);

void applyFuncOnFilteredArgs(
const KernelArgMask *EliminatedArgMask, std::vector<ArgDesc> &Args,
std::function<void(detail::ArgDesc &Arg, int NextTrueIndex)> Func);
template <typename FuncT>
void applyFuncOnFilteredArgs(const KernelArgMask *EliminatedArgMask,
std::vector<ArgDesc> &Args, FuncT Func) {
if (!EliminatedArgMask || EliminatedArgMask->size() == 0) {
for (ArgDesc &Arg : Args) {
Func(Arg, Arg.MIndex);
}
} else {
// TODO this is not necessary as long as we can guarantee that the
// arguments are already sorted (e. g. handle the sorting in handler
// if necessary due to set_arg(...) usage).
std::sort(Args.begin(), Args.end(), [](const ArgDesc &A, const ArgDesc &B) {
return A.MIndex < B.MIndex;
});
int LastIndex = -1;
size_t NextTrueIndex = 0;

for (ArgDesc &Arg : Args) {
// Handle potential gaps in set arguments (e. g. if some of them are
// set on the user side).
for (int Idx = LastIndex + 1; Idx < Arg.MIndex; ++Idx)
if (!(*EliminatedArgMask)[Idx])
++NextTrueIndex;
LastIndex = Arg.MIndex;

if ((*EliminatedArgMask)[Arg.MIndex])
continue;

Func(Arg, NextTrueIndex);
++NextTrueIndex;
}
}
}

void ReverseRangeDimensionsForKernel(NDRDescT &NDR);

Expand Down