Skip to content

Commit a2cf15f

Browse files
authored
---
yaml --- r: 293820 b: refs/heads/tensorflow c: 4e86c8f h: refs/heads/master
1 parent 78519f6 commit a2cf15f

File tree

246 files changed

+2996
-1388
lines changed

Some content is hidden

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

246 files changed

+2996
-1388
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: a1af0e45cb013cdc342d8c1ddfd00956c441a919
819+
refs/heads/tensorflow: 4e86c8ff52aebdd4b19950f5e2b4bbb6d2822b62
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -998,17 +998,17 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
998998
else()
999999
set(SOURCEKIT_RUNTIME_DIR lib)
10001000
endif()
1001-
swift_install_in_component(sourcekit-inproc
1002-
FILES
1001+
swift_install_in_component(FILES
10031002
$<TARGET_FILE:dispatch>
10041003
$<TARGET_FILE:BlocksRuntime>
1005-
DESTINATION ${SOURCEKIT_RUNTIME_DIR})
1004+
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1005+
COMPONENT sourcekit-inproc)
10061006
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1007-
swift_install_in_component(sourcekit-inproc
1008-
FILES
1007+
swift_install_in_component(FILES
10091008
$<TARGET_LINKER_FILE:dispatch>
10101009
$<TARGET_LINKER_FILE:BlocksRuntime>
1011-
DESTINATION lib)
1010+
DESTINATION lib
1011+
COMPONENT sourcekit-inproc)
10121012
endif()
10131013

10141014

@@ -1083,9 +1083,9 @@ endif()
10831083

10841084
add_subdirectory(cmake/modules)
10851085

1086-
swift_install_in_component(license
1087-
FILES "LICENSE.txt"
1088-
DESTINATION "share/swift")
1086+
swift_install_in_component(FILES "LICENSE.txt"
1087+
DESTINATION "share/swift"
1088+
COMPONENT license)
10891089

10901090
# Add a documentation target so that documentation shows up in the
10911091
# Xcode project.

branches/tensorflow/apinotes/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_custom_target("copy_apinotes"
3131
# This is treated as an OPTIONAL target because if we don't build the SDK
3232
# overlay, the files will be missing anyway. It also allows us to build
3333
# single overlays without installing the API notes.
34-
swift_install_in_component(sdk-overlay
35-
DIRECTORY "${output_dir}"
36-
DESTINATION "lib/swift/"
37-
OPTIONAL)
34+
swift_install_in_component(DIRECTORY "${output_dir}"
35+
DESTINATION "lib/swift/"
36+
COMPONENT sdk-overlay
37+
OPTIONAL)

branches/tensorflow/benchmark/single-source/Breadcrumbs.swift

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ extension String {
4545
}
4646
}
4747

48-
let seed = 0x12345678
49-
50-
/// A linear congruential PRNG.
51-
struct LCRNG: RandomNumberGenerator {
52-
private var state: UInt64
53-
54-
init(seed: Int) {
55-
state = UInt64(truncatingIfNeeded: seed)
56-
for _ in 0..<10 { _ = next() }
57-
}
58-
59-
mutating func next() -> UInt64 {
60-
state = 2862933555777941757 &* state &+ 3037000493
61-
return state
62-
}
63-
}
64-
6548
extension Collection {
6649
/// Returns a randomly ordered array of random non-overlapping index ranges
6750
/// that cover this collection entirely.
@@ -254,7 +237,7 @@ class UTF16ToIdx: BenchmarkBase {
254237

255238
override func setUp() {
256239
super.setUp()
257-
var rng = LCRNG(seed: seed)
240+
var rng = SplitMix64(seed: 42)
258241
let range = 0 ..< inputString.utf16.count
259242
inputOffsets = Array(range.shuffled(using: &rng).prefix(count))
260243
}
@@ -286,7 +269,7 @@ class IdxToUTF16: BenchmarkBase {
286269

287270
override func setUp() {
288271
super.setUp()
289-
var rng = LCRNG(seed: seed)
272+
var rng = SplitMix64(seed: 42)
290273
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
291274
}
292275

@@ -318,7 +301,7 @@ class UTF16ToIdxRange: BenchmarkBase {
318301

319302
override func setUp() {
320303
super.setUp()
321-
var rng = LCRNG(seed: seed)
304+
var rng = SplitMix64(seed: 42)
322305
inputOffsets = (
323306
0 ..< inputString.utf16.count
324307
).randomIndexRanges(count: count, using: &rng)
@@ -352,7 +335,7 @@ class IdxToUTF16Range: BenchmarkBase {
352335

353336
override func setUp() {
354337
super.setUp()
355-
var rng = LCRNG(seed: seed)
338+
var rng = SplitMix64(seed: 42)
356339
inputIndices = self.inputString.randomIndexRanges(count: count, using: &rng)
357340
}
358341

@@ -384,7 +367,7 @@ class CopyUTF16CodeUnits: BenchmarkBase {
384367

385368
override func setUp() {
386369
super.setUp()
387-
var rng = LCRNG(seed: seed)
370+
var rng = SplitMix64(seed: 42)
388371
inputIndices = (
389372
0 ..< inputString.utf16.count
390373
).randomIndexRanges(count: count, using: &rng)
@@ -425,7 +408,7 @@ class MutatedUTF16ToIdx: BenchmarkBase {
425408

426409
override func setUp() {
427410
super.setUp()
428-
var generator = LCRNG(seed: seed)
411+
var generator = SplitMix64(seed: 42)
429412
let range = 0 ..< inputString.utf16.count
430413
inputOffsets = Array(range.shuffled(using: &generator).prefix(count))
431414
}
@@ -469,7 +452,7 @@ class MutatedIdxToUTF16: BenchmarkBase {
469452

470453
override func setUp() {
471454
super.setUp()
472-
var rng = LCRNG(seed: seed)
455+
var rng = SplitMix64(seed: 42)
473456
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
474457
}
475458

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- BucketSort.swift ----------------------------------------------------===//
1+
//===--- BucketSort.swift -------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -9,21 +9,21 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
// Adapted from the original implementation:
12+
// This benchmark demonstrates the benefits of ExistentialSpecializer
13+
// optimization pass. It's a generic version of the classic BucketSort algorithm
14+
// adapted from an original implementation from the Swift Algorithm Club.
15+
// See https://en.wikipedia.org/wiki/Bucket_sort and
1316
// https://github.com/raywenderlich/swift-algorithm-club/tree/master/Bucket%20Sort
14-
// Issue: https://github.com/raywenderlich/swift-algorithm-club/issues/863
15-
16-
// This benchmark implements the classical BucketSort algorithm described at
17-
// https://en.wikipedia.org/wiki/Bucket_sort. The implementation allows for an
18-
// array of generic type of "SortableItem" to be sorted. Unfortunately, if
19-
// ``sortingAlgo'' type is not known for the callsite in line 84, then the
20-
// ``sort'' method can not be specialized to integer array sorting, which will
21-
// lead to a huge performance loss. Since SortingAlgorithm and InsertionSort are
22-
// declared to be ``public'' and that lines 83-85 can not be inlined in
23-
// BucketSortImpl (due to inlining heuristic limitations), today swift
24-
// compiler (without ExistentialSpecializer) can not achieve this feat. With
25-
// ExistentialSpecializer which enables generic specialization recursively in a
26-
// call chain, we are able to specialize line 84 for InsertionSort on integers.
17+
//
18+
// It sorts an array of generic `SortableItem`s. If the type of `sortingAlgo`
19+
// is not known to the call site at line 90, the `sort` method can not be
20+
// specialized to integer array sorting, which will lead to a huge performance
21+
// loss. Since `SortingAlgorithm` and `InsertionSort` are declared to be
22+
// `public` and the lines 89-91 can not be inlined in `bucketSort` (due to
23+
// inlining heuristic limitations), compiler without ExistentialSpecializer
24+
// optimization can not achieve this feat. With ExistentialSpecializer which
25+
// enables generic specialization recursively in a call chain, we're able to
26+
// specialize line 90 for `InsertionSort` on integers.
2727

2828
import TestsUtils
2929
import Foundation
@@ -32,21 +32,25 @@ public let BucketSort = BenchmarkInfo(
3232
name: "BucketSort",
3333
runFunction: run_BucketSort,
3434
tags: [.validation, .algorithm],
35-
setUpFunction: { buildWorkload() },
36-
legacyFactor: 10)
35+
setUpFunction: { blackHole(buckets) }
36+
)
3737

3838
public protocol IntegerConvertible {
3939
func convertToInt() -> Int
4040
}
41+
4142
extension Int: IntegerConvertible, SortableItem {
4243
public func convertToInt() -> Int {
4344
return self
4445
}
4546
}
47+
4648
public protocol SortableItem: IntegerConvertible, Comparable { }
49+
4750
public protocol SortingAlgorithm {
4851
func sort<T: SortableItem>(_ items: [T]) -> [T]
4952
}
53+
5054
public struct InsertionSort: SortingAlgorithm {
5155
public func sort<T: SortableItem>(_ items: [T]) -> [T] {
5256
var sortedItems = items
@@ -62,12 +66,14 @@ public struct InsertionSort: SortingAlgorithm {
6266
return sortedItems
6367
}
6468
}
69+
6570
func distribute<T>(_ item: T, bucketArray: inout [Bucket<T>]) {
6671
let val = item.convertToInt()
6772
let capacity = bucketArray.first!.capacity
6873
let index = val / capacity
6974
bucketArray[index].add(item)
7075
}
76+
7177
struct Bucket<T: SortableItem> {
7278
var items: [T]
7379
let capacity: Int
@@ -84,7 +90,10 @@ struct Bucket<T: SortableItem> {
8490
return sortingAlgo.sort(items)
8591
}
8692
}
87-
func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]) -> [T] {
93+
94+
func bucketSort<T>(
95+
_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]
96+
) -> [T] {
8897
var copyBucketArray = bucketArray
8998
for item in items {
9099
distribute(item, bucketArray: &copyBucketArray)
@@ -95,45 +104,28 @@ func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketA
95104
}
96105
return sortedArray
97106
}
98-
func isArraySorted(_ arr: [Int]) -> Bool {
99-
var idx = 0
100-
while idx < (arr.count - 1) {
101-
if arr[idx] > arr[idx+1] {
102-
return false
103-
}
104-
idx += 1
105-
}
106-
return true
107+
108+
func isAscending(_ a: [Int]) -> Bool {
109+
return zip(a, a.dropFirst()).allSatisfy(<=)
107110
}
108-
let NUMITEMS = 2500
109-
let MAXBUCKETSIZE = 1000
110-
let NUMBUCKETS: Int = 10
111+
111112
let items: [Int] = {
112-
var array: [Int]? = [Int]()
113-
for _ in 0..<NUMITEMS {
114-
array!.append(Int.random(in: 0..<MAXBUCKETSIZE))
115-
}
116-
return array!
113+
var g = SplitMix64(seed: 42)
114+
return (0..<10_000).map {_ in Int.random(in: 0..<1000, using: &g) }
117115
}()
118116

119117
let buckets: [Bucket<Int>] = {
120-
let val = (items.max()?.convertToInt())! + 1
121-
let maxCapacity = Int( ceil( Double(val) / Double(NUMBUCKETS)))
122-
var bucketArray = [Bucket<Int>]()
123-
for _ in 0..<NUMBUCKETS {
124-
bucketArray.append(Bucket<Int>(capacity: maxCapacity))
125-
}
126-
return bucketArray
118+
let bucketCount = 10
119+
let maxValue = items.max()!.convertToInt()
120+
let maxCapacity = Int(ceil(Double(maxValue + 1) / Double(bucketCount)))
121+
return (0..<bucketCount).map { _ in Bucket<Int>(capacity: maxCapacity) }
127122
}()
123+
128124
@inline(never)
129125
func run_BucketSort(_ N : Int) {
130126
for _ in 0..<N {
131-
let sortedArray = BucketSortImpl(items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
132-
CheckResults(isArraySorted(sortedArray))
127+
let sortedArray = bucketSort(
128+
items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
129+
CheckResults(isAscending(sortedArray))
133130
}
134131
}
135-
@inline(never)
136-
func buildWorkload() {
137-
blackHole(items)
138-
blackHole(buckets)
139-
}

branches/tensorflow/benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public let ObjectiveCBridging = [
7373
BenchmarkInfo(name: "ObjectiveCBridgeFromNSDateComponents",
7474
runFunction: run_ObjectiveCBridgeFromNSDateComponents, tags: t,
7575
setUpFunction: setup_dateComponents),
76+
BenchmarkInfo(name: "ObjectiveCBridgeASCIIStringFromFile",
77+
runFunction: run_ASCIIStringFromFile, tags: ts,
78+
setUpFunction: setup_ASCIIStringFromFile),
7679
]
7780

7881
#if _runtime(_ObjC)
@@ -709,3 +712,35 @@ public func run_ObjectiveCBridgeFromNSDateComponents(_ N: Int) {
709712
}
710713
#endif
711714
}
715+
716+
var ASCIIStringFromFile:String? = nil
717+
public func setup_ASCIIStringFromFile() {
718+
#if _runtime(_ObjC)
719+
let url:URL
720+
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
721+
url = FileManager.default.temporaryDirectory.appendingPathComponent(
722+
"sphinx.txt"
723+
)
724+
} else {
725+
url = URL(fileURLWithPath: "/tmp/sphinx.txt")
726+
}
727+
var str = "Sphinx of black quartz judge my vow"
728+
str = Array(repeating: str, count: 100).joined()
729+
try? str.write(
730+
to: url,
731+
atomically: true,
732+
encoding: .ascii
733+
)
734+
ASCIIStringFromFile = try! String(contentsOf: url, encoding: .ascii)
735+
#endif
736+
}
737+
738+
@inline(never)
739+
public func run_ASCIIStringFromFile(_ N: Int) {
740+
#if _runtime(_ObjC)
741+
for _ in 0 ..< N {
742+
blackHole((ASCIIStringFromFile! + "").utf8.count)
743+
}
744+
#endif
745+
}
746+

branches/tensorflow/benchmark/utils/TestsUtils.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ public struct BenchmarkInfo {
151151
return _tearDownFunction
152152
}
153153

154+
/// DON'T USE ON NEW BENCHMARKS!
155+
/// Optional `legacyFactor` is a multiplication constant applied to runtime
156+
/// statistics reported in the benchmark summary (it doesn’t affect the
157+
/// individual sample times reported in `--verbose` mode).
158+
///
159+
/// It enables the migration of benchmark suite to smaller workloads (< 1 ms),
160+
/// which are more robust to measurement errors from system under load,
161+
/// while maintaining the continuity of longterm benchmark tracking.
162+
///
163+
/// Most legacy benchmarks had workloads artificially inflated in their main
164+
/// `for` loops with a constant integer factor and the migration consisted of
165+
/// dividing it so that the optimized runtime (-O) was less than 1000 μs and
166+
/// storing the divisor in `legacyFactor`. This effectively only increases the
167+
/// frequency of measurement, gathering more samples that are much less likely
168+
/// to be interrupted by a context switch.
154169
public var legacyFactor: Int?
155170

156171
public init(name: String, runFunction: @escaping (Int) -> (), tags: [BenchmarkCategory],
@@ -221,6 +236,29 @@ public func Random() -> Int64 {
221236
return lfsrRandomGenerator.randInt()
222237
}
223238

239+
// This is a fixed-increment version of Java 8's SplittableRandom generator.
240+
// It is a very fast generator passing BigCrush, with 64 bits of state.
241+
// See http://dx.doi.org/10.1145/2714064.2660195 and
242+
// http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
243+
//
244+
// Derived from public domain C implementation by Sebastiano Vigna
245+
// See http://xoshiro.di.unimi.it/splitmix64.c
246+
public struct SplitMix64: RandomNumberGenerator {
247+
private var state: UInt64
248+
249+
public init(seed: UInt64) {
250+
self.state = seed
251+
}
252+
253+
public mutating func next() -> UInt64 {
254+
self.state &+= 0x9e3779b97f4a7c15
255+
var z: UInt64 = self.state
256+
z = (z ^ (z &>> 30)) &* 0xbf58476d1ce4e5b9
257+
z = (z ^ (z &>> 27)) &* 0x94d049bb133111eb
258+
return z ^ (z &>> 31)
259+
}
260+
}
261+
224262
@inlinable // FIXME(inline-always)
225263
@inline(__always)
226264
public func CheckResults(

0 commit comments

Comments
 (0)