Code Monkey home page Code Monkey logo

surge's Introduction

Surge Build Status GitHub license

Surge is a Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.

Accelerate exposes SIMD instructions available in modern CPUs to significantly improve performance of certain calculations. Because of its relative obscurity and inconvenient APIs, Accelerate is not commonly used by developers, which is a shame, since many applications could benefit from these performance optimizations.

Surge aims to bring Accelerate to the mainstream, making it as easy (and nearly as fast, in most cases) to perform computation over a set of numbers as for a single member.

Though, keep in mind: Accelerate is not a silver bullet. Under certain conditions, such as performing simple calculations over a small data set, Accelerate can be out-performed by conventional algorithms. Always benchmark to determine the performance characteristics of each potential approach.


Curious about the name Surge? Back in the mid 90's, Apple, IBM, and Motorola teamed up to create AltiVec (a.k.a the Velocity Engine), which provided a SIMD instruction set for the PowerPC architecture. When Apple made the switch to Intel CPUs, AltiVec was ported to the x86 architecture and rechristened Accelerate. The derivative of Accelerate (and second derivative of Velocity) is known as either jerk, jolt, surge, or lurch, hence the name of this library.


Performance

Initial benchmarks on iOS devices and the iOS simulator indicate significant performance improvements over a conventional Swift implementation.

import Surge

let numbers: [Double] = ...
var sum: Double = 0.0

// Naïve Swift Implementation
sum = reduce(numbers, 0.0, +)

// Surge Implementation
sum = Surge.sum(numbers)

(Time in milliseconds, Optimization Level -Ofast)

n Swift Surge Δ
100 0.269081 0.004453 ~60x
100000 251.037254 0.028687 ~9000x
100000000 239474.689326 57.009841 ~4000x

Surge's performance characteristics have not yet been thoroughly evaluated, though initial benchmarks show incredible promise. Further investigation is definitely warranted.

Installation

The infrastructure and best practices for distributing Swift libraries are currently in flux during this beta period of Swift & Xcode. In the meantime, you can add Surge as a git submodule, drag the Surge.xcodeproj file into your Xcode project, and add Surge.framework as a dependency for your target.


Inventory

Surge functions are named according to their corresponding "Math.h" functions, where applicable (omitting f and d affixes, since type information is communicated and enforced by the language's type system).

Arithmetic

  • sum
  • asum
  • max
  • min
  • mean
  • meamg
  • measq
  • add
  • sub
  • mul
  • div
  • mod
  • remainder
  • sqrt

Auxilliary

  • abs
  • ceil
  • copysign
  • floor
  • rec
  • round
  • trunc

Convolution

  • conv
  • xcorr

Exponential

  • exp
  • exp2
  • log
  • log2
  • log10
  • logb

FFT

  • fft

Hyperbolic

  • sinh
  • cosh
  • tanh
  • asinh
  • acosh
  • atanh

Matrix

  • add
  • mul
  • inv
  • transpose

Power

  • pow

Trigonometric

  • sincos
  • sin
  • cos
  • tan
  • asin
  • acos
  • atan
  • rad2deg
  • deg2rad

Usage

Computing Sum of [Double]

import Surge

let n = [1.0, 2.0, 3.0, 4.0, 5.0]
let sum = Surge.sum(n) // 15.0

Computing Product of Two [Double]s

import Surge

let a = [1.0, 3.0, 5.0, 7.0]
let b = [2.0, 4.0, 6.0, 8.0]

let product = Surge.mul(a, b) // [2.0, 12.0, 30.0, 56.0]

License

Surge is available under the MIT license. See the LICENSE file for more info.

surge's People

Contributors

mattt avatar rfdickerson avatar rprechelt avatar jasonhotsauce avatar robrix avatar jzzocc avatar arpesenti avatar apexskier avatar gkaimakas avatar lennet avatar zhxnlai avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.