Skip to content

Commit 4511c59

Browse files
committed
[None][fix] Explicitly prohibit all copy and assignment operations for MemoryCounters Singleton.
Signed-off-by: fanyunfan <[email protected]>
1 parent bbb2198 commit 4511c59

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cpp/include/tensorrt_llm/runtime/memoryCounters.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class MemoryCounters
8484
return mPinnedPoolDiff;
8585
}
8686

87+
template <MemoryType T>
88+
struct always_false : std::false_type
89+
{
90+
};
91+
8792
template <MemoryType T>
8893
void allocate(SizeType32 size)
8994
{
@@ -119,7 +124,7 @@ class MemoryCounters
119124
}
120125
else
121126
{
122-
static_assert(!std::is_same_v<T, T>, "Unknown memory type!");
127+
static_assert(always_false<T>::value, "Unknown memory type!");
123128
}
124129
}
125130

@@ -160,14 +165,19 @@ class MemoryCounters
160165
}
161166
else
162167
{
163-
static_assert(!std::is_same_v<T, T>, "Unknown memory type!");
168+
static_assert(always_false<T>::value, "Unknown memory type!");
164169
}
165170
}
166171

167172
void deallocate(MemoryType memoryType, SizeType32 size);
168173

169174
static MemoryCounters& getInstance();
170175

176+
MemoryCounters(MemoryCounters const&) = delete;
177+
MemoryCounters& operator=(MemoryCounters const&) = delete;
178+
MemoryCounters(MemoryCounters&&) = delete;
179+
MemoryCounters& operator=(MemoryCounters&&) = delete;
180+
171181
static std::string bytesToString(SizeType32 bytes, int precision = 2);
172182

173183
static std::string bytesToString(DiffType bytes, int precision = 2);

0 commit comments

Comments
 (0)