Skip to content

Commit

Permalink
Change default pending shape func to a fixed code location instead of…
Browse files Browse the repository at this point in the history
… creating a lambda ad-hoc.

PiperOrigin-RevId: 718917749
  • Loading branch information
cky9301 authored and Google-ML-Automation committed Jan 27, 2025
1 parent 1a94880 commit 1fd1c7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ limitations under the License.
==============================================================================*/
#include "tsl/profiler/lib/scoped_memory_debug_annotation.h"

#include <string>

namespace tsl {
namespace profiler {

std::string DefaultPendingShapeFunc() { return ""; }

/*static*/ MemoryDebugAnnotation*
ScopedMemoryDebugAnnotation::ThreadMemoryDebugAnnotation() {
static thread_local MemoryDebugAnnotation annotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ limitations under the License.
namespace tsl {
namespace profiler {

std::string DefaultPendingShapeFunc();

// Annotations for memory profiling and debugging purpose.
// ScopedMemoryDebugAnnotation will cache the annotations in thread-local
// memory, and some allocators will try to tag allocations with the annotations.
Expand All @@ -34,7 +36,7 @@ struct MemoryDebugAnnotation {
// A lambda function, when invoked, it will generate the string that describe
// the shape of the pending tensor. By default, the TensorShape string is an
// empty string.
std::function<std::string()> pending_shape_func = []() { return ""; };
std::function<std::string()> pending_shape_func = DefaultPendingShapeFunc;
};

// Wrapper class of MemoryDebugAnnotation for RAII.
Expand Down

0 comments on commit 1fd1c7a

Please sign in to comment.