Skip to content

Commit d05cd67

Browse files
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.
1 parent 84d96ad commit d05cd67

File tree

7 files changed

+4807
-3
lines changed

7 files changed

+4807
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 vDSP based functions.
14+
public enum vDSP {}
15+
16+
/// An enum that acts as a namespace for Swift overlays to vForce based functions.
17+
public enum vForce {}

stdlib/public/Darwin/Accelerate/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ 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
Quadrature.swift
7+
ContiguousCollection.swift
8+
vForce_Operations.swift
69

710
"${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"
811

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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, OSX 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, OSX 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, OSX 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, OSX 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, OSX 9999, tvOS 9999, watchOS 9999, *)
65+
extension Array: AccelerateMutableBuffer { }
66+
67+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
68+
extension ContiguousArray: AccelerateMutableBuffer { }
69+
70+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
71+
extension ArraySlice: AccelerateMutableBuffer { }
72+
73+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
74+
extension UnsafeBufferPointer: AccelerateBuffer { }
75+
76+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
77+
extension UnsafeMutableBufferPointer: AccelerateMutableBuffer { }
78+
79+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
80+
extension Slice: AccelerateBuffer where Base: Collection { }
81+
82+
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
83+
extension Slice: AccelerateMutableBuffer where Base: MutableCollection { }

stdlib/public/Darwin/Accelerate/Quadrature.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Accelerate
14-
1513
// MARK: Quadrature
1614

1715
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)

0 commit comments

Comments
 (0)