diff options
author | Asim Shankar <ashankar@google.com> | 2016-11-15 00:15:48 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-11-15 00:24:28 -0800 |
commit | 1f0c5119a0230c5160d45496175b9256f097e144 (patch) | |
tree | 107fd56ab6f05ce743d1867893c4dd75bd7a98f4 /tensorflow/go/session.go | |
parent | 1791aeef881915d75c1d077ae77a205e1bc2d51c (diff) |
C API: Do not take ownership of the TF_Tensors
Prior to this change, TF_*Run, TF_SetAttrTensor and TF_SetAttrTensorList
took ownership of the TF_Tensor*s of the feeds. This can make performance
client languages bothersome when the same Tensor is repeatedly fed into
multiple session executions as the memory for the feed tensor would need
to be re-allocated and filled in every time.
With this change, these functions no longer take ownership of the
TF_Tensor*.
The changes to the Go API implementation reflect the claimed benefits.
(Another step towards #10)
Change: 139169388
Diffstat (limited to 'tensorflow/go/session.go')
-rw-r--r-- | tensorflow/go/session.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/tensorflow/go/session.go b/tensorflow/go/session.go index 430f69a8a4..fc5e3ceb4f 100644 --- a/tensorflow/go/session.go +++ b/tensorflow/go/session.go @@ -81,7 +81,7 @@ func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Op if inputs != nil { for port, tensor := range inputs { inputPorts = append(inputPorts, port.c()) - inputValues = append(inputValues, tensor.c()) + inputValues = append(inputValues, tensor.c) } } @@ -120,10 +120,9 @@ func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Op return nil, err } - var tensors []*Tensor - for _, val := range outputValues { - tensors = append(tensors, newTensorFromC(val)) - C.TF_DeleteTensor(val) + tensors := make([]*Tensor, len(outputValues)) + for i, val := range outputValues { + tensors[i] = newTensorFromC(val) } return tensors, nil |