Skip to content

Latest commit

 

History

History
317 lines (224 loc) · 20 KB

Installation.md

File metadata and controls

317 lines (224 loc) · 20 KB

Install Swift for TensorFlow

To install Swift for TensorFlow, download one of the packages below and follow the instructions for your operating system. After installation, you can use the full suite of Swift tools, including swift (Swift REPL/interpreter) and swiftc (Swift compiler). See here for more details about using Swift for TensorFlow.

Note:

  • If you want to modify the Swift for TensorFlow source code or build with a custom version of TensorFlow, see here for instructions on building from source.
  • Swift for TensorFlow is an early stage project. It has been released to enable open source development and is not yet ready for general use by machine learning developers.

Releases

Release notes for v0.10.0

Download Version Date
Xcode 11 v0.10 June 16, 2020
Ubuntu 18.04 (CPU Only) v0.10 June 16, 2020
Ubuntu 18.04 (CUDA 10.2) v0.10 June 16, 2020
Ubuntu 18.04 (CUDA 10.1) v0.10 June 16, 2020

Release Candidates

Release notes for v0.11.0

Download Version Date
Xcode 11 v0.11-rc1 July 21, 2020
Ubuntu 18.04 (CPU Only) v0.11-rc1 July 21, 2020
Ubuntu 18.04 (CUDA 10.2) v0.11-rc1 July 21, 2020
Ubuntu 18.04 (CUDA 10.1) v0.11-rc1 July 21, 2020
Older Packages

Release notes for v0.9.0

Download Version Date
Xcode 11 v0.9 May 08, 2020
Ubuntu 18.04 (CPU, TPU) v0.9 Apr 30, 2020
Ubuntu 18.04 (CPU, CUDA 10.2, TPU) v0.9 Apr 30, 2020
Ubuntu 18.04 (CPU, CUDA 10.1, TPU) v0.9 Apr 30, 2020

Release notes for v0.8.0

Download Version Date
Xcode 11 v0.8 Mar 17, 2020
Ubuntu 18.04 (CPU Only) v0.8 Mar 17, 2020
Ubuntu 18.04 (CUDA 10.1) v0.8 Mar 17, 2020
Ubuntu 18.04 (CUDA 10.0) v0.8 Mar 17, 2020
Ubuntu 18.04 (CUDA 9.2) v0.8 Mar 17, 2020

Release notes for v0.7.0

Download Version Date
Xcode 11 v0.7.0 Feb 12, 2020
Ubuntu 18.04 (CPU Only) v0.7.0 Feb 12, 2020
Ubuntu 18.04 (CUDA 10.1) v0.7.0 Feb 12, 2020
Ubuntu 18.04 (CUDA 10.0) v0.7.0 Feb 12, 2020
Ubuntu 18.04 (CUDA 9.2) v0.7.0 Feb 12, 2020

Release notes for v0.6.0

Download Version Date
Xcode 11 v0.6.0 Dec 10, 2019
Ubuntu 18.04 (CPU Only) v0.6.0 Dec 10, 2019
Ubuntu 18.04 (CUDA 10.1) v0.6.0 Dec 10, 2019
Ubuntu 18.04 (CUDA 10.0) v0.6.0 Dec 10, 2019
Ubuntu 18.04 (CUDA 9.2) v0.6.0 Dec 10, 2019

Release notes for v0.5.0

Download Version Date
Xcode 11 v0.5.0 Sep 19, 2019
Ubuntu 18.04 (CPU Only) v0.5.0 Sep 19, 2019
Ubuntu 18.04 (CUDA 10.0) v0.5.0 Sep 19, 2019
Ubuntu 18.04 (CUDA 9.2) v0.5.0 Sep 19, 2019
Download Version Date
Xcode 11 beta v0.4.0 July 25, 2019
Ubuntu 18.04 (CPU Only) v0.4.0 July 25, 2019
Ubuntu 18.04 (CUDA 10.0) v0.4.0 July 25, 2019
Ubuntu 18.04 (CUDA 9.2) v0.4.0 July 25, 2019
Download Version Date
Xcode 10 v0.3.1 April 30, 2019
Ubuntu 18.04 (CPU Only) v0.3.1 April 30, 2019
Ubuntu 18.04 (CUDA 10.0) v0.3.1 April 30, 2019
Ubuntu 18.04 (CUDA 9.2) v0.3.1 April 30, 2019
Download Version Date
Xcode 10 v0.3 April 23, 2019
Ubuntu 18.04 (CPU Only) v0.3 April 23, 2019
Ubuntu 18.04 (CUDA 10.0) v0.3 April 23, 2019
Ubuntu 18.04 (CUDA 9.2) v0.3 April 23, 2019
Download Version Date
Xcode 10 v0.2 March 1, 2019
Ubuntu 18.04 (CPU Only) v0.2 March 1, 2019
Ubuntu 18.04 (CUDA 10.0) v0.2 March 1, 2019
Ubuntu 18.04 (CUDA 9.2) v0.2 March 1, 2019

Development Snapshots

Download
Xcode 11 (July 16, 2020)
Ubuntu 18.04 (CPU, TPU) (Nightly)
Ubuntu 18.04 (CPU, CUDA 10.2, TPU) (Nightly)
Ubuntu 18.04 (CPU, CUDA 10.1, TPU) (Nightly)
Windows (June 23, 2020)
Older Packages

Xcode

Xcode 11

Download
July 11, 2020
July 2, 2020
June 25, 2020

Note: Currently, the Xcode toolchains above only support macOS development. iOS/tvOS/watchOS are not supported.

Using Downloads

macOS

Requirements

  • macOS 10.15 or later
  • Xcode 11 or later

Installation

  1. Download the latest package release.

  2. Run the package installer, which will install an Xcode toolchain into /Library/Developer/Toolchains/.

  3. An Xcode toolchain (.xctoolchain) includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift.

  4. Open Xcode's Preferences, navigate to Components > Toolchains, and select the installed Swift for TensorFlow toolchain.

  5. Xcode uses the selected toolchain for building Swift code, debugging, and even code completion and syntax coloring. You'll see a new toolchain indicator in Xcode's toolbar when Xcode is using a Swift toolchain. Select the Xcode toolchain to go back to Xcode's built-in tools.

Select toolchain in Xcode preferences.

  1. Selecting a Swift toolchain affects the Xcode IDE only. To use the Swift toolchain with command-line tools, use xcrun --toolchain swift and xcodebuild -toolchain swift, or add the Swift toolchain to your path as follows:

    $ export PATH=/Library/Developer/Toolchains/swift-latest/usr/bin:"${PATH}"
  2. CUDA-only: If you downloaded a CUDA GPU-enabled toolchain, add the library path(s) for CUDA and cuDNN to $LD_LIBRARY_PATH:

    $ export LD_LIBRARY_PATH=/usr/local/cuda/lib:"${LD_LIBRARY_PATH}"

Linux

Packages for Linux are tar archives including a copy of the Swift compiler, lldb, and related tools. You can install them anywhere as long as the extracted tools are in your PATH. Note that nothing prevents Swift from being ported to other Linux distributions beyond the ones mentioned below. These are only the distributions where these binaries have been built and tested.

Requirements

  • Ubuntu 18.04 (64-bit)

Supported Target Platforms

  • Ubuntu 18.04 (64-bit)

Additional Requirements

  • For GPU toolchains:
    • CUDA Toolkit 10.1 or 10.2
    • CuDNN 7.6.0 onwards (CUDA 10.1)
    • An NVIDIA GPU with compute compatibility 3.5, 3.7, 6.0, 6.1, 7.0, or 7.5.

For detailed instructons on setting up CUDA and CuDNN, please see the TensorFlow Docs.

Installation

  1. Install required dependencies:
$ sudo apt-get install clang libpython-dev libblocksruntime-dev

(Note: You may also need to install other dependencies, if you are unable to run swift or other tools below.)

  1. Download the latest binary release above.

The swift-tensorflow-<VERSION>-<PLATFORM>.tar.gz file is the toolchain itself.

  1. Extract the archive with the following command:
$ tar xzf swift-tensorflow-<VERSION>-<PLATFORM>.tar.gz

This creates a usr/ directory in the location of the archive.

  1. Add the Swift toolchain to your path as follows:
$ export PATH=$(pwd)/usr/bin:"${PATH}"

You can now execute the swiftc command to build Swift projects.

Note: If you are using a CUDA build and you have an NVIDIA GPU with a compute capability other than 3.5 or 7.0, then you will experience a ~10 minute delay the first time you execute a TensorFlow operation, while TensorFlow compiles kernels for your GPU's compute capability. The program will not print anything out and it will appear to be frozen.

Windows

Requirements

  • Windows 10 October 2018 Update (RedStone 5 - 10.0.17763.0) or later1
  • Visual Studio 2017 or later (Visual Studio 2019 is recommended)
  • CMake 3.16 or later

Installation

  1. Install Visual Studio from Microsoft.

The following table lists the required set of installed components:

Component ID
MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.25) Microsoft.VisualStudio.Component.VC.Tools.x86.x64
Windows Univeral C Runtime Microsoft.VisualStudio.Component.Windows10SDK
Windows 10 SDK (10.0.17763.0)2 Microsoft.VisualStudio.Component.Windows10SDK.17763

The following table lists the additional recommended set of installed components:

Component ID
C++ ATL for latest v142 build tools (x86 & x64)3 Microsoft.VisualStudio.Component.VC.ATL
C++ CMake tools for Windows4 Microsoft.VisualStudio.Component.VC.CMake.Project
Git for Windows5 Microsoft.VisualStudio.Component.Git
Python 3 64-bit (3.7.5)6 Component.CPython.x64
  1. Install CMake from cmake.

  2. Download and run the latest release from Swift for TensorFlow. The installer will install a toolchain into %SystemDrive%\Library\Developer\Toolchains. The toolchain (.xctoolchain) includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift.

  3. Deploy the Windows SDK modulemaps from an (elevated) "Administrator" x64 Native Tools for VS2019 Command Prompt shell7:

set SDKROOT=%SystemDrive%\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"

1 You can check which version of Windows you are currently running by opening command prompt and entering winver.
2 You may install a newer SDK if you desire. 17763 is listed here to match the minimum Windows release supported.
3 Needed for parts of lldb.
4 Provides ninja which is needed for building projects. You may download it from ninja-build instead.
5 Provides git to clone projects from GitHub. You may download it from git-scm instead.
6 Provides python needed for Python integration. You may download it from python instead.
7 This will need to be re-run every time Visual Studio is updated.

Verify the Installation

Create a text file test.swift with the following contents:

import TensorFlow
var x = Tensor<Float>([[1, 2], [3, 4]])
print(x + x)

To build on Linux/MacOS

Run these commands to verify the installation.

$ swiftc test.swift
$ test

To build on Windows

Run these commands to verify the installation.

$ set SDKROOT=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
$ swiftc -sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows -emit-executable -o test.exe test.swift
$ test.exe

N.B. Interpreter mode and direct invocation from VS 2019 are currently not supported on Windows.

Verify Output

If you see this output, you have successfully installed Swift for TensorFlow!

[[2.0, 4.0],
 [6.0, 8.0]]