Skip to content

[5.1] Collected Accelerate overlay work #24269

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 11 commits into from
Apr 26, 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
32 changes: 32 additions & 0 deletions stdlib/public/Darwin/Accelerate/Accelerate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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 vImage option sets and enums..
public enum vImage {}

/// 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 {}

extension vDSP {
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public struct VectorizableFloat {
public typealias Scalar = Float
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public struct VectorizableDouble {
public typealias Scalar = Double
}
}
84 changes: 84 additions & 0 deletions stdlib/public/Darwin/Accelerate/AccelerateBuffer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// 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, macOS 9999, tvOS 9999, watchOS 9999, *)
public protocol AccelerateBuffer {
/// 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, macOS 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, macOS 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, macOS 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, macOS 9999, tvOS 9999, watchOS 9999, *)
extension Array: AccelerateMutableBuffer { }

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

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

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

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

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

@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
extension Slice: AccelerateMutableBuffer
where Base: AccelerateMutableBuffer & MutableCollection { }
36 changes: 36 additions & 0 deletions stdlib/public/Darwin/Accelerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@ 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
BNNS.swift.gyb

vImage_Error.swift
vImage_Options.swift
vImage_Buffer.swift
vImage_CVImageFormat.swift
vImage_CGImageFormat.swift
vImage_Converter.swift
AccelerateBuffer.swift
Quadrature.swift
vDSP_Arithmetic.swift
vDSP_Biquad.swift
vDSP_ClippingLimitThreshold.swift
vDSP_ComplexConversion.swift
vDSP_ComplexOperations.swift
vDSP_Conversion.swift
vDSP_Convolution.swift
vDSP_DCT.swift
vDSP_DFT.swift
vDSP_DecibelConversion.swift
vDSP_FFT.swift
vDSP_FFT_DFT_Common.swift
vDSP_FIR.swift
vDSP_FillClearGenerate.swift
vDSP_Geometry.swift
vDSP_Integration.swift
vDSP_Interpolation.swift
vDSP_PolarRectangularConversion.swift
vDSP_PolynomialEvaluation.swift
vDSP_RecursiveFilters.swift
vDSP_Reduction.swift
vDSP_SingleVectorOperations.swift
vDSP_SlidingWindow.swift
vForce_Operations.swift

SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
Expand All @@ -13,6 +47,8 @@ add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC os # auto-updated
SWIFT_MODULE_DEPENDS_WATCHOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC os # auto-updated

FRAMEWORK_DEPENDS Accelerate

DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_OSX}
DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_IOS}
DEPLOYMENT_VERSION_TVOS ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_TVOS}
Expand Down
Loading