Skip to content
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

Enable PGO - alternative approach #17317

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
60 changes: 60 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,64 @@
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>

<PropertyGroup>
<TargetOS>linux</TargetOS>
<TargetOS Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</TargetOS>
<TargetOS Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">windows</TargetOS>

<TargetArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant)</TargetArchitecture>
</PropertyGroup>

<!-- MIBC data -->
<ItemGroup>

<!-- MIBC data to use when exact architecture match is available -->
<MIBCPackageDef
psfinaki marked this conversation as resolved.
Show resolved Hide resolved
Include="optimization.windows_nt-x86.mibc.runtime"
Version="$(optimizationwindows_ntx86MIBCRuntimeVersion)"
MibcArchitecture="windows/x86" />
<MIBCPackageDef
Include="optimization.windows_nt-x64.mibc.runtime"
Version="$(optimizationwindows_ntx64MIBCRuntimeVersion)"
MibcArchitecture="windows/x64" />
<MIBCPackageDef
Include="optimization.windows_nt-arm64.mibc.runtime"
Version="$(optimizationwindows_ntarm64MIBCRuntimeVersion)"
MibcArchitecture="windows/arm64" />
<MIBCPackageDef
Include="optimization.linux-x64.mibc.runtime"
Version="$(optimizationlinuxx64MIBCRuntimeVersion)"
MibcArchitecture="linux/x64" />
<MIBCPackageDef
Include="optimization.linux-arm64.mibc.runtime"
Version="$(optimizationlinuxarm64MIBCRuntimeVersion)"
MibcArchitecture="linux/arm64" />

<!-- MIBC data to use when exact architecture match is not available -->
<MIBCPackageDef
Include="optimization.windows_nt-x64.mibc.runtime"
Version="$(optimizationwindows_ntx64MIBCRuntimeVersion)"
MibcArchitecture="windows" />
<MIBCPackageDef
Include="optimization.linux-x64.mibc.runtime"
Version="$(optimizationlinuxx64MIBCRuntimeVersion)"
MibcArchitecture="linux" />
<MIBCPackageDef
Include="optimization.linux-x64.mibc.runtime"
Version="$(optimizationlinuxx64MIBCRuntimeVersion)"
MibcArchitecture="osx" />

<MIBCPackage
Include="@(MIBCPackageDef->HasMetadata('MibcArchitecture')->WithMetadataValue('MibcArchitecture','$(TargetOS)/$(TargetArchitecture)'))" />
<MIBCPackage
Include="@(MIBCPackageDef->HasMetadata('MibcArchitecture')->WithMetadataValue('MibcArchitecture','$(TargetOS)'))"
Condition="'@(MIBCPackage)' == ''" />
<!-- Fallback in case no OS specific data is available -->
<MIBCPackage
Include="optimization.linux-x64.mibc.runtime"
Version="$(optimizationlinuxx64MIBCRuntimeVersion)"
Condition="'@(MIBCPackage)' == ''" />

</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
<Project>
<Import Project="..\buildtools\buildtools.targets" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<Target Name="Get MIBC data" AfterTargets="Restore" Condition="'$(Configuration)' == 'Release'">

<PropertyGroup>
<MibcOptimizationDataDir>$([System.IO.Path]::Combine($(ArtifactsDir), 'mibc'))</MibcOptimizationDataDir>
</PropertyGroup>

<ItemGroup>
<MIBCPackage>
<PackagePath>$([System.IO.Path]::Combine($(NuGetPackageRoot), %(MIBCPackage.Identity), %(MIBCPackage.Version)))</PackagePath>
</MIBCPackage>

<MibcOriginalFiles
Include="%(MIBCPackage.PackagePath)/**/DotNet_FSharp.mibc"
SubdirectoryName="$([System.IO.Path]::Combine($(TargetOS), $(TargetArchitecture)))" />

<MibcFiles
Include="@(MibcOriginalFiles->'$(MibcOptimizationDataDir)/%(SubdirectoryName)/%(RecursiveDir)%(Filename)%(Extension)')" />
</ItemGroup>

<Error
Condition="'@(MibcOriginalFiles)' == ''"
Text="Failed to restore MIBC optimization data" />

<!-- Copy MIBC files to artifacts -->
<Copy
SourceFiles="@(MibcOriginalFiles)"
DestinationFiles="@(MibcFiles)"
SkipUnchangedFiles="true"
UseHardlinksIfPossible="true" />

</Target>

</Project>
11 changes: 11 additions & 0 deletions src/fsc/fsc.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" />
</ItemGroup>

<Target Name="Add PGO" DependsOnTargets="Get MIBC data" BeforeTargets="Publish" Condition="'$(Configuration)' == 'Release'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ship fsc and fsi to the dotnetsdk as il assemblies not native compiled assemblies.

The sdk native compiles F# in this project here: https://github.com/dotnet/sdk/blob/main/src/Layout/tool_fsharp/tool_fsc.csproj

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So imagine, we will need to work with the sdk team to enable the pgo stuff ... at least if it relies on native compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We called certainly add the mibc files to the package we insert into the sdk.

Copy link
Member

@vzarytovskii vzarytovskii Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think sdk does anything, @baronfel doesn't it just repack stuff from nugets?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the tool_fsc (and also this) and that was my impression.

<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRunCrossgen2ExtraArgs>--embed-pgo-data</PublishReadyToRunCrossgen2ExtraArgs>
</PropertyGroup>

<ItemGroup>
<PublishReadyToRunPgoFiles Include="@(MibcFiles)"/>
</ItemGroup>
</Target>

</Project>
11 changes: 11 additions & 0 deletions src/fsi/fsi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" />
</ItemGroup>

<Target Name="Add PGO" DependsOnTargets="Get MIBC data" BeforeTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRunCrossgen2ExtraArgs>--embed-pgo-data</PublishReadyToRunCrossgen2ExtraArgs>
</PropertyGroup>

<ItemGroup>
<PublishReadyToRunPgoFiles Include="@(MibcFiles)"/>
</ItemGroup>
</Target>

</Project>
Loading