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

Use multiple TFE_OpAddInput calls instead of one TFE_OpAddIputList #375

Merged
merged 2 commits into from
Jul 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
6 changes: 4 additions & 2 deletions Sources/TensorFlow/Bindings/EagerExecution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ internal struct TFE_Op: TFTensorOperation {
defer { buffer.deallocate() }
let pointer = UnsafeMutablePointer<OpaquePointer?>(buffer.baseAddress)
input._unpackTensorHandles(into: buffer.baseAddress)
TFE_OpAddInputList(op, pointer, count, status)
// TODO: checkOk(status)
for i in 0..<Int(count) {
TFE_OpAddInput(op, buffer[i], status)
checkOk(status)
}
}

@inlinable @inline(__always)
Expand Down
13 changes: 10 additions & 3 deletions Sources/TensorFlow/Bindings/EagerExecution.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ internal struct TFE_Op: TFTensorOperation {
defer { buffer.deallocate() }
let pointer = UnsafeMutablePointer<OpaquePointer?>(buffer.baseAddress)
input._unpackTensorHandles(into: buffer.baseAddress)
TFE_OpAddInputList(op, pointer, count, status)
// TODO: checkOk(status)
for i in 0..<Int(count) {
TFE_OpAddInput(op, buffer[i], status)
checkOk(status)
}
}

@inlinable @inline(__always)
Expand Down Expand Up @@ -271,7 +273,12 @@ internal struct TFE_Op: TFTensorOperation {
_ name: String,
_ value: (In) -> Out
) {
_tffunc(value).utf8CString.withUnsafeBufferPointer { buffer in
updateAttribute(name, _TensorFunctionPointer(name: _tffunc(value)))
}

@inlinable @inline(__always)
internal func updateAttribute(_ name: String, _ value: _TensorFunctionPointer) {
value.name.utf8CString.withUnsafeBufferPointer { buffer in
// utf8CString is null-terminated; TFE_OpSetAttrFunctionName wants
// non-null-terminated.
TFE_OpSetAttrFunctionName(op, name, buffer.baseAddress, buffer.count - 1)
Expand Down
6 changes: 1 addition & 5 deletions Tests/TensorFlowTests/OperatorTests/DatasetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ final class DatasetTests: XCTestCase {
XCTAssertEqual(iterator.next()!.scalars, [4])
}

/*
func testDoubleValueDatasetIteration() {
let scalars1 = Tensor<Float>(rangeFrom: 0, to: 5, stride: 1)
let scalars2 = Tensor<Int32>(rangeFrom: 5, to: 10, stride: 1)
Expand All @@ -138,7 +137,6 @@ final class DatasetTests: XCTestCase {
i += 1
}
}
*/

static var allTests = [
("testMultiValue", testMultiValue),
Expand All @@ -149,8 +147,6 @@ final class DatasetTests: XCTestCase {
("testParallelMap", testParallelMap),
("testMapToDifferentType", testMapToDifferentType),
("testSingleValueBatched", testSingleValueBatched),
// Currently broken even in TensorFlow ...
// This will be easier to fix once everything is moved ...
// ("testDoubleValueDatasetIteration", testDoubleValueDatasetIteration),
("testDoubleValueDatasetIteration", testDoubleValueDatasetIteration),
]
}