Skip to content

Commit cf25bcc

Browse files
authored
[SYCL][Fusion] Fix handling of identical parameters (#12415)
Obey the end of the `ParamIdentities` list when looking for opportunities to mark arguments of the fused kernel as unused. --------- Signed-off-by: Julian Oppermann <[email protected]>
1 parent 89327e0 commit cf25bcc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sycl-fusion/passes/kernel-fusion/SYCLKernelFusion.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ Error SYCLKernelFusion::fuseKernel(
367367
DenseMap<std::pair<unsigned, unsigned>, unsigned> ParamMapping;
368368
// The list of identical parameters is sorted, so the relevant entry can
369369
// always only be the current front.
370-
SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin();
370+
SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin(),
371+
*ParamEnd = ParamIdentities.end();
371372
unsigned FuncIndex = 0;
372373
unsigned ArgIndex = 0;
373374
for (const auto &Fused : FusedKernels) {
@@ -386,7 +387,7 @@ Error SYCLKernelFusion::fuseKernel(
386387
SmallVector<bool, 8> UsedArgsMask;
387388
for (const auto &Arg : FF->args()) {
388389
int IdenticalIdx = -1;
389-
if (!ParamIdentities.empty() && FuncIndex == ParamFront->LHS.KernelIdx &&
390+
if (ParamFront != ParamEnd && FuncIndex == ParamFront->LHS.KernelIdx &&
390391
ParamIndex == ParamFront->LHS.ParamIdx) {
391392
// Because ParamIdentity is constructed such that LHS > RHS, the other
392393
// parameter must already have been processed.
@@ -620,7 +621,7 @@ void SYCLKernelFusion::canonicalizeParameters(
620621
// The input is a list of parameter pairs which werde detected to be
621622
// identical. Each pair is constructed such that the RHS belongs to a kernel
622623
// occuring before the kernel for the LHS in the list of kernels to fuse. This
623-
// means, that we want to use the LHS parameter instead of the RHS parameter.
624+
// means, that we want to use the RHS parameter instead of the LHS parameter.
624625

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

0 commit comments

Comments
 (0)