Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 1c20c3c

Browse files
committed
build: bump to TensorFlow 2.4.0
Update to build X10 against TensorFlow 2.4.0.
1 parent 68266f9 commit 1c20c3c

File tree

2 files changed

+17
-66
lines changed

2 files changed

+17
-66
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ if(NOT X10_FOUND AND NOT USE_BUNDLED_X10)
167167
GIT_REPOSITORY
168168
git://github.com/tensorflow/tensorflow
169169
GIT_TAG
170-
r2.3
170+
r2.4
171171
UPDATE_DISCONNECTED
172172
TRUE
173173
CONFIGURE_COMMAND

Sources/TensorFlow/Core/StringTensor.swift

+16-65
Original file line numberDiff line numberDiff line change
@@ -47,72 +47,23 @@ extension StringTensor {
4747
// utf8CString is null-terminated. TF APIs want the strings without null-terminators.
4848
let cStrings = scalars.map { $0.utf8CString.dropLast() }
4949

50-
// Note: `TENSORFLOW_MASTER` changes below are necessary for the new TensorFlow ABI-stable
51-
// unified string tensor design.
52-
#if TENSORFLOW_MASTER
53-
let byteCount = scalars.count * MemoryLayout<TF_TString>.stride
54-
55-
let handle = TensorHandle<String>(
56-
shape: shape.dimensions,
57-
byteCount: byteCount,
58-
bufferInitializer: { tensorBuffer in
59-
var dataAddr =
60-
tensorBuffer.bindMemory(to: TF_TString.self, capacity: scalars.count)
61-
for cString in cStrings {
62-
TF_TString_Init(dataAddr)
63-
cString.withUnsafeBufferPointer { buffer in
64-
TF_TString_Copy(dataAddr, buffer.baseAddress, buffer.count)
65-
}
66-
dataAddr = dataAddr.advanced(by: 1)
67-
}
68-
})
69-
self.init(handle: handle)
70-
#else
71-
let tfEncodedSizes = cStrings.map { TF_StringEncodedSize($0.count) }
72-
73-
// Format information copied from tensorflow/c/c_api.h:
74-
// The format for TF_STRING tensors is:
75-
// start_offset: array[uint64]
76-
// data: byte[...]
77-
//
78-
// The string length (as a varint), followed by the contents of the string is encoded at
79-
// data[start_offset[i]]].
80-
// The size of the "start_offset" region.
81-
let startOffsetsByteCount = scalars.count * MemoryLayout<UInt64>.stride
82-
83-
// The size of the "data" region.
84-
let dataByteCount = tfEncodedSizes.reduce(0, +) * MemoryLayout<UInt8>.stride
85-
86-
let handle = TensorHandle<String>(
87-
shape: shape.dimensions,
88-
byteCount: startOffsetsByteCount + dataByteCount,
89-
bufferInitializer: { tensorBuffer in
90-
// Initialize the "start_offset" region.
91-
var startOffset: UInt64 = 0
92-
var startOffsetAddr =
93-
tensorBuffer.bindMemory(to: UInt64.self, capacity: scalars.count)
94-
for tfEncodedSize in tfEncodedSizes {
95-
startOffsetAddr.initialize(to: startOffset)
96-
startOffsetAddr = startOffsetAddr.advanced(by: 1)
97-
startOffset = startOffset + UInt64(tfEncodedSize)
98-
}
99-
100-
// Initialize the "data" region.
101-
var dataAddr = tensorBuffer.advanced(by: startOffsetsByteCount)
102-
.bindMemory(to: Int8.self, capacity: dataByteCount)
103-
let status = TF_NewStatus()
104-
for (cString, tfEncodedSize) in zip(cStrings, tfEncodedSizes) {
105-
_ = cString.withUnsafeBufferPointer { buffer in
106-
TF_StringEncode(
107-
buffer.baseAddress, buffer.count, dataAddr, tfEncodedSize, status)
108-
}
109-
checkOk(status)
110-
dataAddr = dataAddr.advanced(by: tfEncodedSize)
50+
let byteCount = scalars.count * MemoryLayout<TF_TString>.stride
51+
52+
let handle = TensorHandle<String>(
53+
shape: shape.dimensions,
54+
byteCount: byteCount,
55+
bufferInitializer: { tensorBuffer in
56+
var dataAddr =
57+
tensorBuffer.bindMemory(to: TF_TString.self, capacity: scalars.count)
58+
for cString in cStrings {
59+
TF_TString_Init(dataAddr)
60+
cString.withUnsafeBufferPointer { buffer in
61+
TF_TString_Copy(dataAddr, buffer.baseAddress, buffer.count)
11162
}
112-
TF_DeleteStatus(status)
113-
})
114-
self.init(handle: handle)
115-
#endif
63+
dataAddr = dataAddr.advanced(by: 1)
64+
}
65+
})
66+
self.init(handle: handle)
11667
}
11768

11869
/// Creates a 0-D `StringTensor` from a scalar value.

0 commit comments

Comments
 (0)