Skip to content

Commit eef1d49

Browse files
authored
[TF] Remove legacy dead code from TensorFlow. (#24719)
1 parent ad37ed6 commit eef1d49

File tree

12 files changed

+328
-844
lines changed

12 files changed

+328
-844
lines changed

include/swift/AST/KnownProtocols.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ PROTOCOL(TensorArrayProtocol)
8585
PROTOCOL(TensorGroup)
8686
PROTOCOL_(TensorFlowDataTypeCompatible)
8787
PROTOCOL(TensorProtocol)
88-
PROTOCOL(TensorSendableReceivable)
8988
PROTOCOL(VectorNumeric)
9089
// TODO(TF-213): Remove underscore `Differentiable` protocols.
9190
PROTOCOL(__Differentiable)

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
946946
case KnownProtocolKind::TensorArrayProtocol:
947947
case KnownProtocolKind::TensorGroup:
948948
case KnownProtocolKind::TensorFlowDataTypeCompatible:
949-
case KnownProtocolKind::TensorSendableReceivable:
950949
case KnownProtocolKind::TensorProtocol:
951950
M = getLoadedModule(Id_TensorFlow);
952951
break;

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4192,7 +4192,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
41924192
case KnownProtocolKind::TensorGroup:
41934193
case KnownProtocolKind::TensorFlowDataTypeCompatible:
41944194
case KnownProtocolKind::TensorProtocol:
4195-
case KnownProtocolKind::TensorSendableReceivable:
41964195
case KnownProtocolKind::VectorNumeric:
41974196
// TODO(TF-213): Remove underscore `Differentiable` protocols.
41984197
case KnownProtocolKind::__Differentiable:

stdlib/public/TensorFlow/ArrayOps.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public extension Raw {
3232
/// - shape_and_slices: shape {N}. The slice specs of the tensors to be saved.
3333
/// Empty strings indicate that they are non-partitioned tensors.
3434
/// - tensors: `N` tensors to save.
35-
@inlinable @inline(__always)
35+
@inlinable
3636
static func saveV2(
3737
prefix: StringTensor,
3838
tensorNames: StringTensor,
@@ -78,7 +78,7 @@ public extension Raw {
7878
///
7979
/// - Output tensors: shape {N}. The restored tensors, whose shapes are read from the
8080
/// checkpoint directly.
81-
@inlinable @inline(__always)
81+
@inlinable
8282
static func restoreV2(
8383
prefix: StringTensor,
8484
tensorNames: StringTensor,

stdlib/public/TensorFlow/DataTypes.swift

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,6 @@ public protocol _TensorFlowDataTypeCompatible {
7878
/// The underlying TensorFlow data type.
7979
@inlinable
8080
static var tensorFlowDataType: TensorDataType { get }
81-
82-
// Hooks used by the TFPartition pass for primitive operations on tensors.
83-
// These should not be called directly or implemented.
84-
85-
/// This converts a TensorHandle that is known to have a 0d value into
86-
/// the scalar that it produces. Users should call the _TFGetScalarOrDie
87-
/// wrapper function.
88-
static func _getScalarOrDie(_ handle: TensorHandle<Self>) -> Self
89-
90-
/// This converts a TensorHandle into a scalar if it is 0d, or returns nil
91-
/// otherwise. Users should call the _TFGetScalar wrapper function.
92-
static func _getScalar(_ handle: TensorHandle<Self>) -> Self?
93-
94-
/// This indicates that it is safe to hoist the specified computation that
95-
/// creates a tensor to being a parameter that is passed in from outside of
96-
/// the tensor program.
97-
static func _hoistableClosure(_ fn: () -> TensorHandle<Self>)
98-
-> TensorHandle<Self>
9981
}
10082

10183
/// A scalar data type compatible with TensorFlow.
@@ -125,206 +107,67 @@ public protocol TensorFlowFloatingPoint :
125107
extension Float : TensorFlowFloatingPoint {}
126108
extension Double : TensorFlowFloatingPoint {}
127109

128-
// This is the implementation of the _getScalarOrDie requirement for each
129-
// concrete type below. We use this round-about approach to implement the
130-
// global _TFGetScalarOrDie function in order to ensure that the noinline
131-
// SIL functions below have non-generic type signatures. This is important for
132-
// the inner workings of the partitioning pass.
133-
private func _TFGetScalarOrDieImpl<Scalar>(
134-
_ handle: TensorHandle<Scalar>
135-
) -> Scalar {
136-
return handle.makeHostCopy().scalar!
137-
}
138-
139-
// This is the implementation of the _getScalar requirement for each concrete
140-
// type below. We use this round-about approach to implement the
141-
// global _TFGetScalar function in order to ensure that the noinline
142-
// SIL functions below have non-generic type signatures. This is important for
143-
// the inner workings of the partitioning pass.
144-
private func _TFGetScalarImpl<Scalar>(
145-
_ handle: TensorHandle<Scalar>
146-
) -> Scalar? {
147-
return handle.makeHostCopy().scalar
148-
}
149-
150110
extension Bool : TensorFlowScalar {
151111
@inlinable
152112
public static var tensorFlowDataType: TensorDataType {
153113
return TensorDataType(TF_BOOL)
154114
}
155-
@_silgen_name("__tf_get_scalar_or_die_Bool") @inline(never)
156-
public static func _getScalarOrDie(_ handle: TensorHandle<Bool>) -> Bool {
157-
return _TFGetScalarOrDieImpl(handle)
158-
}
159-
@_silgen_name("__tf_get_scalar_Bool") @inline(never)
160-
public static func _getScalar(_ handle: TensorHandle<Bool>) -> Bool? {
161-
return _TFGetScalarImpl(handle)
162-
}
163-
@_silgen_name("__tf_hoistable_Bool") @_optimize(none) @inline(never)
164-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Bool>)
165-
-> TensorHandle<Bool> {
166-
return fn()
167-
}
168115
}
169116

170117
extension Int8 : TensorFlowScalar {
171118
@inlinable
172119
public static var tensorFlowDataType: TensorDataType {
173120
return TensorDataType(TF_INT8)
174121
}
175-
@_silgen_name("__tf_get_scalar_or_die_Int8") @inline(never)
176-
public static func _getScalarOrDie(_ handle: TensorHandle<Int8>) -> Int8 {
177-
return _TFGetScalarOrDieImpl(handle)
178-
}
179-
@_silgen_name("__tf_get_scalar_Int8") @inline(never)
180-
public static func _getScalar(_ handle: TensorHandle<Int8>) -> Int8? {
181-
return _TFGetScalarImpl(handle)
182-
}
183-
@_silgen_name("__tf_hoistable_Int8") @_optimize(none) @inline(never)
184-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Int8>)
185-
-> TensorHandle<Int8> {
186-
return fn()
187-
}
188122
}
189123

190124
extension UInt8 : TensorFlowScalar {
191125
@inlinable
192126
public static var tensorFlowDataType: TensorDataType {
193127
return TensorDataType(TF_UINT8)
194128
}
195-
@_silgen_name("__tf_get_scalar_or_die_UInt8") @inline(never)
196-
public static func _getScalarOrDie(_ handle: TensorHandle<UInt8>) -> UInt8 {
197-
return _TFGetScalarOrDieImpl(handle)
198-
}
199-
@_silgen_name("__tf_get_scalar_UInt8") @inline(never)
200-
public static func _getScalar(_ handle: TensorHandle<UInt8>) -> UInt8? {
201-
return _TFGetScalarImpl(handle)
202-
}
203-
@_silgen_name("__tf_hoistable_UInt8") @_optimize(none) @inline(never)
204-
public static func _hoistableClosure(_ fn: () -> TensorHandle<UInt8>)
205-
-> TensorHandle<UInt8> {
206-
return fn()
207-
}
208129
}
209130

210131
extension Int16 : TensorFlowScalar {
211132
@inlinable
212133
public static var tensorFlowDataType: TensorDataType {
213134
return TensorDataType(TF_INT16)
214135
}
215-
@_silgen_name("__tf_get_scalar_or_die_Int16") @inline(never)
216-
public static func _getScalarOrDie(_ handle: TensorHandle<Int16>) -> Int16 {
217-
return _TFGetScalarOrDieImpl(handle)
218-
}
219-
@_silgen_name("__tf_get_scalar_Int16") @inline(never)
220-
public static func _getScalar(_ handle: TensorHandle<Int16>) -> Int16? {
221-
return _TFGetScalarImpl(handle)
222-
}
223-
@_silgen_name("__tf_hoistable_Int16") @_optimize(none) @inline(never)
224-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Int16>)
225-
-> TensorHandle<Int16> {
226-
return fn()
227-
}
228136
}
229137

230138
extension UInt16 : TensorFlowScalar {
231139
@inlinable
232140
public static var tensorFlowDataType: TensorDataType {
233141
return TensorDataType(TF_UINT16)
234142
}
235-
@_silgen_name("__tf_get_scalar_or_die_UInt16") @inline(never)
236-
public static func _getScalarOrDie(_ handle: TensorHandle<UInt16>) -> UInt16 {
237-
return _TFGetScalarOrDieImpl(handle)
238-
}
239-
@_silgen_name("__tf_get_scalar_UInt16") @inline(never)
240-
public static func _getScalar(_ handle: TensorHandle<UInt16>) -> UInt16? {
241-
return _TFGetScalarImpl(handle)
242-
}
243-
@_silgen_name("__tf_hoistable_UInt16") @_optimize(none) @inline(never)
244-
public static func _hoistableClosure(_ fn: () -> TensorHandle<UInt16>)
245-
-> TensorHandle<UInt16> {
246-
return fn()
247-
}
248143
}
249144

250145
extension Int32 : TensorFlowScalar {
251146
@inlinable
252147
public static var tensorFlowDataType: TensorDataType {
253148
return TensorDataType(TF_INT32)
254149
}
255-
@_silgen_name("__tf_get_scalar_or_die_Int32") @inline(never)
256-
public static func _getScalarOrDie(_ handle: TensorHandle<Int32>) -> Int32 {
257-
return _TFGetScalarOrDieImpl(handle)
258-
}
259-
@_silgen_name("__tf_get_scalar_Int32") @inline(never)
260-
public static func _getScalar(_ handle: TensorHandle<Int32>) -> Int32? {
261-
return _TFGetScalarImpl(handle)
262-
}
263-
@_silgen_name("__tf_hoistable_Int32") @_optimize(none) @inline(never)
264-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Int32>)
265-
-> TensorHandle<Int32> {
266-
return fn()
267-
}
268150
}
269151

270152
extension UInt32 : TensorFlowScalar {
271153
@inlinable
272154
public static var tensorFlowDataType: TensorDataType {
273155
return TensorDataType(TF_UINT32)
274156
}
275-
@_silgen_name("__tf_get_scalar_or_die_UInt32") @inline(never)
276-
public static func _getScalarOrDie(_ handle: TensorHandle<UInt32>) -> UInt32 {
277-
return _TFGetScalarOrDieImpl(handle)
278-
}
279-
@_silgen_name("__tf_get_scalar_UInt32") @inline(never)
280-
public static func _getScalar(_ handle: TensorHandle<UInt32>) -> UInt32? {
281-
return _TFGetScalarImpl(handle)
282-
}
283-
@_silgen_name("__tf_hoistable_UInt32") @_optimize(none) @inline(never)
284-
public static func _hoistableClosure(_ fn: () -> TensorHandle<UInt32>)
285-
-> TensorHandle<UInt32> {
286-
return fn()
287-
}
288157
}
289158

290159
extension Int64 : TensorFlowScalar {
291160
@inlinable
292161
public static var tensorFlowDataType: TensorDataType {
293162
return TensorDataType(TF_INT64)
294163
}
295-
@_silgen_name("__tf_get_scalar_or_die_Int64") @inline(never)
296-
public static func _getScalarOrDie(_ handle: TensorHandle<Int64>) -> Int64 {
297-
return _TFGetScalarOrDieImpl(handle)
298-
}
299-
@_silgen_name("__tf_get_scalar_Int64") @inline(never)
300-
public static func _getScalar(_ handle: TensorHandle<Int64>) -> Int64? {
301-
return _TFGetScalarImpl(handle)
302-
}
303-
@_silgen_name("__tf_hoistable_Int64") @_optimize(none) @inline(never)
304-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Int64>)
305-
-> TensorHandle<Int64> {
306-
return fn()
307-
}
308164
}
309165

310166
extension UInt64 : TensorFlowScalar {
311167
@inlinable
312168
public static var tensorFlowDataType: TensorDataType {
313169
return TensorDataType(TF_UINT64)
314170
}
315-
@_silgen_name("__tf_get_scalar_or_die_UInt64") @inline(never)
316-
public static func _getScalarOrDie(_ handle: TensorHandle<UInt64>) -> UInt64 {
317-
return _TFGetScalarOrDieImpl(handle)
318-
}
319-
@_silgen_name("__tf_get_scalar_UInt64") @inline(never)
320-
public static func _getScalar(_ handle: TensorHandle<UInt64>) -> UInt64? {
321-
return _TFGetScalarImpl(handle)
322-
}
323-
@_silgen_name("__tf_hoistable_UInt64") @_optimize(none) @inline(never)
324-
public static func _hoistableClosure(_ fn: () -> TensorHandle<UInt64>)
325-
-> TensorHandle<UInt64> {
326-
return fn()
327-
}
328171
}
329172

330173
@_fixed_layout
@@ -338,80 +181,25 @@ extension BFloat16 : TensorFlowScalar {
338181
public static var tensorFlowDataType: TensorDataType {
339182
return TensorDataType(TF_BFLOAT16)
340183
}
341-
@_silgen_name("__tf_get_scalar_or_die_BFloat16") @inline(never)
342-
public static func _getScalarOrDie
343-
(_ handle: TensorHandle<BFloat16>
344-
) -> BFloat16 {
345-
return _TFGetScalarOrDieImpl(handle)
346-
}
347-
@_silgen_name("__tf_get_scalar_BFloat16") @inline(never)
348-
public static func _getScalar(_ handle: TensorHandle<BFloat16>) -> BFloat16? {
349-
return _TFGetScalarImpl(handle)
350-
}
351-
@_silgen_name("__tf_hoistable_BFloat16") @_optimize(none) @inline(never)
352-
public static func _hoistableClosure(
353-
_ fn: () -> TensorHandle<BFloat16>
354-
) -> TensorHandle<BFloat16> {
355-
return fn()
356-
}
357184
}
358185

359186
extension Float : TensorFlowScalar {
360187
@inlinable
361188
public static var tensorFlowDataType: TensorDataType {
362189
return TensorDataType(TF_FLOAT)
363190
}
364-
@_silgen_name("__tf_get_scalar_or_die_Float") @inline(never)
365-
public static func _getScalarOrDie(_ handle: TensorHandle<Float>) -> Float {
366-
return _TFGetScalarOrDieImpl(handle)
367-
}
368-
@_silgen_name("__tf_get_scalar_Float") @inline(never)
369-
public static func _getScalar(_ handle: TensorHandle<Float>) -> Float? {
370-
return _TFGetScalarImpl(handle)
371-
}
372-
@_silgen_name("__tf_hoistable_Float") @_optimize(none) @inline(never)
373-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Float>)
374-
-> TensorHandle<Float> {
375-
return fn()
376-
}
377191
}
378192

379193
extension Double : TensorFlowScalar {
380194
@inlinable
381195
public static var tensorFlowDataType: TensorDataType {
382196
return TensorDataType(TF_DOUBLE)
383197
}
384-
@_silgen_name("__tf_get_scalar_or_die_Double") @inline(never)
385-
public static func _getScalarOrDie(_ handle: TensorHandle<Double>) -> Double {
386-
return _TFGetScalarOrDieImpl(handle)
387-
}
388-
@_silgen_name("__tf_get_scalar_Double") @inline(never)
389-
public static func _getScalar(_ handle: TensorHandle<Double>) -> Double? {
390-
return _TFGetScalarImpl(handle)
391-
}
392-
@_silgen_name("__tf_hoistable_Double") @_optimize(none) @inline(never)
393-
public static func _hoistableClosure(_ fn: () -> TensorHandle<Double>)
394-
-> TensorHandle<Double> {
395-
return fn()
396-
}
397198
}
398199

399200
extension String : _TensorFlowDataTypeCompatible {
400201
@inlinable
401202
public static var tensorFlowDataType: TensorDataType {
402203
return TensorDataType(TF_STRING)
403204
}
404-
@_silgen_name("__tf_get_scalar_or_die_String") @inline(never)
405-
public static func _getScalarOrDie(_ handle: TensorHandle<String>) -> String {
406-
return _TFGetScalarOrDieImpl(handle)
407-
}
408-
@_silgen_name("__tf_get_scalar_String") @inline(never)
409-
public static func _getScalar(_ handle: TensorHandle<String>) -> String? {
410-
return _TFGetScalarImpl(handle)
411-
}
412-
@_silgen_name("__tf_hoistable_String") @_optimize(none) @inline(never)
413-
public static func _hoistableClosure(_ fn: () -> TensorHandle<String>)
414-
-> TensorHandle<String> {
415-
return fn()
416-
}
417205
}

0 commit comments

Comments
 (0)