Home

Awesome


Overview

SwiftRT is an experimental computational framework written in the Swift language. The project is under heavy devopment, so frequent changes should be expected.


Installation

This project requires the use of the Google Swift for TensorFlow custom toolchain (in place of the standard toolchain), because it leverages the toolchain's integrated auto differentiation functionality.

MacOS and Ubuntu CPU Only Installation

Currently a cpu build is available on MacOS.

  1. Install Xcode 12

  2. Install the Google Swift for TensorFlow Xcode 12 Toolchain, and in Xcode select the toolchain in the Preferences pane.

  3. Install and run the SwiftRT unit tests to verify the installation:

$ git clone https://github.com/ewconnell/swiftrt.git
$ cd swiftrt
$ swift test
  1. To create an Xcode project for debugging
$ swift package generate-xcodeproj

Ubuntu Cuda Installation

Currently the Swift Package Manager does not support building .cpp or cuda .cu files, so CMake is used. CMake and the SPM are used in combination in order to resolve dependent packages during build.

NOTE: all unit tests should pass with the CPU only build. The Cuda version is currently under development and there is no claim that the unit tests currently pass. This notice will be removed after they successfully pass.

  1. Install CUDA 11.0 and cuDNN with CUDA 11.0 support.

    Note: SwiftRT expects cuddn.h to be available from within /usr/local/cuda/include directory. If you install cudnn via the deb package, you might have to symlink it manually.

  2. Install the latest development snapshot of the Google Swift for TensorFlow Toolchain with CUDA 11.0.

  3. Add the following exports to your ~/.bashrc file, assuming SwiftRT installation is in the $HOME directory.

# swiftrt installation location
export SWIFTRT_HOME=$HOME/swiftrt

# add to pkgconfig path location of .pc files so SPM can link to Cuda
export PKG_CONFIG_PATH=$SWIFTRT_HOME/pkgconfig

# add `gyb` utility to path if you will be modifying the SwiftRT codebase
# and changing any .gyb files.
export PATH=$SWIFTRT_HOME/gyb:$PATH

# tells Package.swift to include a dependency and link to cuda
export SWIFTRT_PLATFORM=cuda

# cuda installation location
export CUDA_ROOT=/usr/local/cuda
export LIBRARY_PATH=$CUDA_ROOT/lib64

# to enable LLDB to find Cuda symbols
export C_INCLUDE_PATH=$CUDA_ROOT/include
export CPLUS_INCLUDE_PATH=$CUDA_ROOT/include

  1. CMake 3.18 or higher is required to build. If your current version is less than 3.18, download and install the latest version.

  2. To configure cmake for a Debug version

$ cd $SWIFTRT_HOME
$ mkdir build
$ cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=$SWIFT_HOME/usr/bin/clang-10 -H$SWIFTRT_HOME -B$SWIFTRT_HOME/build -DSWIFTRT_ENABLE_CUDA:BOOL=YES -G Ninja
  1. To build
$ cd $SWIFTRT_HOME
$ cmake --build ./build --target SwiftRTTestRunner
  1. To clean
$ cd $SWIFTRT_HOME
$ cmake --build ./build --target clean
$ rm -rf .build

Setting up VScode

VScode is the only IDE so far that seems to be able to build and debug using the custom S4TF toolchain.

  1. Install VScode
  2. The following extensions seem to work.
  1. The $SWIFTRT_HOME/Documents/vscode directory contains some helpful starter examples (launch and tasks) to configure the development environment.