Skip to content

Commit

Permalink
Added ReleaseCores to BuildEngine usages that did not have it. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ilonatommy authored Jul 1, 2024
1 parent 9f26939 commit f8bcb89
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
27 changes: 17 additions & 10 deletions src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ private bool ExecuteInternal()
else
{
int allowedParallelism = DisableParallelAot ? 1 : Math.Min(_assembliesToCompile.Count, Environment.ProcessorCount);
if (BuildEngine is IBuildEngine9 be9)
IBuildEngine9? be9 = BuildEngine as IBuildEngine9;
if (be9 is not null)
allowedParallelism = be9.RequestCores(allowedParallelism);

/*
Expand Down Expand Up @@ -553,20 +554,26 @@ all assigned to that one partition.
Instead, we want to use work-stealing so jobs can be run by any partition.
*/
ParallelLoopResult result = Parallel.ForEach(
try
{
ParallelLoopResult result = Parallel.ForEach(
Partitioner.Create(argsList, EnumerablePartitionerOptions.NoBuffering),
new ParallelOptions { MaxDegreeOfParallelism = allowedParallelism },
PrecompileLibraryParallel);

if (result.IsCompleted)
{
int numUnchanged = _totalNumAssemblies - _numCompiled;
if (numUnchanged > 0 && numUnchanged != _totalNumAssemblies)
Log.LogMessage(MessageImportance.High, $"[{numUnchanged}/{_totalNumAssemblies}] skipped unchanged assemblies.");
if (result.IsCompleted)
{
int numUnchanged = _totalNumAssemblies - _numCompiled;
if (numUnchanged > 0 && numUnchanged != _totalNumAssemblies)
Log.LogMessage(MessageImportance.High, $"[{numUnchanged}/{_totalNumAssemblies}] skipped unchanged assemblies.");
}
else if (!Log.HasLoggedErrors)
{
Log.LogError($"Precompiling failed due to unknown reasons. Check log for more info");
}
}
else if (!Log.HasLoggedErrors)
finally
{
Log.LogError($"Precompiling failed due to unknown reasons. Check log for more info");
be9?.ReleaseCores(allowedParallelism);
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ public override bool Execute()
Log.LogMessage(MessageImportance.High, "IL stripping assemblies");

int allowedParallelism = DisableParallelStripping ? 1 : Math.Min(Assemblies.Length, Environment.ProcessorCount);
if (BuildEngine is IBuildEngine9 be9)
IBuildEngine9? be9 = BuildEngine as IBuildEngine9;
if (be9 is not null)
allowedParallelism = be9.RequestCores(allowedParallelism);
ParallelLoopResult result = Parallel.ForEach(Assemblies,
try
{
ParallelLoopResult result = Parallel.ForEach(Assemblies,
new ParallelOptions { MaxDegreeOfParallelism = allowedParallelism },
(assemblyItem, state) =>
{
Expand All @@ -93,14 +96,19 @@ public override bool Execute()
}
});

if (TrimIndividualMethods)
{
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();
}
if (TrimIndividualMethods)
{
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();
}

if (!result.IsCompleted && !Log.HasLoggedErrors)
if (!result.IsCompleted && !Log.HasLoggedErrors)
{
Log.LogError("Unknown failure occurred while IL stripping assemblies. Check logs to get more details.");
}
}
finally
{
Log.LogError("Unknown failure occurred while IL stripping assemblies. Check logs to get more details.");
be9?.ReleaseCores(allowedParallelism);
}

return !Log.HasLoggedErrors;
Expand Down
22 changes: 15 additions & 7 deletions src/tasks/WasmAppBuilder/EmccCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ private bool ExecuteActual()
Directory.CreateDirectory(_tempPath);

int allowedParallelism = DisableParallelCompile ? 1 : Math.Min(SourceFiles.Length, Environment.ProcessorCount);
if (BuildEngine is IBuildEngine9 be9)
IBuildEngine9? be9 = BuildEngine as IBuildEngine9;
if (be9 is not null)
allowedParallelism = be9.RequestCores(allowedParallelism);

/*
Expand Down Expand Up @@ -160,17 +161,24 @@ all assigned to that one partition.
Instead, we want to use work-stealing so jobs can be run by any partition.
*/
ParallelLoopResult result = Parallel.ForEach(
try
{
ParallelLoopResult result = Parallel.ForEach(
Partitioner.Create(filesToCompile, EnumerablePartitionerOptions.NoBuffering),
new ParallelOptions { MaxDegreeOfParallelism = allowedParallelism },
(toCompile, state) =>
{
if (!ProcessSourceFile(toCompile.Item1, toCompile.Item2))
state.Stop();
});
if (!result.IsCompleted && !Log.HasLoggedErrors)
Log.LogError("Unknown failure occurred while compiling. Check logs to get more details.");
}
finally
{
if (!ProcessSourceFile(toCompile.Item1, toCompile.Item2))
state.Stop();
});
be9?.ReleaseCores(allowedParallelism);
}

if (!result.IsCompleted && !Log.HasLoggedErrors)
Log.LogError("Unknown failure occurred while compiling. Check logs to get more details.");

if (!Log.HasLoggedErrors)
{
Expand Down

0 comments on commit f8bcb89

Please sign in to comment.