Open shoelzer opened 3 years ago
Hello,
Any news on this?
I also believe that the overhead of memory allocation should be avoided when calling TF_SesssionRun()
multiple times. I'm using the Tensorflow C API (2.6) for inference in the context of real-time audio processing, and malloc is not a real-time safe operation. Having a way to avoid this memory allocation is crucial for I think numerous use cases.
This issue has been pointed more than 2 years ago for Tensorflow 1.13 (https://github.com/tensorflow/tensorflow/issues/29733).
The solution suggested by @shoelzer seems good to me. There might also be other ways to implement it.
Same problem in C++ API, did anyone solve it ?
In the C API,
TF_SessionRun()
allocates new output tensors on every call. This leads to frequent allocation/deallocation and memory copies in some situations. It would be useful to be able to reuse existing tensors for output.The current API takes
TF_Tensor** output_values
and will update that variable to point to newly allocated output tensors. I propose that ifoutput_values
points to existing tensors, those tensors should be used for output instead of allocating new tensors.