Should I call TF_AllocateOutput or TF_SetOutput and reuse input?

Hi,

Is it valid to reuse the input tensor as the output whenever they are “compatible”?
Let’s say for example I am creating a kernel for Reshape, can I call process the input tensor in place and call TF_SetOutput on it?

Hi @slai-nick ,

Reusing the input tensor as the output tensor when they are “compatible” is generally not recommended in TensorFlow, especially if you are creating a kernel for operations like Reshape. TensorFlow manages tensor memory and lifecycle, so modifying the input tensor in place could lead to unexpected behavior, memory issues, or incorrect results.

Instead, you should create a new tensor for the output using TensorFlow’s memory management functions, ensuring proper handling and avoiding potential conflicts with the framework’s internal mechanisms.

Thank You .