This CL introduces a GetDebugOpName function to avoid using op_name if the Chunk is not in use.
PiperOrigin-RevId: 356788273 Change-Id: I692f6b8e2553d29189872085d28ef7b0413ca75f
This commit is contained in:
parent
4499fa94bc
commit
e04eb6b4af
@ -1032,9 +1032,9 @@ void BFCAllocator::DumpMemoryLog(size_t num_bytes) {
|
||||
(c->in_use() ? "InUse" : "Free "), " at ",
|
||||
strings::Hex(reinterpret_cast<uint64>(c->ptr)), " of size ", c->size);
|
||||
if (ShouldRecordOpName()) {
|
||||
strings::StrAppend(
|
||||
&buf, " by op ", c->op_name ? string(c->op_name) : "UNKNOWN",
|
||||
" action_count ", c->action_count, " step ", c->step_id);
|
||||
strings::StrAppend(&buf, " by op ", c->GetDebugOpName(),
|
||||
" action_count ", c->action_count, " step ",
|
||||
c->step_id);
|
||||
}
|
||||
strings::StrAppend(&buf, " next ", c->next);
|
||||
if (timing_counter_) {
|
||||
@ -1125,7 +1125,7 @@ MemoryDump BFCAllocator::RecordMemoryMapInternal() {
|
||||
mc->set_size(c->size);
|
||||
mc->set_requested_size(c->requested_size);
|
||||
mc->set_bin(c->bin_num);
|
||||
mc->set_op_name(c->op_name ? string(c->op_name) : "UNKNOWN");
|
||||
mc->set_op_name(c->GetDebugOpName());
|
||||
mc->set_step_id(c->step_id);
|
||||
mc->set_action_count(c->action_count);
|
||||
if (timing_counter_) {
|
||||
|
@ -193,6 +193,20 @@ class BFCAllocator : public Allocator {
|
||||
uint64 step_id = 0;
|
||||
uint64 action_count = 0;
|
||||
|
||||
// Get the op name used for memory debugging.
|
||||
const char* GetDebugOpName() const {
|
||||
// If chunk is not in use, although the op_name pointer is not nullptr,
|
||||
// the corresponding OpKernel might have already been deallocated, and the
|
||||
// op_name pointer might point to invalid memory. So in this case, return
|
||||
// a special op name "UNUSED";
|
||||
if (!in_use())
|
||||
return "UNUSED";
|
||||
else if (op_name)
|
||||
return op_name;
|
||||
else
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
string DebugString(BFCAllocator* a,
|
||||
bool recurse) TF_NO_THREAD_SAFETY_ANALYSIS {
|
||||
string dbg;
|
||||
@ -208,7 +222,7 @@ class BFCAllocator : public Allocator {
|
||||
Chunk* n = a->ChunkFromHandle(next);
|
||||
strings::StrAppend(&dbg, ", next: ", n->DebugString(a, false));
|
||||
}
|
||||
strings::StrAppend(&dbg, ", for: ", op_name ? op_name : "UNKNOWN",
|
||||
strings::StrAppend(&dbg, ", for: ", GetDebugOpName(),
|
||||
", stepid: ", step_id,
|
||||
", last_action: ", action_count);
|
||||
return dbg;
|
||||
|
Loading…
Reference in New Issue
Block a user