Skip to content

Commit 2802df1

Browse files
[5.1] Collected Accelerate overlay work (#24269)
* [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.
1 parent 8bd0e9f commit 2802df1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+26507
-51
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// An enum that acts as a namespace for Swift overlays to vImage option sets and enums..
14+
public enum vImage {}
15+
16+
/// An enum that acts as a namespace for Swift overlays to vDSP based functions.
17+
public enum vDSP {}
18+
19+
/// An enum that acts as a namespace for Swift overlays to vForce based functions.
20+
public enum vForce {}
21+
22+
extension vDSP {
23+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
24+
public struct VectorizableFloat {
25+
public typealias Scalar = Float
26+
}
27+
28+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
29+
public struct VectorizableDouble {
30+
public typealias Scalar = Double
31+
}
32+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// An object composed of count elements that are stored contiguously in memory.
14+
///
15+
/// In practice, most types conforming to this protocol will be Collections,
16+
/// but they need not be--they need only have an Element type and count, and
17+
/// provide the withUnsafeBufferPointer function.
18+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
19+
public protocol AccelerateBuffer {
20+
/// The buffer's element type.
21+
associatedtype Element
22+
23+
/// The number of elements in the buffer.
24+
var count: Int { get }
25+
26+
/// Calls a closure with a pointer to the object's contiguous storage.
27+
func withUnsafeBufferPointer<R>(
28+
_ body: (UnsafeBufferPointer<Element>) throws -> R
29+
) rethrows -> R
30+
}
31+
32+
/// A mutable object composed of count elements that are stored contiguously
33+
/// in memory.
34+
///
35+
/// In practice, most types conforming to this protocol will be
36+
/// MutableCollections, but they need not be.
37+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
38+
public protocol AccelerateMutableBuffer: AccelerateBuffer {
39+
/// Calls the given closure with a pointer to the object's mutable
40+
/// contiguous storage.
41+
mutating func withUnsafeMutableBufferPointer<R>(
42+
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
43+
) rethrows -> R
44+
}
45+
46+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
47+
public extension AccelerateBuffer where Self: Collection {
48+
func withUnsafeBufferPointer<R>(
49+
_ body: (UnsafeBufferPointer<Element>) throws -> R
50+
) rethrows -> R {
51+
return try withContiguousStorageIfAvailable(body)!
52+
}
53+
}
54+
55+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
56+
extension AccelerateMutableBuffer where Self: MutableCollection {
57+
public mutating func withUnsafeMutableBufferPointer<R>(
58+
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
59+
) rethrows -> R {
60+
return try withContiguousMutableStorageIfAvailable(body)!
61+
}
62+
}
63+
64+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
65+
extension Array: AccelerateMutableBuffer { }
66+
67+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
68+
extension ContiguousArray: AccelerateMutableBuffer { }
69+
70+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
71+
extension ArraySlice: AccelerateMutableBuffer { }
72+
73+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
74+
extension UnsafeBufferPointer: AccelerateBuffer { }
75+
76+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
77+
extension UnsafeMutableBufferPointer: AccelerateMutableBuffer { }
78+
79+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
80+
extension Slice: AccelerateBuffer where Base: AccelerateBuffer { }
81+
82+
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
83+
extension Slice: AccelerateMutableBuffer
84+
where Base: AccelerateMutableBuffer & MutableCollection { }

stdlib/public/Darwin/Accelerate/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,42 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5+
Accelerate.swift
56
BNNS.swift.gyb
67

8+
vImage_Error.swift
9+
vImage_Options.swift
10+
vImage_Buffer.swift
11+
vImage_CVImageFormat.swift
12+
vImage_CGImageFormat.swift
13+
vImage_Converter.swift
14+
AccelerateBuffer.swift
15+
Quadrature.swift
16+
vDSP_Arithmetic.swift
17+
vDSP_Biquad.swift
18+
vDSP_ClippingLimitThreshold.swift
19+
vDSP_ComplexConversion.swift
20+
vDSP_ComplexOperations.swift
21+
vDSP_Conversion.swift
22+
vDSP_Convolution.swift
23+
vDSP_DCT.swift
24+
vDSP_DFT.swift
25+
vDSP_DecibelConversion.swift
26+
vDSP_FFT.swift
27+
vDSP_FFT_DFT_Common.swift
28+
vDSP_FIR.swift
29+
vDSP_FillClearGenerate.swift
30+
vDSP_Geometry.swift
31+
vDSP_Integration.swift
32+
vDSP_Interpolation.swift
33+
vDSP_PolarRectangularConversion.swift
34+
vDSP_PolynomialEvaluation.swift
35+
vDSP_RecursiveFilters.swift
36+
vDSP_Reduction.swift
37+
vDSP_SingleVectorOperations.swift
38+
vDSP_SlidingWindow.swift
39+
vForce_Operations.swift
40+
741
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
842
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
943
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
@@ -13,6 +47,8 @@ add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
1347
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC os # auto-updated
1448
SWIFT_MODULE_DEPENDS_WATCHOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC os # auto-updated
1549

50+
FRAMEWORK_DEPENDS Accelerate
51+
1652
DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_OSX}
1753
DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_IOS}
1854
DEPLOYMENT_VERSION_TVOS ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_TVOS}

0 commit comments

Comments
 (0)