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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions stdlib/public/Darwin/Accelerate/Accelerate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// An enum that acts as a namespace for Swift overlays to vDSP based functions.
public enum vDSP {}

/// An enum that acts as a namespace for Swift overlays to vForce based functions.
public enum vForce {}
3 changes: 3 additions & 0 deletions stdlib/public/Darwin/Accelerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.4.3)
include("../../../../cmake/modules/StandaloneOverlay.cmake")

add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
Accelerate.swift
Quadrature.swift
ContiguousCollection.swift
vForce_Operations.swift

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

Expand Down
83 changes: 83 additions & 0 deletions stdlib/public/Darwin/Accelerate/ContiguousCollection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// An object composed of count elements that are stored contiguously in memory.
///
/// In practice, most types conforming to this protocol will be Collections,
/// 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...

/// The buffer's element type.
associatedtype Element

/// The number of elements in the buffer.
var count: Int { get }

/// Calls a closure with a pointer to the object's contiguous storage.
func withUnsafeBufferPointer<R>(
_ body: (UnsafeBufferPointer<Element>) throws -> R
) rethrows -> R
}

/// A mutable object composed of count elements that are stored contiguously
/// in memory.
///
/// In practice, most types conforming to this protocol will be
/// MutableCollections, but they need not be.
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public protocol AccelerateMutableBuffer: AccelerateBuffer {
/// Calls the given closure with a pointer to the object's mutable
/// contiguous storage.
mutating func withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public extension AccelerateBuffer where Self: Collection {
func withUnsafeBufferPointer<R>(
_ body: (UnsafeBufferPointer<Element>) throws -> R
) rethrows -> R {
return try withContiguousStorageIfAvailable(body)!
}
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension AccelerateMutableBuffer where Self: MutableCollection {
public mutating func withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R {
return try withContiguousMutableStorageIfAvailable(body)!
}
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Array: AccelerateMutableBuffer { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension ContiguousArray: AccelerateMutableBuffer { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension ArraySlice: AccelerateMutableBuffer { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension UnsafeBufferPointer: AccelerateBuffer { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension UnsafeMutableBufferPointer: AccelerateMutableBuffer { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Slice: AccelerateBuffer where Base: Collection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Slice: AccelerateMutableBuffer where Base: MutableCollection { }
2 changes: 0 additions & 2 deletions stdlib/public/Darwin/Accelerate/Quadrature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//
//===----------------------------------------------------------------------===//

import Accelerate

// MARK: Quadrature

@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
Expand Down
Loading