Skip to content

Commit ecfcdbf

Browse files
Merge pull request #24312 from stephentyrone/accelerate-04-24
[5.1-04-24] Accelerate overlay
2 parents 56d2a56 + 3d7a783 commit ecfcdbf

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

+26508
-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)