Skip to content

[SYCL] Fix ModuleSplitterBase::totalSplits usage #7485

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
6 changes: 4 additions & 2 deletions llvm/tools/sycl-post-link/ModuleSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ class ModuleSplitterBase {
// submodule containing these entry points and their dependencies.
virtual ModuleDesc nextSplit() = 0;

size_t totalSplits() const { return Groups.size(); }
// Returns a number of remaining modules, which can be split out using this
// splitter. The value is reduced by 1 each time nextSplit is called.
size_t remainingSplits() const { return Groups.size(); }

// Check that there are still submodules to split.
bool hasMoreSplits() const { return totalSplits() > 0; }
bool hasMoreSplits() const { return remainingSplits() > 0; }
};

std::unique_ptr<ModuleSplitterBase>
Expand Down
13 changes: 7 additions & 6 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,12 +758,14 @@ processInputModule(std::unique_ptr<Module> M) {
EmitOnlyKernelsAsEntryPoints);

SmallVector<module_split::ModuleDesc, 8> TopLevelModules;
bool SplitByOptionalFeatures = false;

// FIXME: this check should be performed on all split levels
if (DeviceGlobals)
ScopedSplitter->verifyNoCrossModuleDeviceGlobalUsage();

const bool SplitByScope = ScopedSplitter->remainingSplits() > 1;
bool SplitByOptionalFeatures = false;

while (ScopedSplitter->hasMoreSplits()) {
module_split::ModuleDesc MD = ScopedSplitter->nextSplit();

Expand All @@ -782,14 +784,13 @@ processInputModule(std::unique_ptr<Module> M) {
// This step is mandatory, because it is required for functional
// correctness, i.e. to prevent speculative compilation of kernels that use
// optional features on a HW which doesn't support them.
SplitByOptionalFeatures |= OptionalFeaturesSplitter->remainingSplits() > 1;

while (OptionalFeaturesSplitter->hasMoreSplits()) {
TopLevelModules.emplace_back(OptionalFeaturesSplitter->nextSplit());
}

SplitByOptionalFeatures |= OptionalFeaturesSplitter->totalSplits() > 1;
}

const bool SplitByScope = ScopedSplitter->totalSplits() > 1;
Modified |= SplitByScope;
Modified |= SplitByOptionalFeatures;

Expand All @@ -809,7 +810,7 @@ processInputModule(std::unique_ptr<Module> M) {
std::unique_ptr<module_split::ModuleSplitterBase> LargeGRFSplitter =
module_split::getLargeGRFSplitter(std::move(MDesc),
EmitOnlyKernelsAsEntryPoints);
const bool SplitByLargeGRF = LargeGRFSplitter->totalSplits() > 1;
const bool SplitByLargeGRF = LargeGRFSplitter->remainingSplits() > 1;
Modified |= SplitByLargeGRF;

// Now split further by "large-grf" attribute.
Expand All @@ -827,7 +828,7 @@ processInputModule(std::unique_ptr<Module> M) {
std::unique_ptr<module_split::ModuleSplitterBase> ESIMDSplitter =
module_split::getSplitterByKernelType(std::move(MDesc1),
EmitOnlyKernelsAsEntryPoints);
const bool SplitByESIMD = ESIMDSplitter->totalSplits() > 1;
const bool SplitByESIMD = ESIMDSplitter->remainingSplits() > 1;
Modified |= SplitByESIMD;

if (SplitByESIMD && SplitByScope &&
Expand Down