forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go: Cut memory footprint of Go type -> Tensor conversion by 1/2.
When converting a Go type to the raw bytes for a Tensor representation, encode directly into the C memory of the Tensor instead of first filling in the content in a buffer in Go memory and then memcpy()ing it to C. Added a benchmark, results from: go test -bench BenchmarkNewTensor -benchmem -benchtime=5s BEFORE: 19042821 ns/op 3444744 B/op 150547 allocs/op AFTER: 14478480 ns/op 1205597 B/op 150531 allocs/op Note the total bytes/op is cut down considerably. The total number of allocs/op is ridiculously high though and I suspect this is because encoding/binary.Write is doing one allocation per call (explaining 150528 of the 150531 allocations for the benchmark vector). Perhaps that will be dealt with when someone feels its pain. Another step towards tensorflow#10 Change: 139593834
- Loading branch information
1 parent
e4daca8
commit 86e348e
Showing
2 changed files
with
94 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters