Skip to content

[SYCL][Fusion] Fix handling of identical parameters #12415

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 3 commits into from
Jan 22, 2024
Merged
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: 5 additions & 5 deletions sycl-fusion/passes/kernel-fusion/SYCLKernelFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ Error SYCLKernelFusion::fuseKernel(
DenseMap<std::pair<unsigned, unsigned>, unsigned> ParamMapping;
// The list of identical parameters is sorted, so the relevant entry can
// always only be the current front.
SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin();
SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin(),
*ParamEnd = ParamIdentities.end();
unsigned FuncIndex = 0;
unsigned ArgIndex = 0;
for (const auto &Fused : FusedKernels) {
Expand All @@ -386,7 +387,7 @@ Error SYCLKernelFusion::fuseKernel(
SmallVector<bool, 8> UsedArgsMask;
for (const auto &Arg : FF->args()) {
int IdenticalIdx = -1;
if (!ParamIdentities.empty() && FuncIndex == ParamFront->LHS.KernelIdx &&
if (ParamFront != ParamEnd && FuncIndex == ParamFront->LHS.KernelIdx &&
ParamIndex == ParamFront->LHS.ParamIdx) {
// Because ParamIdentity is constructed such that LHS > RHS, the other
// parameter must already have been processed.
Expand Down Expand Up @@ -620,7 +621,7 @@ void SYCLKernelFusion::canonicalizeParameters(
// The input is a list of parameter pairs which werde detected to be
// identical. Each pair is constructed such that the RHS belongs to a kernel
// occuring before the kernel for the LHS in the list of kernels to fuse. This
// means, that we want to use the LHS parameter instead of the RHS parameter.
// means, that we want to use the RHS parameter instead of the LHS parameter.

// In the first step we sort the list of pairs by their LHS.
std::sort(Params.begin(), Params.end());
Expand All @@ -639,8 +640,7 @@ void SYCLKernelFusion::canonicalizeParameters(
// LHS and RHS are identical - this does not provide
// any useful information at all, discard it.
I = Params.erase(I);
}
if (Identities.count(I->LHS)) {
} else if (Identities.count(I->LHS)) {
// Duplicate
auto ExistingIdentity = Identities.at(I->LHS);
Identities.emplace(I->RHS, ExistingIdentity);
Expand Down