Skip to content
Merged
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
19 changes: 17 additions & 2 deletions stdlib/public/TensorFlow/CompilerRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private class TraceContext {
internalConsistencyCheck(tracedFunctionName != nil)
let eagerContext = _TFCGetGlobalEagerContext()
let op: CTFEOp! = TFE_NewOp(eagerContext, tracedFunctionName, status)
defer { TFE_DeleteOp(op) }
checkOk(status)

let deviceName = _ExecutionContext.global.currentDeviceName
Expand Down Expand Up @@ -829,6 +830,20 @@ private extension TensorGroup {
TF_DeleteStatus(status)
self.init(_owning: buffer)
}

init<C: Collection>(_owning input: C) where C.Element == CTensorHandle {
Copy link
Contributor

@rxwei rxwei Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
init<C: Collection>(_owning input: C) where C.Element == CTensorHandle {
init<C : Collection>(_owning input: C) where C.Element == CTensorHandle {

(Random nit. No big deal.)

assert(Self._tensorHandleCount == input.count)
let buffer = UnsafeMutablePointer<CTensorHandle>.allocate(
capacity: input.count)
let status = TF_NewStatus()
// copy input to buffer
for (i, inputTensorHandle) in input.enumerated() {
let address = buffer.advanced(by: i)
address.initialize(to: inputTensorHandle)
}
TF_DeleteStatus(status)
self.init(_owning: buffer)
}
}

// TODO: Fold this protocol into TensorArrayProtocol.
Expand Down Expand Up @@ -936,7 +951,7 @@ private func _graphInternal<State : _TensorArrayProtocolEnhanced,
let newState = state._makeInstance(owning: returnValues.prefix(
Int(state._tensorHandleCount)))
let resultValues = returnValues.dropFirst(Int(state._tensorHandleCount))
let result = resultValues.isEmpty ? nil : Result(_copying: resultValues)
let result: Result? = resultValues.isEmpty ? nil : Result(_owning: resultValues)
return (newState, result)
}
}
Expand Down Expand Up @@ -1035,7 +1050,7 @@ public func _graph<In : TensorGroup, Out : TensorGroup>(
traceeInputs: inputTensors, useXLA: useXLA)

debugLog("Creating output model instance.")
return Out(_copying: returnValues)
return Out(_owning: returnValues)
}
}

Expand Down