Skip to content

[4.2][BatchMode] Add -driver-batch-count to allow overriding batch count inferred by -j #17452

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
4 changes: 4 additions & 0 deletions include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class Compilation {
/// Provides a randomization seed to batch-mode partitioning, for debugging.
const unsigned BatchSeed;

/// Overrides parallelism level as count of batches, if in batch-mode.
const Optional<unsigned> BatchCount;

/// In order to test repartitioning, set to true if
/// -driver-force-one-batch-repartition is present.
const bool ForceOneBatchRepartition = false;
Expand Down Expand Up @@ -236,6 +239,7 @@ class Compilation {
bool EnableIncrementalBuild = false,
bool EnableBatchMode = false,
unsigned BatchSeed = 0,
Optional<unsigned> BatchCount = None,
bool ForceOneBatchRepartition = false,
bool SkipTaskExecution = false,
bool SaveTemps = false,
Expand Down
6 changes: 0 additions & 6 deletions include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ class Driver {
/// Indicates whether the driver should check that the input files exist.
bool CheckInputFilesExist = true;

/// Provides a randomization seed to batch-mode partitioning, for debugging.
unsigned DriverBatchSeed = 0;

/// Forces a repartition for testing.
bool DriverForceOneBatchRepartition = false;

public:
Driver(StringRef DriverExecutable, StringRef Name,
ArrayRef<const char *> Args, DiagnosticEngine &Diags);
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def driver_filelist_threshold_EQ : Joined<["-"], "driver-filelist-threshold=">,
def driver_batch_seed : Separate<["-"], "driver-batch-seed">,
InternalDebugOpt,
HelpText<"Use the given seed value to randomize batch-mode partitions">;
def driver_batch_count : Separate<["-"], "driver-batch-count">,
InternalDebugOpt,
HelpText<"Use the given number of batch-mode partitions, rather than default parallelism level">;
def driver_force_one_batch_repartition : Flag<["-"], "driver-force-one-batch-repartition">,
InternalDebugOpt,
HelpText<"Force one batch repartitioning for testing">;
Expand Down
6 changes: 5 additions & 1 deletion lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Compilation::Compilation(DiagnosticEngine &Diags,
bool EnableIncrementalBuild,
bool EnableBatchMode,
unsigned BatchSeed,
Optional<unsigned> BatchCount,
bool ForceOneBatchRepartition,
bool SkipTaskExecution,
bool SaveTemps,
Expand All @@ -136,6 +137,7 @@ Compilation::Compilation(DiagnosticEngine &Diags,
OutputCompilationRecordForModuleOnlyBuild),
EnableBatchMode(EnableBatchMode),
BatchSeed(BatchSeed),
BatchCount(BatchCount),
ForceOneBatchRepartition(ForceOneBatchRepartition),
SaveTemps(SaveTemps),
ShowDriverTimeCompilation(ShowDriverTimeCompilation),
Expand Down Expand Up @@ -931,7 +933,9 @@ namespace driver {
return;
}

size_t NumPartitions = Comp.NumberOfParallelCommands;
size_t NumPartitions = (Comp.BatchCount.hasValue() ?
Comp.BatchCount.getValue() :
TQ->getNumberOfParallelTasks());
CommandSetVector Batchable, NonBatchable;
std::vector<const Job *> Batches;
bool PretendTheCommandLineIsTooLongOnce =
Expand Down
40 changes: 33 additions & 7 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,35 @@ static bool getFilelistThreshold(DerivedArgList &Args, size_t &FilelistThreshold
return false;
}

static unsigned
getDriverBatchSeed(llvm::opt::InputArgList &ArgList,
DiagnosticEngine &Diags) {
unsigned DriverBatchSeed = 0;
if (const Arg *A = ArgList.getLastArg(options::OPT_driver_batch_seed)) {
if (StringRef(A->getValue()).getAsInteger(10, DriverBatchSeed)) {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(ArgList), A->getValue());
}
}
return DriverBatchSeed;
}

static Optional<unsigned>
getDriverBatchCount(llvm::opt::InputArgList &ArgList,
DiagnosticEngine &Diags)
{
if (const Arg *A = ArgList.getLastArg(options::OPT_driver_batch_count)) {
unsigned Count = 0;
if (StringRef(A->getValue()).getAsInteger(10, Count)) {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(ArgList), A->getValue());
} else {
return Count;
}
}
return None;
}

std::unique_ptr<Compilation>
Driver::buildCompilation(const ToolChain &TC,
std::unique_ptr<llvm::opt::InputArgList> ArgList) {
Expand All @@ -644,13 +673,9 @@ Driver::buildCompilation(const ToolChain &TC,
ArgList->hasArg(options::OPT_driver_show_incremental);
bool ShowJobLifecycle =
ArgList->hasArg(options::OPT_driver_show_job_lifecycle);
if (const Arg *A = ArgList->getLastArg(options::OPT_driver_batch_seed)) {
if (StringRef(A->getValue()).getAsInteger(10, DriverBatchSeed)) {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(*ArgList), A->getValue());
}
}
DriverForceOneBatchRepartition =
unsigned DriverBatchSeed = getDriverBatchSeed(*ArgList, Diags);
Optional<unsigned> DriverBatchCount = getDriverBatchCount(*ArgList, Diags);
bool DriverForceOneBatchRepartition =
ArgList->hasArg(options::OPT_driver_force_one_batch_repartition);

bool Incremental = ArgList->hasArg(options::OPT_incremental);
Expand Down Expand Up @@ -828,6 +853,7 @@ Driver::buildCompilation(const ToolChain &TC,
Incremental,
BatchMode,
DriverBatchSeed,
DriverBatchCount,
DriverForceOneBatchRepartition,
DriverSkipExecution,
SaveTemps,
Expand Down