[None][fix] Fix and enhance MemoryCounters Singleton with compile-time safety and bounds checking - #8140
[None][fix] Fix and enhance MemoryCounters Singleton with compile-time safety and bounds checking#8140Fan-Yunfan wants to merge 15 commits into
Conversation
…rsion Signed-off-by: fanyunfan <2569548856@qq.com>
…ds checking Signed-off-by: fanyunfan <2569548856@qq.com>
Walkthrough
ChangesMemoryCounters type and template handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Dear @karljang , Would you like to help me review this pr when you have time? |
|
@Fan-Yunfan , |
…r MemoryCounters Singleton. Signed-off-by: fanyunfan <2569548856@qq.com>
b3b1f2f to
4511c59
Compare
Thanks for your correction!Using I have updated the commits. Thanks for let me learn about the concept and usage of std::false_type of C++.
|
|
/bot run |
|
PR_Github #21433 [ run ] triggered by Bot |
|
PR_Github #21433 [ run ] completed with state |
|
|
|
/bot run |
|
Just running it again, the errors look not related to this change. |
|
PR_Github #21718 [ run ] triggered by Bot. Commit: |
|
PR_Github #21718 [ run ] completed with state |
|
/bot run |
Signed-off-by: fanyunfan <2569548856@qq.com>
41c55be to
a676106
Compare
|
Oops, this slipped my mind, I'm rerunning the tests now |
|
/bot run |
|
PR_Github #23425 [ run ] triggered by Bot. Commit: |
|
PR_Github #23425 [ run ] completed with state |
Haha, no worries~ I just dropped by when it crossed my mind. It doesn’t matter whether it’s early or late—just feel free to take a look whenever you have a moment. If you’re busy, just focus on your work first. I don’t have any specific requests~ |
MartinMarciniszyn
left a comment
There was a problem hiding this comment.
@Fan-Yunfan , thank you for your suggestions. I agree with the static_assert, but I am not convinced about the other changes. Please revert these.
Since you are editing this file, I suggest renaming SizeType32 to SizeType since the 32 is wrong and misleading. Many thanks for your help.
Thank you for your review—these were very helpful suggestions! I have already made the corresponding revisions based on your advice. Additionally, if the systems in focus are all 64-bit systems, I was wondering whether the 32-bit system check in another PR related to ITensor at #8855 might also be unnecessary? (I believe so, but it might require your confirmation~) |
…constraints Signed-off-by: fanyunfan <2569548856@qq.com>
1509d03 to
8c43e55
Compare
|
👋 As part of an effort to reduce the TensorRT-LLM open-PR backlog, we're checking in on PRs with no activity in over 120 days. This one qualifies. Could you let us know whether you still plan to land it?
If we don't hear back within 14 days, we'll close this PR to keep the review queue manageable. Closing isn't a rejection: the branch, commits, and discussion are all preserved, and you can reopen or resubmit at any time. Thanks for the contribution! |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpp/include/tensorrt_llm/runtime/memoryCounters.h`:
- Around line 88-90: Rename the helper type always_false to AlwaysFalse, add a
Doxygen //! \brief comment documenting the nested public type, and update both
static_assert expressions that reference it to use AlwaysFalse.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 7c383aa0-b502-49b6-aa11-101e47c86593
📒 Files selected for processing (1)
cpp/include/tensorrt_llm/runtime/memoryCounters.h
@brnguyen2 Thanks for your checking in. Yes, I still plan to land this. Could you please help review it? |



Problem
The
allocateanddeallocatetemplate functions in compile-time can determine the specified value of T, so the exception process macroTLLM_THROWwill never be invoke in runtime, it should be replaced with compile-time check such asstatic_assert.The
MemoryTypeString<T>template class don't have specified impl for unsupported type of T, so it don't havevaluemember. It may throw error: 'value' is not a member of 'MemoryTypeString<T>' .Lines
auto const sizeDiff = static_cast<DiffType>(size);andauto const sizeDiff = -static_cast<DiffType>(size);can overflow becauseSizeType32is an alias forstd::size_twhileDiffTypeisstd::ptrdiff_t.On a 32-bit platform, for example,
std::size_tspans [0 … 4 294 967 295] (2³²–1) butstd::ptrdiff_tonly covers [–2 147 483 648 … 2 147 483 647] (–2³¹ … 2³¹–1).Any size value larger than
PTRDIFF_MAXwill therefore be truncated, yielding an incorrect signed result.The current
MemoryCounterssingleton does not explicitly forbid copy and assignment operations, which is unsafe.Current Implementation
cpp/include/tensorrt_llm/runtime/memoryCounters.h
cpp/include/tensorrt_llm/runtime/iBuffer.h
Solution
static_assertto replaceTLLM_THROWand removeMemoryTypeString<T>::value.static_cast<DiffType>(size).MemoryCountersSingleton.Dev Engineer Review
MemoryCounters::SizeType32was renamed toSizeType.MemoryTypetemplate parameters now use compile-time rejection.std::size_ttostd::ptrdiff_t.QA Engineer Review
No test changes.