Browse Source

Complete a nuget for TensorFlow Gpu redist

tags/v0.12
Amine Chadly Amine Chadly 6 years ago
parent
commit
6f39b48b8e
5 changed files with 292 additions and 20 deletions
  1. +12
    -3
      TensorFlow.NET.sln
  2. +145
    -17
      scripts/Copy-NativeTensorFlowLibs.ps1
  3. +81
    -0
      src/SciSharp.TensorFlow-Gpu.Redist/SciSharp.TensorFlow-Gpu.Redist.csproj
  4. +14
    -0
      src/SciSharp.TensorFlow-Gpu.Redist/runtime.json
  5. +40
    -0
      src/runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist/runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist.csproj

+ 12
- 3
TensorFlow.NET.sln View File

@@ -29,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EA9A
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -67,7 +71,6 @@ Global
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.Build.0 = Release|Any CPU
<<<<<<< HEAD
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF151A51-E9FD-41BD-B0F4-08A743755D44}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -76,12 +79,18 @@ Global
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F6B3382-8F87-4CD9-BF87-C81D5405685A}.Release|Any CPU.Build.0 = Release|Any CPU
=======
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEC7FC31-58BD-48C1-96CE-6B68570A5431}.Release|Any CPU.Build.0 = Release|Any CPU
>>>>>>> Provide the win-x64 runtime nuget for TensorFlow Gpu
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAF0995D-88B9-444B-866F-2E9EB07D77A6}.Release|Any CPU.Build.0 = Release|Any CPU
{E26AA660-F734-444C-A982-3F19C2AF8829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E26AA660-F734-444C-A982-3F19C2AF8829}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 145
- 17
scripts/Copy-NativeTensorFlowLibs.ps1 View File

@@ -1,21 +1,149 @@
$targetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist")

$fileName = "libtensorflow-gpu-windows-x86_64-1.14.0.zip"
$zipfile = [IO.Path]::Combine($PSScriptRoot, "..", "packages", $fileName)
if (-not (Test-Path $zipfile -PathType Leaf)) {
# Create the directory just in case it's actually needed...
$path = [IO.Path]::Combine($PSScriptRoot, "..", "packages")
New-Item -Path $path -Force -ItemType Directory
Write-Host "Downloading libtensorflow gpu for Windows..."
<#
.SYNOPSIS
Copy the native TensorFlow library to enable the packing a nuget to make
them available to TensorFlow.NET

.DESCRIPTION
The TensorFlow libraries are copied for Windows and Linux and it becomes
possible to bundle a meta-package containing them.

.PARAMETER CpuLibraries
Switch indicating if the script should download the CPU or GPU version of the
TensorFlow libraries.
By default the GPU version of the libraries is downloaded.

#>
param(
[switch] $CpuLibraries = $false
)

function Expand-TarGzFiles {
<#
.SYNOPSIS
Expands the given list of files from the given archive into the given
target directory.

.PARAMETER Archive
Path to the archive that should be considered.

.PARAMETER Files
Files that should be extracted from the archive.

.PARAMETER TargetDirectory
Directory into which the files should be expanded.

#>
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $Archive,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string []] $Files,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $TargetDirectory
)

& 7z e $Archive -o"$TargetDirectory"
$TarArchive = Join-Path $TargetDirectory "libtensorflow.tar"

& 7z e $TarArchive $Files -o"$TargetDirectory"
Remove-Item $TarArchive
}

function Expand-ZipFiles {
<#
.SYNOPSIS
Expands the given list of files from the given archive into the given target directory.

.PARAMETER Archive
Path to the archive that should be considered.

.PARAMETER Files
Files that should be extracted from the archive.

.PARAMETER TargetDirectory
Directory into which the files should be expanded.
#>
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $Archive,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string []] $Files,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $TargetDirectory
)

& 7z e $Archive $Files -o"$TargetDirectory"
}

function Split-ArchiveFromUrl {
<#
.SYNOPSIS
Extracts the archive name out of the given Url.

.PARAMETER ArchiveUrl
Url of the archive that will be downloaded.

#>
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $ArchiveUrl
)
$uriParts = $ArchiveUrl.split("/")
$ArchivePath = $uriParts[$uriParts.Count - 1]

return $ArchivePath
}

function Copy-Archive {
<#
.SYNOPSIS
This function copies the given binary file to the given target location.

.PARAMETER ArchiveUrl
Url where the archive should be downloaded from.

.PARAMETER TargetDirectory
Target directory where the archive should be downloaded.
#>
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $ArchiveUrl,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $TargetDirectory
)

$ArchiveName = Split-ArchiveFromUrl $ArchiveUrl

$TargetPath = [IO.Path]::Combine($PSScriptRoot, "..", "packages", $ArchiveName)

if (Test-Path $TargetPath -PathType Leaf) {
Write-Error "$TargetPath already exists, please remove to download againg."
return $TargetPath
}

if (-not (Test-Path $TargetDirectory -PathType Container)) {
Write-Host "Creating missing $TargetDirectory"
New-Item -Path $TargetDirectory -ItemType Directory
}
Write-Host "Downloading $ArchiveUrl, this might take a while..."
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip", $zipfile)
$wc.DownloadFile($ArchiveUrl, $TargetPath)

return $TargetPath
}

$LinuxGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz"
$LinuxFiles = @(".\libtensorflow.tar", ".\lib\libtensorflow.so", ".\lib\libtensorflow.so.1", ".\lib\libtensorflow.so.1.14.0", `
".\lib\libtensorflow_framework.so", ".\lib\libtensorflow_framework.so.1", ".\lib\libtensorflow_framework.so.1.14.0")
$WindowsGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip"
$WindowsFiles = @("lib\tensorflow.dll")
$PackagesDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "packages")


if (-not $CpuLibraries) {
$WindowsArchive = $WindowsGpuArchive
$LinuxArchive = $LinuxGpuArchive
}

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

if (-not (Test-Path $windowsTensorFlow))
{
& 7z e $zipfile $libraryLocation -o"$targetDirectory"
}
$Archive = Copy-Archive -ArchiveUrl $LinuxArchive -TargetDirectory $PackagesDirectory
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist")
Expand-TarGzFiles $Archive $LinuxFiles $TargetDirectory

+ 81
- 0
src/SciSharp.TensorFlow-Gpu.Redist/SciSharp.TensorFlow-Gpu.Redist.csproj View File

@@ -0,0 +1,81 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- TensorFlow doesn't support Gpus on Mac Os. -->
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<AssemblyName>SciSharp.Tensorflow-Gpu.Redist</AssemblyName>

<PackageId>SciSharp.Tensorflow-Gpu.Redist</PackageId>
<Version>1.0.0</Version>
<Authors>SciSharp team</Authors>
<Company>SciSharp STACK</Company>
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Description>
Meta-package for GPU Tensoflow library runtime distribution.
Libraries can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
<PackageOutputPath>../../packages</PackageOutputPath>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<!-- Need to add some dependencies so Meta-Project will pull runtime Project(s) -->
<Target Name="ValidateRuntimePack" BeforeTargets="GenerateNuspec">
<ItemGroup>
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
</ItemGroup>
<Message
Importance="high"
Text="Package runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist: found"
Condition="Exists('@(RuntimeLinux)')" />
<Message
Importance="high"
Text="Package runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist: not found"
Condition="!Exists('@(RuntimeLinux)')" />
<Message
Importance="high"
Text="Package runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist: found"
Condition="Exists('@(RuntimeWin)')" />
<Message
Importance="high"
Text="Package runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist: not found"
Condition="!Exists('@(RuntimeWin)')" />
<Error
Text="You must locally 'dotnet pack' at least one runtime.{rid}.SciSharp.Tensorflow-Gpu.Redist project."
Condition="!Exists('@(RuntimeLinux)') AND !Exists('@(RuntimeWin)')" />
</Target>

<PropertyGroup>
<RestoreSources>../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup Condition="Exists('../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.1.0.0.nupkg')">
<PackageReference Include="runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="Exists('../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.1.0.0.nupkg')">
<PackageReference Include="runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist.*.nupkg" />
<Content
Include="runtime.json"
Condition="Exists('@(RuntimeLinux)') AND Exists('@(RuntimeWin)')">
<PackagePath>runtime.json</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>

+ 14
- 0
src/SciSharp.TensorFlow-Gpu.Redist/runtime.json View File

@@ -0,0 +1,14 @@
{
"runtimes": {
"linux-x64": {
"SciSharp.TensorFlow-Gpu.Redist": {
"runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist": "1.0.0"
}
},
"win-x64": {
"SciSharp.TensorFlow-Gpu.Redist": {
"runtime.win-x64.SciSharp.Tensorflow-Gpu.Redist": "1.0.0"
}
}
}
}

+ 40
- 0
src/runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist/runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist.csproj View File

@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<AssemblyName>SciSharp.Tensorflow-Gpu.Redist</AssemblyName>

<PackageId>runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist</PackageId>
<Version>1.0.0</Version>
<Authors>SciSharp team</Authors>
<Company>SciSharp STACK</Company>
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Description>
Distribution of the Linux GPU Tensoflow library.
Dll can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
<PackageOutputPath>../../packages</PackageOutputPath>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<ItemGroup>
<!-- All dlls will be dropped in a folder available through DllImport.-->
<Content Include="*.so.*">
<PackagePath>runtimes/$(RuntimeIdentifier)/native/%(Filename)%(Extension)</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>

Loading…
Cancel
Save