Skip to content

Commit 8c43e55

Browse files
committed
[None][fix] Fix compile-time check and remove unnecessary checks and constraints
Signed-off-by: fanyunfan <[email protected]>
1 parent 7924c7f commit 8c43e55

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

cpp/include/tensorrt_llm/runtime/memoryCounters.h

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <atomic>
2323
#include <cstddef>
24-
#include <limits>
2524
#include <string>
2625

2726
namespace tensorrt_llm::runtime
@@ -30,32 +29,32 @@ namespace tensorrt_llm::runtime
3029
class MemoryCounters
3130
{
3231
public:
33-
using SizeType32 = std::size_t;
32+
using SizeType = std::size_t;
3433
using DiffType = std::ptrdiff_t;
3534

3635
MemoryCounters() = default;
3736

38-
[[nodiscard]] SizeType32 getGpu() const
37+
[[nodiscard]] SizeType getGpu() const
3938
{
4039
return mGpu;
4140
}
4241

43-
[[nodiscard]] SizeType32 getCpu() const
42+
[[nodiscard]] SizeType getCpu() const
4443
{
4544
return mCpu;
4645
}
4746

48-
[[nodiscard]] SizeType32 getPinned() const
47+
[[nodiscard]] SizeType getPinned() const
4948
{
5049
return mPinned;
5150
}
5251

53-
[[nodiscard]] SizeType32 getUVM() const
52+
[[nodiscard]] SizeType getUVM() const
5453
{
5554
return mUVM;
5655
}
5756

58-
[[nodiscard]] SizeType32 getPinnedPool() const
57+
[[nodiscard]] SizeType getPinnedPool() const
5958
{
6059
return mPinnedPool;
6160
}
@@ -91,12 +90,8 @@ class MemoryCounters
9190
};
9291

9392
template <MemoryType T>
94-
void allocate(SizeType32 size)
93+
void allocate(SizeType size)
9594
{
96-
if (size > static_cast<SizeType32>(std::numeric_limits<DiffType>::max()))
97-
{
98-
TLLM_THROW("Memory size too large for diff type: %zu", size);
99-
}
10095
auto const sizeDiff = static_cast<DiffType>(size);
10196
if constexpr (T == MemoryType::kGPU)
10297
{
@@ -129,15 +124,11 @@ class MemoryCounters
129124
}
130125
}
131126

132-
void allocate(MemoryType memoryType, SizeType32 size);
127+
void allocate(MemoryType memoryType, SizeType size);
133128

134129
template <MemoryType T>
135-
void deallocate(SizeType32 size)
130+
void deallocate(SizeType size)
136131
{
137-
if (size > static_cast<SizeType32>(std::numeric_limits<DiffType>::max()))
138-
{
139-
TLLM_THROW("Memory size too large for diff type: %zu", size);
140-
}
141132
auto const sizeDiff = -static_cast<DiffType>(size);
142133
if constexpr (T == MemoryType::kGPU)
143134
{
@@ -170,23 +161,18 @@ class MemoryCounters
170161
}
171162
}
172163

173-
void deallocate(MemoryType memoryType, SizeType32 size);
164+
void deallocate(MemoryType memoryType, SizeType size);
174165

175166
static MemoryCounters& getInstance();
176167

177-
MemoryCounters(MemoryCounters const&) = delete;
178-
MemoryCounters& operator=(MemoryCounters const&) = delete;
179-
MemoryCounters(MemoryCounters&&) = delete;
180-
MemoryCounters& operator=(MemoryCounters&&) = delete;
181-
182-
static std::string bytesToString(SizeType32 bytes, int precision = 2);
168+
static std::string bytesToString(SizeType bytes, int precision = 2);
183169

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

186172
[[nodiscard]] std::string toString() const;
187173

188174
private:
189-
std::atomic<SizeType32> mGpu{}, mCpu{}, mPinned{}, mUVM{}, mPinnedPool{};
175+
std::atomic<SizeType> mGpu{}, mCpu{}, mPinned{}, mUVM{}, mPinnedPool{};
190176
std::atomic<DiffType> mGpuDiff{}, mCpuDiff{}, mPinnedDiff{}, mUVMDiff{}, mPinnedPoolDiff{};
191177
};
192178

0 commit comments

Comments
 (0)