diff --git a/cpp/include/tensorrt_llm/runtime/memoryCounters.h b/cpp/include/tensorrt_llm/runtime/memoryCounters.h index 42ccdc13d62..6fd48e66be1 100644 --- a/cpp/include/tensorrt_llm/runtime/memoryCounters.h +++ b/cpp/include/tensorrt_llm/runtime/memoryCounters.h @@ -29,32 +29,32 @@ namespace tensorrt_llm::runtime class MemoryCounters { public: - using SizeType32 = std::size_t; + using SizeType = std::size_t; using DiffType = std::ptrdiff_t; MemoryCounters() = default; - [[nodiscard]] SizeType32 getGpu() const + [[nodiscard]] SizeType getGpu() const { return mGpu; } - [[nodiscard]] SizeType32 getCpu() const + [[nodiscard]] SizeType getCpu() const { return mCpu; } - [[nodiscard]] SizeType32 getPinned() const + [[nodiscard]] SizeType getPinned() const { return mPinned; } - [[nodiscard]] SizeType32 getUVM() const + [[nodiscard]] SizeType getUVM() const { return mUVM; } - [[nodiscard]] SizeType32 getPinnedPool() const + [[nodiscard]] SizeType getPinnedPool() const { return mPinnedPool; } @@ -85,7 +85,12 @@ class MemoryCounters } template - void allocate(SizeType32 size) + struct always_false : std::false_type + { + }; + + template + void allocate(SizeType size) { auto const sizeDiff = static_cast(size); if constexpr (T == MemoryType::kGPU) @@ -115,14 +120,14 @@ class MemoryCounters } else { - TLLM_THROW("Unknown memory type: %s", MemoryTypeString::value); + static_assert(always_false::value, "Unknown memory type!"); } } - void allocate(MemoryType memoryType, SizeType32 size); + void allocate(MemoryType memoryType, SizeType size); template - void deallocate(SizeType32 size) + void deallocate(SizeType size) { auto const sizeDiff = -static_cast(size); if constexpr (T == MemoryType::kGPU) @@ -152,22 +157,22 @@ class MemoryCounters } else { - TLLM_THROW("Unknown memory type: %s", MemoryTypeString::value); + static_assert(always_false::value, "Unknown memory type!"); } } - void deallocate(MemoryType memoryType, SizeType32 size); + void deallocate(MemoryType memoryType, SizeType size); static MemoryCounters& getInstance(); - static std::string bytesToString(SizeType32 bytes, int precision = 2); + static std::string bytesToString(SizeType bytes, int precision = 2); static std::string bytesToString(DiffType bytes, int precision = 2); [[nodiscard]] std::string toString() const; private: - std::atomic mGpu{}, mCpu{}, mPinned{}, mUVM{}, mPinnedPool{}; + std::atomic mGpu{}, mCpu{}, mPinned{}, mUVM{}, mPinnedPool{}; std::atomic mGpuDiff{}, mCpuDiff{}, mPinnedDiff{}, mUVMDiff{}, mPinnedPoolDiff{}; };