forked from dotnet/TorchSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibtorch-cpu.proj
136 lines (118 loc) · 8.71 KB
/
libtorch-cpu.proj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- see https://pytorch.org/get-started/locally/ for download links -->
<!-- For example Linux, LibTorch 1.9.0 https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.9.0%2Bcpu.zip -->
<!-- note the very odd characters %2Bcpu in the LibTorch download name. The % is encoded via %25 -->
<LocalBaseName>$(LibTorchCpuLocalBase)</LocalBaseName>
<ArchiveBaseName>$(LibTorchCpuArchiveBase)</ArchiveBaseName>
<ArchiveExtension>.zip</ArchiveExtension>
<ArchiveUrl>https://download.pytorch.org/libtorch/cpu/$(ArchiveBaseName)$(ArchiveExtension)</ArchiveUrl>
<DownloadedArchiveFolder>$(MassiveDownloadRoot)$(MSBuildProjectName)\</DownloadedArchiveFolder>
<DownloadedArchiveFileName>$(ArchiveBaseName)$(ArchiveExtension)</DownloadedArchiveFileName>
<DownloadedArchive>$(DownloadedArchiveFolder)$(DownloadedArchiveFileName)</DownloadedArchive>
<ArchiveShaFile>$(IntermediateOutputPath)$(ArchiveBaseName)$(ArchiveExtension).sha</ArchiveShaFile>
<ExtractDirectory>$(IntermediateOutputPath)$(LocalBaseName)</ExtractDirectory>
<ExtractSemaphore>$(ExtractDirectory)\.extracted</ExtractSemaphore>
<LocalShaFile>$(MSBuildProjectDirectory)\$(ArchiveBaseName)$(ArchiveExtension).sha</LocalShaFile>
<LicenseUrl>https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE</LicenseUrl>
<DownloadedLicenseFolder>$(IntermediateOutputPath)</DownloadedLicenseFolder>
<DownloadedLicenseFileName>LICENSE-LIBTORCH</DownloadedLicenseFileName>
<DownloadedLicenseFile>$(DownloadedLicenseFolder)$(DownloadedLicenseFileName)</DownloadedLicenseFile>
<MainPackageFolder>$(PackagePreparationPath)$(MSBuildProjectName)-$(TargetRuntimeID)</MainPackageFolder>
<CopyToPackageSemaphore>$(MainPackageFolder)\.copied.SkipTests.$(SkipTests).IncludeLibTorchCpuPackages.$(IncludeLibTorchCpuPackages)</CopyToPackageSemaphore>
</PropertyGroup>
<ItemGroup Condition="'$(TargetOS)' == 'windows'">
<File Include="libtorch\lib\asmjit.dll" />
<File Include="libtorch\lib\c10.dll" />
<File Include="libtorch\lib\fbgemm.dll" />
<File Include="libtorch\lib\libiomp5md.dll" />
<File Include="libtorch\lib\libiompstubs5md.dll" />
<File Include="libtorch\lib\torch.dll" />
<File Include="libtorch\lib\torch_cpu.dll" />
<File Include="libtorch\lib\torch_global_deps.dll" />
<File Include="libtorch\lib\uv.dll" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'mac'">
<File Include="libtorch\lib\libbackend_with_compiler.dylib" />
<File Include="libtorch\lib\libc10.dylib" />
<File Include="libtorch\lib\libfbjni.dylib" />
<File Include="libtorch\lib\libiomp5.dylib" />
<File Include="libtorch\lib\libjitbackend_test.dylib" />
<File Include="libtorch\lib\libpytorch_jni.dylib" />
<File Include="libtorch\lib\libshm.dylib" />
<File Include="libtorch\lib\libtorch.dylib" />
<File Include="libtorch\lib\libtorch_cpu.dylib" />
<File Include="libtorch\lib\libtorch_global_deps.dylib" />
<File Include="libtorch\lib\libtorch_python.dylib" />
<File Include="libtorch\lib\libtorchbind_test.dylib" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'linux'">
<File Include="libtorch\lib\libbackend_with_compiler.so" />
<File Include="libtorch\lib\libc10.so" />
<File Include="libtorch\lib\libfbjni.so" />
<File Include="libtorch\lib\libjitbackend_test.so" />
<File Include="libtorch\lib\libnnapi_backend.so" />
<File Include="libtorch\lib\libpytorch_jni.so" />
<File Include="libtorch\lib\libshm.so" />
<File Include="libtorch\lib\libtorch.so" />
<File Include="libtorch\lib\libtorch_cpu.so" />
<File Include="libtorch\lib\libtorch_global_deps.so" />
<File Include="libtorch\lib\libtorch_python.so" />
<File Include="libtorch\lib\libtorchbind_test.so" />
<File Include="libtorch\lib\libgomp-a34b3233.so.1" />
</ItemGroup>
<Target Name="DownloadArchive" Inputs="..\..\..\LICENSE" Outputs="$(DownloadedArchive);$(DownloadedLicenseFile)">
<MakeDir Directories="$(DownloadedArchiveFolder)" />
<MakeDir Directories="$(DownloadedLicenseFolder)" />
<DownloadFile SourceUrl="$(ArchiveUrl)" DestinationFolder="$(DownloadedArchiveFolder)" DestinationFileName="$(DownloadedArchiveFileName)" Condition="!Exists('$(DownloadedArchive)')" />
<DownloadFile SourceUrl="$(LicenseUrl)" DestinationFolder="$(DownloadedLicenseFolder)" DestinationFileName="$(DownloadedLicenseFileName)" Condition="!Exists('$(DownloadedLicense)')" />
</Target>
<!-- Validate and extract Archive for Libtorch -->
<Target Name="ValidateAndExtractArchives" DependsOnTargets="DownloadArchive" Inputs="$(DownloadedArchive)" Outputs="$(ExtractSemaphore)">
<Message Importance="High" Text="GetFileHash $(DownloadedArchive)" />
<GetFileHash Files="$(DownloadedArchive)"> <Output TaskParameter="Hash" PropertyName="DownloadedArchiveHash" /> </GetFileHash>
<WriteLinesToFile File="$(ArchiveShaFile)" Lines="$(DownloadedArchiveHash)" Overwrite="true" />
<!-- If specified we'll update the checked in SHAs with the downloaded ones. -->
<Copy Condition="'$(UpdateSHA)' == 'true'" SourceFiles="$(ArchiveShaFile)" DestinationFiles="$(LocalShaFile)" />
<Error Condition="!Exists('$(LocalShaFile)')" Text="SHA file '$(LocalShaFile)' does not exist. Build with /p:UpdateSHA=true to save it." />
<!-- Read in the SHAs as metadata on the archive items -->
<ItemGroup>
<Archive>
<LocalSha>$([System.IO.File]::ReadAllText('$(LocalShaFile)'))</LocalSha>
<DownloadSha>$([System.IO.File]::ReadAllText('$(ArchiveShaFile)'))</DownloadSha>
</Archive>
</ItemGroup>
<!-- Validate that the downloaded SHAs match the expected checked in SHAs -->
<Error Condition="'%(Archive.LocalSha)' != '%(Archive.DownloadSha)'" Text="Downloaded file '$(DownloadedArchive)' has unexpected SHA.%0A expected: %(Archive.LocalSha)%0A actual: %(Archive.DownloadSha)%0ABuild with /p:UpdateSHA=true if you intentionally changed the URL and wish to update the SHAs, otherwise this could indicate an incomplete download or intercerpted URL and should be examined." />
<!-- The archives are valid, lets extract them, ensuring an empty directory -->
<RemoveDir Directories="$(ExtractDirectory)" />
<MakeDir Directories="$(ExtractDirectory)" />
<Message Importance="High" Text="Unzip $(DownloadedArchive) --> $(ExtractDirectory)" />
<Unzip Condition="'$(ArchiveExtension)' == '.zip'" SourceFiles="$(DownloadedArchive)" DestinationFolder="$(ExtractDirectory)" OverwriteReadOnlyFiles="true" />
<Exec Condition="'$(ArchiveExtension)' == '.tar.gz'"
WorkingDirectory="$(ExtractDirectory)"
Command="tar -xzmf "$([MSBuild]::MakeRelative('$(ExtractDirectory)', '$(DownloadedArchive)'))"" />
<WriteLinesToFile File="$(ExtractSemaphore)" Lines="done" Overwrite="true" />
<!-- delete the archive files when running on CI -->
<Message Importance="High" Text="Deleting '$(DownloadedArchive)' to free up space." Condition="'$(TF_BUILD)' != ''" />
<Delete Files="$(DownloadedArchive)" Condition="'$(TF_BUILD)' != ''" />
</Target>
<Target Name="CopyFilesFromArchive" DependsOnTargets="ValidateAndExtractArchives" Inputs="$(ExtractSemaphore)" Outputs="$(CopyToPackageSemaphore)">
<Message Importance="High" Text="Copy @(File) -> $(MainPackageFolder)\runtimes\$(TargetRuntimeID)\native\" />
<!-- Copy to MainPackageFolder to use in libtorch-cpu package build -->
<Copy SourceFiles="$(ExtractDirectory)\%(File.Identity)" DestinationFolder="$(MainPackageFolder)\runtimes\$(TargetRuntimeID)\native\" SkipUnchangedFiles="true" Condition="'$(IncludeLibTorchCpuPackages)' == 'true' "/>
<!-- Copy license to MainPackageFolder to use in libtorch-cpu packages build -->
<Copy SourceFiles="$(DownloadedLicenseFile)" DestinationFolder="$(MainPackageFolder)\" SkipUnchangedFiles="true" Condition="'$(IncludeLibTorchCpuPackages)' == 'true'" />
<!-- Copy to NativeOutputPath to use in tests (headers, lib etc.) -->
<MakeDir Directories="$(NativeOutputPath)" Condition="'$(SkipTests)' != 'true'" />
<Copy SourceFiles="$(ExtractDirectory)\%(File.Identity)" DestinationFolder="$(NativeOutputPath)" SkipUnchangedFiles="true" Condition="'$(SkipTests)' != 'true'" />
<WriteLinesToFile File="$(CopyToPackageSemaphore)" Lines="done" Overwrite="true" />
</Target>
<!-- Define Build to do the work of downloading and copying assets -->
<Target Name="Build" DependsOnTargets="CopyFilesFromArchive" />
<Target Name="Clean">
<RemoveDir Directories="$(IntermediateOutputPath)" />
</Target>
</Project>