Skip to content

Accelerate vForce #24152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 19, 2019
Merged

Conversation

stephentyrone
Copy link
Contributor

Adapted from @FlexMonkey 's PR, renaming and slightly changing the surface of _ContiguousCollection.

Since we are not adding ContiguousCollection to the standard library at this point in time, we can and should use something more narrowly tailored to Accelerate's needs. In particular, Accelerate does not require almost anything from Collection; it only needs withUnsafe[Mutable]BufferPointer, count, and the Element associatedtype. So let's pare the protocol back to only those things, and give it a name scoped as well: [Mutable]AccelerateBuffer.

In practice, most types people use with these API will be Collections anyway, but this enables two useful additional use cases:

- Fixed-size buffers
- Retroactive conformance of SIMD types

FlexMonkey and others added 12 commits April 18, 2019 21:13
This PR contains a suite of overlays to the vForce transcendental and trigonometric functions on vectors of any length.
The overlays simplify the API to the existing functions and accept collections that implement `_ContiguousCollection`.
Mainly renames of functions (e.g. `ceiling` to `ceil`) and parameters (e.g. `numerators` to `dividends`).
* Create individual `log2`and `log10` functions.
* Rename `exponent` to `logb`
* `squareRoot` -> `sqrt`
* `reciprocalSquareRoot` -> `rsqrt`
* `xxx(piTimes:...)` -> `xxxPi(:_....)`
Since we are not adding ContiguousCollection to the standard library at this point in time, we can and should use something more narrowly tailored to Accelerate's needs. In particular, Accelerate does not require almost anything from Collection; it only needs withUnsafe[Mutable]BufferPointer, count, and the Element associatedtype. So let's pare the protocol back to only those things, and give it a name scoped as well: [Mutable]AccelerateBuffer.

In practice, most types people use with these API will be Collections anyway, but this enables a few useful additional use cases:

- Fixed-size buffers
- Retroactive conformance of SIMD types
@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@stephentyrone
Copy link
Contributor Author

@DougGregor This moves the protocol outside the Collection hierarchy, and gives it a name that should make it less of an attractive nuisance that people might use in their own code. Does this partially alleviate your concerns?

@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@stephentyrone
Copy link
Contributor Author

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e91bcfc

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e91bcfc

@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@stephentyrone stephentyrone marked this pull request as ready for review April 19, 2019 14:15
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6ef3f2d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6ef3f2d

@stephentyrone
Copy link
Contributor Author

@swift-ci please smoke test linux

@stephentyrone
Copy link
Contributor Author

The one linux failure is LLDB, and unrelated to this change. Running smoke test instead.

@stephentyrone stephentyrone merged commit d05cd67 into swiftlang:master Apr 19, 2019
@stephentyrone stephentyrone deleted the accelerate-vForce branch April 19, 2019 19:59
/// but they need not be--they need only have an Element type and count, and
/// provide the withUnsafeBufferPointer function.
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public protocol AccelerateBuffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the file as well would not be unjustified...

stephentyrone added a commit to stephentyrone/swift that referenced this pull request Apr 25, 2019
* [Accelerate] [vForce] New vForce Overlay

This PR contains a suite of overlays to the vForce transcendental and trigonometric functions on vectors of any length. The overlays simplify the API to the existing functions and accept collections that implement a new protocol called AccelerateBuffer. Conformances are provided for the most useful stdlib Collections.
stephentyrone added a commit that referenced this pull request Apr 26, 2019
* [Accelerate] [Quadrature] New Quadrature Overlay (#23127)

* [Accelerate] [Quadrature] New Quadrature Overlay

A class that simplifies approximating the definite integral of a function.

* Fixes in response to PR Review.

Change `@_exported import Accelerate` to `import Accelerate`.
Correct date in copyright comment.

* Code Review Fixes.

* Remove mutable integrator, simply set options in init().
* Remove mutable `maxIntervals` and `qagPointsPerInterval`.
* Update tests.

* Code Review Fixes.

* Use standard library `Result`.
* Implement `QAGPointsPerInterval` as a struct.

* Tidy up Passing Integrand to `quadrature_integrate_function`.

Pass the integrand closure directly to the `quadrature_integrate_function` initialiser rather than attaching as a property of the `Quadrature` class.

* Make `Quadrature` a struct, and remove requirement for `integrand` to be escaping.

* Code Review Changes

* Add long-form integrator algorithm aliases (update tests to use these aliases).
* Make quadrature error description public.
* New tests for error description and `QAGPointsPerInterval`.

* Vectorized Integrand for Quadrature

Create an alternative implementation of `integrate` that accepts an integrand of type `(_ input: UnsafeBufferPointer<Double>, _ result: UnsafeMutableBufferPointer<Double>)`.

* Vectorized Integrand for Quadrature

Create an alternative implementation of `integrate` that accepts an integrand of type `(_ input: UnsafeBufferPointer<Double>, _ result: UnsafeMutableBufferPointer<Double>)`.

* Vectorized Integrand for Quadrature

Remove _ContiguousCollection - it's no longer used.

* Delete ContiguousCollection.swift

Not required.

* Refactor tests.

* Accelerate vForce (#24152)

* [Accelerate] [vForce] New vForce Overlay

This PR contains a suite of overlays to the vForce transcendental and trigonometric functions on vectors of any length. The overlays simplify the API to the existing functions and accept collections that implement a new protocol called AccelerateBuffer. Conformances are provided for the most useful stdlib Collections.

* Merge pull request #24184 from FlexMonkey/Accelerate_Swift-vDSP-Overlays

* Fix a case where vDSP is missing a cast (#24197)

* Add missing cast to new vDSP_FIR overlay.

* Use macOS instead of OSX in availability annotations.

* Reorder Accelerate/CMakeLists.txt alphabetically.

* [Accelerate] [vImage] Swift Overlays (#23592)

* Accelerate vImage Swift Overlays

A suite of functions, enumerations, and option sets to make working with vImage in Swift simpler.

* vImage_Buffer - new initializers to instantiate and initialize buffers with a single function call.
* vImage_Buffer - new functions to copy buffers and create CGImage instances from contents.
* vImage_CGImageFormat - new initializers.
* vImage_CGImageFormat - new equivalence operator.
* vImageConverter - methods to wrap free functions.
* vImageConverter - new make and convert functions.
* vImageCVImageFormat - new make functions.
* vImageCVImageFormat - methods to wrap free functions.
* vImage_Error - errorDescription function.
* vImage flags as an option set.

* Add new methods for generating CV -> CG and CG -> CV converters.

* update comments: `height` and `width` to `size`.

* `vImage_CGImageFormat.componentCount` should be `Int`.

* `vImage_CGImageFormat.componentCount` should be `Int`

* Move `self.init()` to after the size check for kvImageNoAllocate init.

* Buffer initializers to width and height rather than size.

* change vImage_CGImageFormat lightweight initializer to accept Int for `bitsPerComponent` and `bitsPerPixel`.

* Flesh out docs for vImage_Buffer.size

* Remove faux initializer in favor of new static function: `preferredAlignmentAndRowBytes`.

* Change functions to use proper error handling rather than inout error codes.

* Removed `flags` from basic init.

The only real flag to pass here is print diagnostics to console, and I now throw proper errors.

* Tests to check error throwing for buffer copy.

* remove unnecessary import, add missing docs.

* Add comments to error enums.

* Fix bug creating string from format code.

* Make `vImageCVImageFormat.formatCode` a `UInt32`.

* Remove equivalence operator from `CGImageFormat`.

* [Accelerate] [vDSP] DFT, FFT, DCT, and Biquad (#24207)

* Swift overlay to vDSP cascaded biquad IIR filter.

* update comment in test

* Swift overlay to vDSP Discrete Cosine Transform

* Swift Overlays to vDSP Fast Fourier Transform and Discrete Fourier Transform

* Tests for DFT and FFT

* Some refactoring and begin documentation.

* Swift overlays to FFT and DFT operations.

* Expand docs.
* Implement `vDSP_destroy_fftsetup` and `vDSP_destroy_fftsetupD`

* Refactor Tests

* Refactor Tests

* Provide transform function that returns the result. Refactoring: parameter names more consistent with other vDSP operations, push `fileprivate` symbols to bottom of file.

* Add apply() function that returns the result.

* Added a version of DFT transform that returns the result.

* update some DFT comments

* Remove FFT overlays from this branch to separate DFT and FFT pull requests.

* [Accelerate] [vDSP] Swift Overlays to FFT Operations

This PR contains Swift overlays to simplify performing 1D and 2D fast Fourier transforms on single- and double-precision data.

This PR includes a subset of the operations (e.g. vDSP_fft_zrop for FFT). My plan is to add the additional operations (e.g. multiple signals, in-place operations, etc.) in a subsequent PR once this is approved.

cc: @moiseev @airspeedswift @stephentyrone

* Composite Branch

Contains FFT, DFT, DCT, and Biquad branches.

* Merge pull request #24232 from stephentyrone/veclib-enum-availability

* Merge pull request #24275 from stephentyrone/disable-broken-vImage-test

Temporarily disable a new vImage test that's failing for some platforms.

* Remove magic-symbols-for-install-name.c from Accelerate CMakeLists.txt

This file exists on master but not on 5.1.

* Apparently GYB_SOURCES hasn't made it onto 5.1.

* Slice should only conform to AB when the Base conforms to AB.
stephentyrone added a commit to stephentyrone/swift that referenced this pull request Apr 26, 2019
* [Accelerate] [Quadrature] New Quadrature Overlay (swiftlang#23127)

* [Accelerate] [Quadrature] New Quadrature Overlay

A class that simplifies approximating the definite integral of a function.

* Fixes in response to PR Review.

Change `@_exported import Accelerate` to `import Accelerate`.
Correct date in copyright comment.

* Code Review Fixes.

* Remove mutable integrator, simply set options in init().
* Remove mutable `maxIntervals` and `qagPointsPerInterval`.
* Update tests.

* Code Review Fixes.

* Use standard library `Result`.
* Implement `QAGPointsPerInterval` as a struct.

* Tidy up Passing Integrand to `quadrature_integrate_function`.

Pass the integrand closure directly to the `quadrature_integrate_function` initialiser rather than attaching as a property of the `Quadrature` class.

* Make `Quadrature` a struct, and remove requirement for `integrand` to be escaping.

* Code Review Changes

* Add long-form integrator algorithm aliases (update tests to use these aliases).
* Make quadrature error description public.
* New tests for error description and `QAGPointsPerInterval`.

* Vectorized Integrand for Quadrature

Create an alternative implementation of `integrate` that accepts an integrand of type `(_ input: UnsafeBufferPointer<Double>, _ result: UnsafeMutableBufferPointer<Double>)`.

* Vectorized Integrand for Quadrature

Create an alternative implementation of `integrate` that accepts an integrand of type `(_ input: UnsafeBufferPointer<Double>, _ result: UnsafeMutableBufferPointer<Double>)`.

* Vectorized Integrand for Quadrature

Remove _ContiguousCollection - it's no longer used.

* Delete ContiguousCollection.swift

Not required.

* Refactor tests.

* Accelerate vForce (swiftlang#24152)

* [Accelerate] [vForce] New vForce Overlay

This PR contains a suite of overlays to the vForce transcendental and trigonometric functions on vectors of any length. The overlays simplify the API to the existing functions and accept collections that implement a new protocol called AccelerateBuffer. Conformances are provided for the most useful stdlib Collections.

* Merge pull request swiftlang#24184 from FlexMonkey/Accelerate_Swift-vDSP-Overlays

* Fix a case where vDSP is missing a cast (swiftlang#24197)

* Add missing cast to new vDSP_FIR overlay.

* Use macOS instead of OSX in availability annotations.

* Reorder Accelerate/CMakeLists.txt alphabetically.

* [Accelerate] [vImage] Swift Overlays (swiftlang#23592)

* Accelerate vImage Swift Overlays

A suite of functions, enumerations, and option sets to make working with vImage in Swift simpler.

* vImage_Buffer - new initializers to instantiate and initialize buffers with a single function call.
* vImage_Buffer - new functions to copy buffers and create CGImage instances from contents.
* vImage_CGImageFormat - new initializers.
* vImage_CGImageFormat - new equivalence operator.
* vImageConverter - methods to wrap free functions.
* vImageConverter - new make and convert functions.
* vImageCVImageFormat - new make functions.
* vImageCVImageFormat - methods to wrap free functions.
* vImage_Error - errorDescription function.
* vImage flags as an option set.

* Add new methods for generating CV -> CG and CG -> CV converters.

* update comments: `height` and `width` to `size`.

* `vImage_CGImageFormat.componentCount` should be `Int`.

* `vImage_CGImageFormat.componentCount` should be `Int`

* Move `self.init()` to after the size check for kvImageNoAllocate init.

* Buffer initializers to width and height rather than size.

* change vImage_CGImageFormat lightweight initializer to accept Int for `bitsPerComponent` and `bitsPerPixel`.

* Flesh out docs for vImage_Buffer.size

* Remove faux initializer in favor of new static function: `preferredAlignmentAndRowBytes`.

* Change functions to use proper error handling rather than inout error codes.

* Removed `flags` from basic init.

The only real flag to pass here is print diagnostics to console, and I now throw proper errors.

* Tests to check error throwing for buffer copy.

* remove unnecessary import, add missing docs.

* Add comments to error enums.

* Fix bug creating string from format code.

* Make `vImageCVImageFormat.formatCode` a `UInt32`.

* Remove equivalence operator from `CGImageFormat`.

* [Accelerate] [vDSP] DFT, FFT, DCT, and Biquad (swiftlang#24207)

* Swift overlay to vDSP cascaded biquad IIR filter.

* update comment in test

* Swift overlay to vDSP Discrete Cosine Transform

* Swift Overlays to vDSP Fast Fourier Transform and Discrete Fourier Transform

* Tests for DFT and FFT

* Some refactoring and begin documentation.

* Swift overlays to FFT and DFT operations.

* Expand docs.
* Implement `vDSP_destroy_fftsetup` and `vDSP_destroy_fftsetupD`

* Refactor Tests

* Refactor Tests

* Provide transform function that returns the result. Refactoring: parameter names more consistent with other vDSP operations, push `fileprivate` symbols to bottom of file.

* Add apply() function that returns the result.

* Added a version of DFT transform that returns the result.

* update some DFT comments

* Remove FFT overlays from this branch to separate DFT and FFT pull requests.

* [Accelerate] [vDSP] Swift Overlays to FFT Operations

This PR contains Swift overlays to simplify performing 1D and 2D fast Fourier transforms on single- and double-precision data.

This PR includes a subset of the operations (e.g. vDSP_fft_zrop for FFT). My plan is to add the additional operations (e.g. multiple signals, in-place operations, etc.) in a subsequent PR once this is approved.

cc: @moiseev @airspeedswift @stephentyrone

* Composite Branch

Contains FFT, DFT, DCT, and Biquad branches.

* Merge pull request swiftlang#24232 from stephentyrone/veclib-enum-availability

* Merge pull request swiftlang#24275 from stephentyrone/disable-broken-vImage-test

Temporarily disable a new vImage test that's failing for some platforms.

* Remove magic-symbols-for-install-name.c from Accelerate CMakeLists.txt

This file exists on master but not on 5.1.

* Apparently GYB_SOURCES hasn't made it onto 5.1.

* Slice should only conform to AB when the Base conforms to AB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants