Skip to content

Commit 6f39b48

Browse files
Amine Chadlychaami
authored andcommitted
Complete a nuget for TensorFlow Gpu redist
1 parent 0b815f0 commit 6f39b48

5 files changed

Lines changed: 292 additions & 20 deletions

File tree

TensorFlow.NET.sln

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EA9A
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist", "src\runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist\runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist.csproj", "{BEC7FC31-58BD-48C1-96CE-6B68570A5431}"
3131
EndProject
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SciSharp.TensorFlow-Gpu.Redist", "src\SciSharp.TensorFlow-Gpu.Redist\SciSharp.TensorFlow-Gpu.Redist.csproj", "{FAF0995D-88B9-444B-866F-2E9EB07D77A6}"
33+
EndProject
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist", "src\runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist\runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist.csproj", "{E26AA660-F734-444C-A982-3F19C2AF8829}"
35+
EndProject
3236
Global
3337
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3438
Debug|Any CPU = Debug|Any CPU
@@ -67,7 +71,6 @@ Global
6771
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Debug|Any CPU.Build.0 = Debug|Any CPU
6872
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.ActiveCfg = Release|Any CPU
6973
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.Build.0 = Release|Any CPU
70-
<<<<<<< HEAD
7174
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7275
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Debug|Any CPU.Build.0 = Debug|Any CPU
7376
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -76,12 +79,18 @@ Global
7679
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Debug|Any CPU.Build.0 = Debug|Any CPU
7780
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Release|Any CPU.ActiveCfg = Release|Any CPU
7881
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Release|Any CPU.Build.0 = Release|Any CPU
79-
=======
8082
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8183
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Debug|Any CPU.Build.0 = Debug|Any CPU
8284
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Release|Any CPU.ActiveCfg = Release|Any CPU
8385
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Release|Any CPU.Build.0 = Release|Any CPU
84-
>>>>>>> Provide the win-x64 runtime nuget for TensorFlow Gpu
86+
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
87+
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Release|Any CPU.Build.0 = Release|Any CPU
90+
{E26AA660-F734-444C-A982-3F19C2AF8829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
91+
{E26AA660-F734-444C-A982-3F19C2AF8829}.Debug|Any CPU.Build.0 = Debug|Any CPU
92+
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.ActiveCfg = Release|Any CPU
93+
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.Build.0 = Release|Any CPU
8594
EndGlobalSection
8695
GlobalSection(SolutionProperties) = preSolution
8796
HideSolutionNode = FALSE
Lines changed: 145 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,149 @@
1-
$targetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist")
2-
3-
$fileName = "libtensorflow-gpu-windows-x86_64-1.14.0.zip"
4-
$zipfile = [IO.Path]::Combine($PSScriptRoot, "..", "packages", $fileName)
5-
if (-not (Test-Path $zipfile -PathType Leaf)) {
6-
# Create the directory just in case it's actually needed...
7-
$path = [IO.Path]::Combine($PSScriptRoot, "..", "packages")
8-
New-Item -Path $path -Force -ItemType Directory
9-
Write-Host "Downloading libtensorflow gpu for Windows..."
1+
<#
2+
.SYNOPSIS
3+
Copy the native TensorFlow library to enable the packing a nuget to make
4+
them available to TensorFlow.NET
5+
6+
.DESCRIPTION
7+
The TensorFlow libraries are copied for Windows and Linux and it becomes
8+
possible to bundle a meta-package containing them.
9+
10+
.PARAMETER CpuLibraries
11+
Switch indicating if the script should download the CPU or GPU version of the
12+
TensorFlow libraries.
13+
By default the GPU version of the libraries is downloaded.
14+
15+
#>
16+
param(
17+
[switch] $CpuLibraries = $false
18+
)
19+
20+
function Expand-TarGzFiles {
21+
<#
22+
.SYNOPSIS
23+
Expands the given list of files from the given archive into the given
24+
target directory.
25+
26+
.PARAMETER Archive
27+
Path to the archive that should be considered.
28+
29+
.PARAMETER Files
30+
Files that should be extracted from the archive.
31+
32+
.PARAMETER TargetDirectory
33+
Directory into which the files should be expanded.
34+
35+
#>
36+
param
37+
(
38+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $Archive,
39+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string []] $Files,
40+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $TargetDirectory
41+
)
42+
43+
& 7z e $Archive -o"$TargetDirectory"
44+
$TarArchive = Join-Path $TargetDirectory "libtensorflow.tar"
45+
46+
& 7z e $TarArchive $Files -o"$TargetDirectory"
47+
Remove-Item $TarArchive
48+
}
49+
50+
function Expand-ZipFiles {
51+
<#
52+
.SYNOPSIS
53+
Expands the given list of files from the given archive into the given target directory.
54+
55+
.PARAMETER Archive
56+
Path to the archive that should be considered.
57+
58+
.PARAMETER Files
59+
Files that should be extracted from the archive.
60+
61+
.PARAMETER TargetDirectory
62+
Directory into which the files should be expanded.
63+
#>
64+
param(
65+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $Archive,
66+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string []] $Files,
67+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $TargetDirectory
68+
)
69+
70+
& 7z e $Archive $Files -o"$TargetDirectory"
71+
}
72+
73+
function Split-ArchiveFromUrl {
74+
<#
75+
.SYNOPSIS
76+
Extracts the archive name out of the given Url.
77+
78+
.PARAMETER ArchiveUrl
79+
Url of the archive that will be downloaded.
80+
81+
#>
82+
param(
83+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $ArchiveUrl
84+
)
85+
86+
$uriParts = $ArchiveUrl.split("/")
87+
$ArchivePath = $uriParts[$uriParts.Count - 1]
88+
89+
return $ArchivePath
90+
}
91+
92+
function Copy-Archive {
93+
<#
94+
.SYNOPSIS
95+
This function copies the given binary file to the given target location.
96+
97+
.PARAMETER ArchiveUrl
98+
Url where the archive should be downloaded from.
99+
100+
.PARAMETER TargetDirectory
101+
Target directory where the archive should be downloaded.
102+
#>
103+
param (
104+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
105+
[string] $ArchiveUrl,
106+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
107+
[string] $TargetDirectory
108+
)
109+
110+
$ArchiveName = Split-ArchiveFromUrl $ArchiveUrl
111+
112+
$TargetPath = [IO.Path]::Combine($PSScriptRoot, "..", "packages", $ArchiveName)
113+
114+
if (Test-Path $TargetPath -PathType Leaf) {
115+
Write-Error "$TargetPath already exists, please remove to download againg."
116+
return $TargetPath
117+
}
118+
119+
if (-not (Test-Path $TargetDirectory -PathType Container)) {
120+
Write-Host "Creating missing $TargetDirectory"
121+
New-Item -Path $TargetDirectory -ItemType Directory
122+
}
123+
Write-Host "Downloading $ArchiveUrl, this might take a while..."
10124
$wc = New-Object System.Net.WebClient
11-
$wc.DownloadFile("https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip", $zipfile)
125+
$wc.DownloadFile($ArchiveUrl, $TargetPath)
126+
127+
return $TargetPath
128+
}
129+
130+
$LinuxGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz"
131+
$LinuxFiles = @(".\libtensorflow.tar", ".\lib\libtensorflow.so", ".\lib\libtensorflow.so.1", ".\lib\libtensorflow.so.1.14.0", `
132+
".\lib\libtensorflow_framework.so", ".\lib\libtensorflow_framework.so.1", ".\lib\libtensorflow_framework.so.1.14.0")
133+
$WindowsGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip"
134+
$WindowsFiles = @("lib\tensorflow.dll")
135+
$PackagesDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "packages")
136+
137+
138+
if (-not $CpuLibraries) {
139+
$WindowsArchive = $WindowsGpuArchive
140+
$LinuxArchive = $LinuxGpuArchive
12141
}
13142

14-
$libraryName = "tensoflow.dll"
15-
$libraryLocation = "lib\tensorflow.dll"
16-
$windowsTensorFlow = Join-Path $targetDirectory $libraryName
143+
$Archive = Copy-Archive -ArchiveUrl $WindowsArchive -TargetDirectory $PackagesDirectory
144+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist")
145+
Expand-ZipFiles $Archive $WindowsFiles $TargetDirectory
17146

18-
if (-not (Test-Path $windowsTensorFlow))
19-
{
20-
& 7z e $zipfile $libraryLocation -o"$targetDirectory"
21-
}
147+
$Archive = Copy-Archive -ArchiveUrl $LinuxArchive -TargetDirectory $PackagesDirectory
148+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist")
149+
Expand-TarGzFiles $Archive $LinuxFiles $TargetDirectory
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<!-- TensorFlow doesn't support Gpus on Mac Os. -->
7+
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
8+
<AssemblyName>SciSharp.Tensorflow-Gpu.Redist</AssemblyName>
9+
10+
<PackageId>SciSharp.Tensorflow-Gpu.Redist</PackageId>
11+
<Version>1.0.0</Version>
12+
<Authors>SciSharp team</Authors>
13+
<Company>SciSharp STACK</Company>
14+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
15+
<RepositoryType>git</RepositoryType>
16+
<Description>
17+
Meta-package for GPU Tensoflow library runtime distribution.
18+
Libraries can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
19+
</Description>
20+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
21+
22+
<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
23+
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
24+
<PackageOutputPath>../../packages</PackageOutputPath>
25+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
26+
27+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
28+
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
29+
<IncludeBuildOutput>false</IncludeBuildOutput>
30+
</PropertyGroup>
31+
32+
<!-- Need to add some dependencies so Meta-Project will pull runtime Project(s) -->
33+
<Target Name="ValidateRuntimePack" BeforeTargets="GenerateNuspec">
34+
<ItemGroup>
35+
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
36+
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
37+
</ItemGroup>
38+
<Message
39+
Importance="high"
40+
Text="Package runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist: found"
41+
Condition="Exists('@(RuntimeLinux)')" />
42+
<Message
43+
Importance="high"
44+
Text="Package runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist: not found"
45+
Condition="!Exists('@(RuntimeLinux)')" />
46+
<Message
47+
Importance="high"
48+
Text="Package runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist: found"
49+
Condition="Exists('@(RuntimeWin)')" />
50+
<Message
51+
Importance="high"
52+
Text="Package runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist: not found"
53+
Condition="!Exists('@(RuntimeWin)')" />
54+
<Error
55+
Text="You must locally 'dotnet pack' at least one runtime.{rid}.SciSharp.Tensorflow-Gpu.Redist project."
56+
Condition="!Exists('@(RuntimeLinux)') AND !Exists('@(RuntimeWin)')" />
57+
</Target>
58+
59+
<PropertyGroup>
60+
<RestoreSources>../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
61+
</PropertyGroup>
62+
<ItemGroup Condition="Exists('../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.1.0.0.nupkg')">
63+
<PackageReference Include="runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist" Version="1.0.0" />
64+
</ItemGroup>
65+
<ItemGroup Condition="Exists('../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.1.0.0.nupkg')">
66+
<PackageReference Include="runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist" Version="1.0.0" />
67+
</ItemGroup>
68+
69+
<ItemGroup>
70+
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
71+
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
72+
<Content
73+
Include="runtime.json"
74+
Condition="Exists('@(RuntimeLinux)') AND Exists('@(RuntimeWin)')">
75+
<PackagePath>runtime.json</PackagePath>
76+
<Pack>true</Pack>
77+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
78+
</Content>
79+
</ItemGroup>
80+
81+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"runtimes": {
3+
"linux-x64": {
4+
"SciSharp.TensorFlow-Gpu.Redist": {
5+
"runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist": "1.0.0"
6+
}
7+
},
8+
"win-x64": {
9+
"SciSharp.TensorFlow-Gpu.Redist": {
10+
"runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist": "1.0.0"
11+
}
12+
}
13+
}
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
7+
<AssemblyName>SciSharp.Tensorflow-Gpu.Redist</AssemblyName>
8+
9+
<PackageId>runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist</PackageId>
10+
<Version>1.0.0</Version>
11+
<Authors>SciSharp team</Authors>
12+
<Company>SciSharp STACK</Company>
13+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
14+
<RepositoryType>git</RepositoryType>
15+
<Description>
16+
Distribution of the Linux GPU Tensoflow library.
17+
Dll can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
18+
</Description>
19+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
20+
21+
<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
22+
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
23+
<PackageOutputPath>../../packages</PackageOutputPath>
24+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
25+
26+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
27+
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
28+
<IncludeBuildOutput>false</IncludeBuildOutput>
29+
</PropertyGroup>
30+
31+
<ItemGroup>
32+
<!-- All dlls will be dropped in a folder available through DllImport.-->
33+
<Content Include="*.so.*">
34+
<PackagePath>runtimes/$(RuntimeIdentifier)/native/%(Filename)%(Extension)</PackagePath>
35+
<Pack>true</Pack>
36+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
37+
</Content>
38+
</ItemGroup>
39+
40+
</Project>

0 commit comments

Comments
 (0)